Skip to content

Commit

Permalink
fix(sqlite): check if plugin exists before opening database
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed committed Oct 27, 2016
1 parent 8f5532e commit 6f47371
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/plugins/sqlite.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cordova, CordovaInstance, Plugin } from './plugin';
import {Cordova, CordovaInstance, Plugin, pluginWarn} from './plugin';


declare var sqlitePlugin;
Expand Down Expand Up @@ -73,13 +73,20 @@ export class SQLite {
*/
openDatabase(config: any): Promise<any> {
return new Promise((resolve, reject) => {
sqlitePlugin.openDatabase(config, db => {
this._objectInstance = db;
resolve(db);
}, error => {
console.warn(error);
reject(error);
});
if (typeof sqlitePlugin !== 'undefined') {
sqlitePlugin.openDatabase(config, db => {
this._objectInstance = db;
resolve(db);
}, error => {
console.warn(error);
reject(error);
});
} else {
pluginWarn({
name: 'SQLite',
plugin: 'cordova-sqlite-storage'
});
}
});
}

Expand Down

0 comments on commit 6f47371

Please sign in to comment.