Skip to content

Commit

Permalink
Add support for cordova SQLite plugin to use plugin outside of the gl…
Browse files Browse the repository at this point in the history
…obal scope, passed in via argument
  • Loading branch information
berickson1 committed Jan 11, 2016
1 parent a467efd commit 388457d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/CordovaNativeSqliteProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import NoSqlProvider = require('./NoSqlProviderInterfaces');
import SqlProviderBase = require('./SqlProviderBase');
export declare class CordovaNativeSqliteProvider extends SqlProviderBase.SqlProviderBase {
private _db;
open(dbName: string, schema: NoSqlProvider.DbSchema, wipeIfExists: boolean, verbose: boolean): SyncTasks.Promise<void>;
open(dbName: string, schema: NoSqlProvider.DbSchema, wipeIfExists: boolean, verbose: boolean, plugin?: SqlitePlugin): SyncTasks.Promise<void>;
close(): SyncTasks.Promise<void>;
openTransaction(storeNames: string | string[], writeNeeded: boolean): SyncTasks.Promise<SqlProviderBase.SqlTransaction>;
}
7 changes: 4 additions & 3 deletions dist/CordovaNativeSqliteProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ var CordovaNativeSqliteProvider = (function (_super) {
function CordovaNativeSqliteProvider() {
_super.apply(this, arguments);
}
CordovaNativeSqliteProvider.prototype.open = function (dbName, schema, wipeIfExists, verbose) {
CordovaNativeSqliteProvider.prototype.open = function (dbName, schema, wipeIfExists, verbose, plugin) {
if (plugin === void 0) { plugin = window.sqlitePlugin; }
_super.prototype.open.call(this, dbName, schema, wipeIfExists, verbose);
if (!window.sqlitePlugin || !window.sqlitePlugin.openDatabase) {
if (!plugin || !plugin.openDatabase) {
return SyncTasks.Rejected('No support for native sqlite in this browser');
}
if (typeof (navigator) !== 'undefined' && navigator.userAgent.indexOf('Mobile Crosswalk') !== -1) {
return SyncTasks.Rejected('Android NativeSqlite is broken, skipping');
}
this._db = window.sqlitePlugin.openDatabase({
this._db = plugin.openDatabase({
name: dbName + '.db',
location: 2,
androidDatabaseImplementation: 2,
Expand Down
7 changes: 4 additions & 3 deletions src/CordovaNativeSqliteProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ import SqlProviderBase = require('./SqlProviderBase');
// The DbProvider implementation for Native Sqlite on cordova
export class CordovaNativeSqliteProvider extends SqlProviderBase.SqlProviderBase {
private _db: SqliteDatabase;
open(dbName: string, schema: NoSqlProvider.DbSchema, wipeIfExists: boolean, verbose: boolean): SyncTasks.Promise<void> {
open(dbName: string, schema: NoSqlProvider.DbSchema, wipeIfExists: boolean, verbose: boolean,
plugin: SqlitePlugin = window.sqlitePlugin): SyncTasks.Promise<void> {
super.open(dbName, schema, wipeIfExists, verbose);

if (!window.sqlitePlugin || !window.sqlitePlugin.openDatabase) {
if (!plugin || !plugin.openDatabase) {
return SyncTasks.Rejected<void>('No support for native sqlite in this browser');
}

if (typeof (navigator) !== 'undefined' && navigator.userAgent.indexOf('Mobile Crosswalk') !== -1) {
return SyncTasks.Rejected<void>('Android NativeSqlite is broken, skipping');
}

this._db = window.sqlitePlugin.openDatabase({
this._db = plugin.openDatabase({
name: dbName + '.db',
location: 2,
androidDatabaseImplementation: 2,
Expand Down

0 comments on commit 388457d

Please sign in to comment.