mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-19 08:32:52 +08:00
fix(sqlite): fix implementation and improve typings
This commit is contained in:
parent
6773ed341c
commit
fec19b734c
@ -1,8 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Cordova, CordovaInstance, Plugin, CordovaCheck, InstanceProperty, IonicNativePlugin } from '@ionic-native/core';
|
||||
|
||||
|
||||
declare var sqlitePlugin;
|
||||
declare const sqlitePlugin: any;
|
||||
|
||||
export interface SQLiteDatabaseConfig {
|
||||
/**
|
||||
@ -19,6 +18,21 @@ export interface SQLiteDatabaseConfig {
|
||||
iosDatabaseLocation?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
export interface SQLiteTransaction {
|
||||
start: () => void;
|
||||
executeSql: (sql: any, values: any, success: Function, error: Function) => void;
|
||||
addStatement: (sql: any, values: any, success: Function, error: Function) => void;
|
||||
handleStatementSuccess: (handler: Function, response: any) => void;
|
||||
handleStatementFailure: (handler: Function, response: any) => void;
|
||||
run: () => void;
|
||||
abort: (txFailure: any) => void;
|
||||
finish: () => void;
|
||||
abortFromQ: (sqlerror: any) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
@ -26,12 +40,14 @@ export class SQLiteObject {
|
||||
|
||||
constructor(public _objectInstance: any) { }
|
||||
|
||||
@InstanceProperty databaseFeatures: any;
|
||||
@InstanceProperty databaseFeatures: { isSQLitePluginDatabase: boolean };
|
||||
|
||||
@InstanceProperty openDBs: any;
|
||||
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
addTransaction(transaction: any): void { }
|
||||
addTransaction(transaction: (tx: SQLiteTransaction) => void): void { }
|
||||
|
||||
/**
|
||||
* @param fn {any}
|
||||
@ -44,11 +60,11 @@ export class SQLiteObject {
|
||||
transaction(fn: any): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* @param fn {any}
|
||||
* @param fn {(tx: SQLiteTransaction) => void}
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance()
|
||||
readTransaction(fn: any): Promise<any> { return; }
|
||||
readTransaction(fn: (tx: SQLiteTransaction) => void): Promise<any> { return; }
|
||||
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
@ -59,12 +75,13 @@ export class SQLiteObject {
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance()
|
||||
close(): Promise<any> { return; }
|
||||
open(): Promise<any> { return; }
|
||||
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
start(): void { }
|
||||
/**
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance()
|
||||
close(): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Execute SQL on the opened database. Note, you must call `create` first, and
|
||||
@ -74,71 +91,17 @@ export class SQLiteObject {
|
||||
executeSql(statement: string, params: any): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* @param sql
|
||||
* @param values
|
||||
* @param sqlStatements {Array<string | string[]>}
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance()
|
||||
addStatement(sql, values): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* @param sqlStatements {any}
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance()
|
||||
sqlBatch(sqlStatements: any): Promise<any> { return; }
|
||||
sqlBatch(sqlStatements: Array<string | string[]>): Promise<any> { return; }
|
||||
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
abortallPendingTransactions(): void { }
|
||||
|
||||
/**
|
||||
@param handler
|
||||
@param response
|
||||
*/
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
handleStatementSuccess(handler, response): void { }
|
||||
|
||||
/**
|
||||
* @param handler
|
||||
* @param response
|
||||
*/
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
handleStatementFailure(handler, response): void { }
|
||||
|
||||
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
run(): void { }
|
||||
|
||||
/**
|
||||
* @param txFailure
|
||||
*/
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
abort(txFailure): void { }
|
||||
|
||||
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
finish(): void { }
|
||||
|
||||
/**
|
||||
* @param sqlerror
|
||||
*/
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
abortFromQ(sqlerror): void { }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,6 +140,7 @@ export class SQLiteObject {
|
||||
* SQLiteObject
|
||||
* @interfaces
|
||||
* SQLiteDatabaseConfig
|
||||
* SQLiteTransaction
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'SQLite',
|
||||
@ -198,7 +162,7 @@ export class SQLite extends IonicNativePlugin {
|
||||
@CordovaCheck()
|
||||
create(config: SQLiteDatabaseConfig): Promise<SQLiteObject> {
|
||||
return new Promise((resolve, reject) => {
|
||||
sqlitePlugin.openDatabase(config, db => resolve(new SQLiteObject(db)), reject);
|
||||
sqlitePlugin.openDatabase(config, (db: any) => resolve(new SQLiteObject(db)), reject);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user