Skip to content

Commit

Permalink
fix(sqlite): fix implementation and improve typings
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed committed May 14, 2017
1 parent 6773ed3 commit fec19b7
Showing 1 changed file with 32 additions and 68 deletions.
100 changes: 32 additions & 68 deletions src/@ionic-native/plugins/sqlite/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand All @@ -19,19 +18,36 @@ 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
*/
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}
Expand All @@ -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
Expand All @@ -59,86 +75,33 @@ export class SQLiteObject {
* @returns {Promise<any>}
*/
@CordovaInstance()
close(): Promise<any> { return; }

@CordovaInstance({
sync: true
})
start(): void { }
open(): Promise<any> { return; }

/**
* Execute SQL on the opened database. Note, you must call `create` first, and
* ensure it resolved and successfully opened the database.
* @returns {Promise<any>}
*/
@CordovaInstance()
executeSql(statement: string, params: any): Promise<any> { return; }
close(): Promise<any> { return; }

/**
* @param sql
* @param values
* @returns {Promise<any>}
* 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<any> { return; }
executeSql(statement: string, params: any): Promise<any> { return; }

/**
* @param sqlStatements {any}
* @param sqlStatements {Array<string | string[]>}
* @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 { }

}

/**
Expand Down Expand Up @@ -177,6 +140,7 @@ export class SQLiteObject {
* SQLiteObject
* @interfaces
* SQLiteDatabaseConfig
* SQLiteTransaction
*/
@Plugin({
pluginName: 'SQLite',
Expand All @@ -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);
});
}

Expand Down

0 comments on commit fec19b7

Please sign in to comment.