awesome-cordova-plugins/src/plugins/sqlite.ts

182 lines
3.7 KiB
TypeScript
Raw Normal View History

2016-07-18 02:21:04 +08:00
import { Cordova, CordovaInstance, Plugin } from './plugin';
declare var sqlitePlugin;
2016-07-18 02:21:04 +08:00
/**
* @name SQLite
*
* @description
* Access SQLite databases on the device.
*
* @usage
*
* ```typescript
* 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);
* });
* ```
*
*/
@Plugin({
2016-04-30 10:47:01 +08:00
pluginRef: 'sqlitePlugin',
plugin: 'cordova-sqlite-storage',
repo: 'https://github.com/litehelpers/Cordova-sqlite-storage'
})
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
*
* ```typescript
2016-07-18 02:21:04 +08:00
* 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-07-18 02:21:04 +08:00
});
}
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
addTransaction(transaction: any): void { }
@CordovaInstance({
successIndex: 2,
errorIndex: 1
})
2016-07-18 02:21:04 +08:00
transaction(fn: any): Promise<any> { return; }
2016-07-18 02:21:04 +08:00
@CordovaInstance()
readTransaction(fn: any): Promise<any> { return; }
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
startNextTransaction(): void { }
2016-07-18 02:21:04 +08:00
@CordovaInstance()
close(): Promise<any> { return; }
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
start(): void { }
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
*
* ```typescript
2016-07-18 02:21:04 +08:00
* 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-07-18 02:21:04 +08:00
@CordovaInstance()
addStatement(sql, values): Promise<any> { return; }
2016-07-18 02:21:04 +08:00
@CordovaInstance()
sqlBatch(sqlStatements: any): Promise<any> { return; }
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
abortallPendingTransactions(): void { }
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
handleStatementSuccess(handler, response): void { }
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
handleStatementFailure(handler, response): void { }
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
run(): void { }
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
abort(txFailure): void { }
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
finish(): void { }
2016-07-18 02:21:04 +08:00
@CordovaInstance({
sync: true
})
abortFromQ(sqlerror): void { }
2016-07-18 02:21:04 +08:00
@Cordova()
static echoTest(): Promise<any> { return; }
2016-07-18 02:21:04 +08:00
@Cordova()
static deleteDatabase(first): Promise<any> { return; }
}