2016-07-18 02:21:04 +08:00
|
|
|
import { Cordova, CordovaInstance, Plugin } from './plugin';
|
|
|
|
|
|
|
|
|
2016-03-29 18:50:03 +08:00
|
|
|
declare var sqlitePlugin;
|
2016-07-18 02:21:04 +08:00
|
|
|
|
2016-03-29 18:50:03 +08:00
|
|
|
/**
|
|
|
|
* @name SQLite
|
2016-06-21 05:23:26 +08:00
|
|
|
*
|
|
|
|
* @description
|
|
|
|
* Access SQLite databases on the device.
|
|
|
|
*
|
|
|
|
* @usage
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* import { SQLite } from 'ionic-native';
|
|
|
|
*
|
|
|
|
* let db = new SQLite();
|
|
|
|
* db.openDatabse({
|
|
|
|
* 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);
|
|
|
|
* });
|
|
|
|
* ```
|
|
|
|
*
|
2016-03-29 18:50:03 +08:00
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-04-30 10:47:01 +08:00
|
|
|
pluginRef: 'sqlitePlugin',
|
|
|
|
plugin: 'cordova-sqlite-storage',
|
|
|
|
repo: 'https://github.com/litehelpers/Cordova-sqlite-storage'
|
2016-03-29 18:50:03 +08:00
|
|
|
})
|
|
|
|
export class SQLite {
|
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
private _objectInstance: any;
|
|
|
|
get databaseFeatures(): any {
|
|
|
|
return this._objectInstance.databaseFeatures;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* @param config the config for opening the database.
|
|
|
|
* @usage
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* 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> {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
sqlitePlugin.openDatabase(config, db => {
|
|
|
|
this._objectInstance = db;
|
|
|
|
resolve(db);
|
|
|
|
}, error => {
|
|
|
|
console.warn(error);
|
|
|
|
reject(error);
|
2016-06-21 05:23:26 +08:00
|
|
|
});
|
2016-07-18 02:21:04 +08:00
|
|
|
});
|
|
|
|
}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
addTransaction(transaction: any): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance()
|
|
|
|
transaction(fn: any): Promise<any> { return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance()
|
|
|
|
readTransaction(fn: any): Promise<any> { return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
startNextTransaction(): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance()
|
|
|
|
close(): Promise<any> { return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
start(): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
/**
|
|
|
|
* Execute SQL on the opened database. Note, you must call `openDatabase` first, and
|
|
|
|
* ensure it resolved and successfully opened the database.
|
|
|
|
*
|
|
|
|
* @usage
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* db.executeSql('SELECT FROM puppies WHERE type = ?', ['cavalier']).then((resultSet) => {
|
|
|
|
* // Access the items through resultSet.rows
|
|
|
|
* // resultSet.rows.item(i)
|
|
|
|
* }, (err) => {})
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
@CordovaInstance()
|
|
|
|
executeSql(statement: string, params: any): Promise<any> { return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance()
|
2016-07-18 18:34:31 +08:00
|
|
|
addStatement(sql, values): Promise<any> { return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance()
|
|
|
|
sqlBatch(sqlStatements: any): Promise<any> { return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
abortallPendingTransactions(): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
handleStatementSuccess(handler, response): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
handleStatementFailure(handler, response): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
run(): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
abort(txFailure): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
finish(): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
|
|
|
abortFromQ(sqlerror): void { }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@Cordova()
|
|
|
|
static echoTest(): Promise<any> { return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-07-18 02:21:04 +08:00
|
|
|
@Cordova()
|
|
|
|
static deleteDatabase(first): Promise<any> { return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-06-21 05:23:26 +08:00
|
|
|
}
|