From fec19b734cecca989f95ad5054880f7c0765a0e3 Mon Sep 17 00:00:00 2001 From: Ibby Hadeed Date: Sun, 14 May 2017 00:52:30 -0400 Subject: [PATCH] fix(sqlite): fix implementation and improve typings --- src/@ionic-native/plugins/sqlite/index.ts | 100 +++++++--------------- 1 file changed, 32 insertions(+), 68 deletions(-) diff --git a/src/@ionic-native/plugins/sqlite/index.ts b/src/@ionic-native/plugins/sqlite/index.ts index 3b0bf26152..424fa4f942 100644 --- a/src/@ionic-native/plugins/sqlite/index.ts +++ b/src/@ionic-native/plugins/sqlite/index.ts @@ -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 { return; } /** - * @param fn {any} + * @param fn {(tx: SQLiteTransaction) => void} * @returns {Promise} */ @CordovaInstance() - readTransaction(fn: any): Promise { return; } + readTransaction(fn: (tx: SQLiteTransaction) => void): Promise { return; } @CordovaInstance({ sync: true @@ -59,86 +75,33 @@ export class SQLiteObject { * @returns {Promise} */ @CordovaInstance() - close(): Promise { return; } - - @CordovaInstance({ - sync: true - }) - start(): void { } + open(): Promise { return; } /** - * Execute SQL on the opened database. Note, you must call `create` first, and - * ensure it resolved and successfully opened the database. + * @returns {Promise} */ @CordovaInstance() - executeSql(statement: string, params: any): Promise { return; } + close(): Promise { return; } /** - * @param sql - * @param values - * @returns {Promise} + * Execute SQL on the opened database. Note, you must call `create` first, and + * ensure it resolved and successfully opened the database. */ @CordovaInstance() - addStatement(sql, values): Promise { return; } + executeSql(statement: string, params: any): Promise { return; } /** - * @param sqlStatements {any} + * @param sqlStatements {Array} * @returns {Promise} */ @CordovaInstance() - sqlBatch(sqlStatements: any): Promise { return; } + sqlBatch(sqlStatements: Array): Promise { 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 { return new Promise((resolve, reject) => { - sqlitePlugin.openDatabase(config, db => resolve(new SQLiteObject(db)), reject); + sqlitePlugin.openDatabase(config, (db: any) => resolve(new SQLiteObject(db)), reject); }); }