mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-22 01:19:36 +08:00
fix(sqlite): add static constructor, and fix resolve type (#697)
This commit is contained in:
parent
b19f6d1ccd
commit
9082c5efbf
@ -14,6 +14,20 @@ declare var sqlitePlugin;
|
|||||||
* ```typescript
|
* ```typescript
|
||||||
* import { SQLite } from 'ionic-native';
|
* import { SQLite } from 'ionic-native';
|
||||||
*
|
*
|
||||||
|
* // OPTION A: Use static constructor
|
||||||
|
* SQLite.openDatabase({
|
||||||
|
* name: 'data.db',
|
||||||
|
* location: 'default'
|
||||||
|
* })
|
||||||
|
* .then((db: SQLite) => {
|
||||||
|
*
|
||||||
|
* db.executeSQL('create table danceMoves(name VARCHAR(32))').then(() => {}).catch(() => {});
|
||||||
|
*
|
||||||
|
* })
|
||||||
|
* .catch(error => console.error('Error openening database', error);
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* // OPTION B: Create a new instance of SQLite
|
||||||
* let db = new SQLite();
|
* let db = new SQLite();
|
||||||
* db.openDatabase({
|
* db.openDatabase({
|
||||||
* name: 'data.db',
|
* name: 'data.db',
|
||||||
@ -45,32 +59,18 @@ export class SQLite {
|
|||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
|
static openDatabase(config: any): Promise<SQLite> {
|
||||||
|
let db = new SQLite();
|
||||||
|
return db.openDatabase(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open or create a SQLite database file.
|
* Open or create a SQLite database file.
|
||||||
*
|
*
|
||||||
* See the plugin docs for an explanation of all options: https://github.com/litehelpers/Cordova-sqlite-storage#opening-a-database
|
* 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.
|
* @param config the config for opening the database.
|
||||||
* @returns {Promise<any>}
|
|
||||||
* @usage
|
|
||||||
*
|
|
||||||
* ```typescript
|
|
||||||
* import { SQLite } from 'ionic-native';
|
|
||||||
*
|
|
||||||
* let db = new SQLite();
|
|
||||||
* db.openDatabase({
|
|
||||||
* 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> {
|
openDatabase(config: any): Promise<any> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -132,18 +132,6 @@ export class SQLite {
|
|||||||
/**
|
/**
|
||||||
* Execute SQL on the opened database. Note, you must call `openDatabase` first, and
|
* Execute SQL on the opened database. Note, you must call `openDatabase` first, and
|
||||||
* ensure it resolved and successfully opened the database.
|
* ensure it resolved and successfully opened the database.
|
||||||
*
|
|
||||||
* @usage
|
|
||||||
*
|
|
||||||
* ```typescript
|
|
||||||
* db.executeSql('SELECT FROM puppies WHERE type = ?', ['cavalier']).then((resultSet) => {
|
|
||||||
* // Access the items through resultSet.rows
|
|
||||||
* // resultSet.rows.item(i)
|
|
||||||
* }, (err) => {})
|
|
||||||
* ```
|
|
||||||
* @param statement {string}
|
|
||||||
* @param params {any}
|
|
||||||
* @returns {Promise<any>}
|
|
||||||
*/
|
*/
|
||||||
@CordovaInstance()
|
@CordovaInstance()
|
||||||
executeSql(statement: string, params: any): Promise<any> { return; }
|
executeSql(statement: string, params: any): Promise<any> { return; }
|
||||||
|
Loading…
Reference in New Issue
Block a user