mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-03-17 00:51:07 +08:00
fix(sqlite): resolve race condition, add comments (#235)
This commit is contained in:
parent
32661b791a
commit
f1c8ce35e8
@ -2,6 +2,30 @@ import {CordovaInstance, Plugin, Cordova} from './plugin';
|
|||||||
declare var sqlitePlugin;
|
declare var sqlitePlugin;
|
||||||
/**
|
/**
|
||||||
* @name SQLite
|
* @name SQLite
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Access SQLite databases on the device.
|
||||||
|
*
|
||||||
|
* @usage
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import { SQLite } from 'ionic-native';
|
||||||
|
*
|
||||||
|
* let db = new SQLite();
|
||||||
|
* db.openDatabse({
|
||||||
|
* name: 'data.db',
|
||||||
|
* location: 'default' // the location field is required
|
||||||
|
* }).then(() => {
|
||||||
|
* db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {
|
||||||
|
*
|
||||||
|
* }, (err) => {
|
||||||
|
* console.error('Unable to execute sql', err);
|
||||||
|
* })
|
||||||
|
* }, (err) => {
|
||||||
|
* console.error('Unable to open database', err);
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
@Plugin({
|
@Plugin({
|
||||||
pluginRef: 'sqlitePlugin',
|
pluginRef: 'sqlitePlugin',
|
||||||
@ -15,13 +39,44 @@ export class SQLite {
|
|||||||
return this._objectInstance.databaseFeatures;
|
return this._objectInstance.databaseFeatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (config: any) {
|
constructor () {}
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
sqlitePlugin.openDatabase(config, resolve, reject);
|
/**
|
||||||
}).then(
|
* Open or create a SQLite database file.
|
||||||
db => this._objectInstance = db,
|
*
|
||||||
error => console.warn(error)
|
* See the plugin docs for an explanation of all options: https://github.com/litehelpers/Cordova-sqlite-storage#opening-a-database
|
||||||
);
|
*
|
||||||
|
* @param config the config for opening the database.
|
||||||
|
* @usage
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import { SQLite } from 'ionic-native';
|
||||||
|
*
|
||||||
|
* let db = new SQLite();
|
||||||
|
* db.openDatabse({
|
||||||
|
* name: 'data.db',
|
||||||
|
* location: 'default' // the location field is required
|
||||||
|
* }).then(() => {
|
||||||
|
* db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {
|
||||||
|
*
|
||||||
|
* }, (err) => {
|
||||||
|
* console.error('Unable to execute sql', err);
|
||||||
|
* })
|
||||||
|
* }, (err) => {
|
||||||
|
* console.error('Unable to open database', err);
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordovaInstance({
|
@CordovaInstance({
|
||||||
@ -48,6 +103,19 @@ export class SQLite {
|
|||||||
})
|
})
|
||||||
start (): void {}
|
start (): void {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute SQL on the opened database. Note, you must call `openDatabase` first, and
|
||||||
|
* ensure it resolved and successfully opened the database.
|
||||||
|
*
|
||||||
|
* @usage
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* db.executeSql('SELECT FROM puppies WHERE type = ?', ['cavalier']).then((resultSet) => {
|
||||||
|
* // Access the items through resultSet.rows
|
||||||
|
* // resultSet.rows.item(i)
|
||||||
|
* }, (err) => {})
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
@CordovaInstance()
|
@CordovaInstance()
|
||||||
executeSql (statement: string, params: any): Promise<any> {return; }
|
executeSql (statement: string, params: any): Promise<any> {return; }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user