2016-03-29 18:50:03 +08:00
|
|
|
import {CordovaInstance, Plugin, Cordova} from './plugin';
|
|
|
|
declare var sqlitePlugin;
|
|
|
|
/**
|
|
|
|
* @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-04-30 11:56:49 +08:00
|
|
|
private _objectInstance: any;
|
|
|
|
get databaseFeatures(): any {
|
2016-03-29 18:50:03 +08:00
|
|
|
return this._objectInstance.databaseFeatures;
|
|
|
|
}
|
|
|
|
|
2016-06-21 05:23:26 +08:00
|
|
|
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.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-06-27 00:54:14 +08:00
|
|
|
openDatabase (config: any): Promise<any> {
|
2016-06-21 05:23:26 +08:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
sqlitePlugin.openDatabase(config, db => {
|
|
|
|
this._objectInstance = db;
|
|
|
|
resolve(db);
|
|
|
|
}, error => {
|
2016-06-27 00:54:14 +08:00
|
|
|
console.warn(error);
|
2016-06-21 05:23:26 +08:00
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
2016-03-29 18:50:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
addTransaction (transaction: any): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@CordovaInstance()
|
2016-04-30 11:56:49 +08:00
|
|
|
transaction (fn: any): Promise<any> {return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@CordovaInstance()
|
2016-04-30 11:56:49 +08:00
|
|
|
readTransaction (fn: any): Promise<any> {return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
startNextTransaction (): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@CordovaInstance()
|
2016-04-30 11:56:49 +08:00
|
|
|
close (): Promise<any> {return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
start (): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-06-21 05:23:26 +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) => {})
|
|
|
|
* ```
|
|
|
|
*/
|
2016-03-29 18:50:03 +08:00
|
|
|
@CordovaInstance()
|
2016-04-30 11:56:49 +08:00
|
|
|
executeSql (statement: string, params: any): Promise<any> {return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@CordovaInstance()
|
2016-04-30 11:56:49 +08:00
|
|
|
addSatement (sql, values): Promise<any> {return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@CordovaInstance()
|
2016-04-30 11:56:49 +08:00
|
|
|
sqlBatch (sqlStatements: any): Promise<any> {return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
abortallPendingTransactions (): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
handleStatementSuccess (handler, response): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
handleStatementFailure (handler, response): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
run (): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
abort (txFailure): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
finish (): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
@CordovaInstance({
|
|
|
|
sync: true
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
abortFromQ (sqlerror): void {}
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
@Cordova()
|
2016-04-30 11:56:49 +08:00
|
|
|
static echoTest (): Promise<any> {return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
|
|
|
@Cordova()
|
2016-04-30 11:56:49 +08:00
|
|
|
static deleteDatabase (first): Promise<any> {return; }
|
2016-03-29 18:50:03 +08:00
|
|
|
|
2016-06-21 05:23:26 +08:00
|
|
|
}
|