mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-03-17 00:51:07 +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 { Injectable } from '@angular/core';
|
||||||
import { Cordova, CordovaInstance, Plugin, CordovaCheck, InstanceProperty, IonicNativePlugin } from '@ionic-native/core';
|
import { Cordova, CordovaInstance, Plugin, CordovaCheck, InstanceProperty, IonicNativePlugin } from '@ionic-native/core';
|
||||||
|
|
||||||
|
declare const sqlitePlugin: any;
|
||||||
declare var sqlitePlugin;
|
|
||||||
|
|
||||||
export interface SQLiteDatabaseConfig {
|
export interface SQLiteDatabaseConfig {
|
||||||
/**
|
/**
|
||||||
@ -19,6 +18,21 @@ export interface SQLiteDatabaseConfig {
|
|||||||
iosDatabaseLocation?: string;
|
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
|
* @hidden
|
||||||
*/
|
*/
|
||||||
@ -26,12 +40,14 @@ export class SQLiteObject {
|
|||||||
|
|
||||||
constructor(public _objectInstance: any) { }
|
constructor(public _objectInstance: any) { }
|
||||||
|
|
||||||
@InstanceProperty databaseFeatures: any;
|
@InstanceProperty databaseFeatures: { isSQLitePluginDatabase: boolean };
|
||||||
|
|
||||||
|
@InstanceProperty openDBs: any;
|
||||||
|
|
||||||
@CordovaInstance({
|
@CordovaInstance({
|
||||||
sync: true
|
sync: true
|
||||||
})
|
})
|
||||||
addTransaction(transaction: any): void { }
|
addTransaction(transaction: (tx: SQLiteTransaction) => void): void { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param fn {any}
|
* @param fn {any}
|
||||||
@ -44,11 +60,11 @@ export class SQLiteObject {
|
|||||||
transaction(fn: any): Promise<any> { return; }
|
transaction(fn: any): Promise<any> { return; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param fn {any}
|
* @param fn {(tx: SQLiteTransaction) => void}
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
@CordovaInstance()
|
@CordovaInstance()
|
||||||
readTransaction(fn: any): Promise<any> { return; }
|
readTransaction(fn: (tx: SQLiteTransaction) => void): Promise<any> { return; }
|
||||||
|
|
||||||
@CordovaInstance({
|
@CordovaInstance({
|
||||||
sync: true
|
sync: true
|
||||||
@ -59,12 +75,13 @@ export class SQLiteObject {
|
|||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
@CordovaInstance()
|
@CordovaInstance()
|
||||||
close(): Promise<any> { return; }
|
open(): Promise<any> { return; }
|
||||||
|
|
||||||
@CordovaInstance({
|
/**
|
||||||
sync: true
|
* @returns {Promise<any>}
|
||||||
})
|
*/
|
||||||
start(): void { }
|
@CordovaInstance()
|
||||||
|
close(): Promise<any> { return; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute SQL on the opened database. Note, you must call `create` first, and
|
* 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; }
|
executeSql(statement: string, params: any): Promise<any> { return; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sql
|
* @param sqlStatements {Array<string | string[]>}
|
||||||
* @param values
|
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
@CordovaInstance()
|
@CordovaInstance()
|
||||||
addStatement(sql, values): Promise<any> { return; }
|
sqlBatch(sqlStatements: Array<string | string[]>): Promise<any> { return; }
|
||||||
|
|
||||||
/**
|
|
||||||
* @param sqlStatements {any}
|
|
||||||
* @returns {Promise<any>}
|
|
||||||
*/
|
|
||||||
@CordovaInstance()
|
|
||||||
sqlBatch(sqlStatements: any): Promise<any> { return; }
|
|
||||||
|
|
||||||
@CordovaInstance({
|
@CordovaInstance({
|
||||||
sync: true
|
sync: true
|
||||||
})
|
})
|
||||||
abortallPendingTransactions(): void { }
|
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
|
* SQLiteObject
|
||||||
* @interfaces
|
* @interfaces
|
||||||
* SQLiteDatabaseConfig
|
* SQLiteDatabaseConfig
|
||||||
|
* SQLiteTransaction
|
||||||
*/
|
*/
|
||||||
@Plugin({
|
@Plugin({
|
||||||
pluginName: 'SQLite',
|
pluginName: 'SQLite',
|
||||||
@ -198,7 +162,7 @@ export class SQLite extends IonicNativePlugin {
|
|||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
create(config: SQLiteDatabaseConfig): Promise<SQLiteObject> {
|
create(config: SQLiteDatabaseConfig): Promise<SQLiteObject> {
|
||||||
return new Promise((resolve, reject) => {
|
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…
x
Reference in New Issue
Block a user