UNPKG

7.51 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var plugin_1 = require('./plugin');
9/**
10 * @name SQLite
11 *
12 * @description
13 * Access SQLite databases on the device.
14 *
15 * @usage
16 *
17 * ```typescript
18 * import { SQLite } from 'ionic-native';
19 *
20 * // OPTION A: Use static constructor
21 * SQLite.openDatabase({
22 * name: 'data.db',
23 * location: 'default'
24 * })
25 * .then((db: SQLite) => {
26 *
27 * db.executeSql('create table danceMoves(name VARCHAR(32))', []).then(() => {}).catch(() => {});
28 *
29 * })
30 * .catch(error => console.error('Error opening database', error));
31 *
32 *
33 * // OPTION B: Create a new instance of SQLite
34 * let db = new SQLite();
35 * db.openDatabase({
36 * name: 'data.db',
37 * location: 'default' // the location field is required
38 * }).then(() => {
39 * db.executeSql('create table danceMoves(name VARCHAR(32))', []).then(() => {
40 *
41 * }, (err) => {
42 * console.error('Unable to execute sql: ', err);
43 * });
44 * }, (err) => {
45 * console.error('Unable to open database: ', err);
46 * });
47 * ```
48 *
49 */
50var SQLite = (function () {
51 function SQLite() {
52 }
53 SQLite.openDatabase = function (config) {
54 return new SQLite().openDatabase(config);
55 };
56 /**
57 * Open or create a SQLite database file.
58 *
59 * See the plugin docs for an explanation of all options: https://github.com/litehelpers/Cordova-sqlite-storage#opening-a-database
60 *
61 * @param config the config for opening the database.
62 */
63 SQLite.prototype.openDatabase = function (config) {
64 var _this = this;
65 return new Promise(function (resolve, reject) {
66 if (typeof sqlitePlugin !== 'undefined') {
67 sqlitePlugin.openDatabase(config, function (db) {
68 _this._objectInstance = db;
69 resolve(db);
70 }, function (error) {
71 console.warn(error);
72 reject(error);
73 });
74 }
75 else {
76 plugin_1.pluginWarn({
77 pluginName: 'SQLite',
78 plugin: 'cordova-sqlite-storage'
79 });
80 }
81 });
82 };
83 SQLite.prototype.addTransaction = function (transaction) { };
84 /**
85 * @param fn {any}
86 * @returns {Promise<any>}
87 */
88 SQLite.prototype.transaction = function (fn) { return; };
89 /**
90 * @param fn {any}
91 * @returns {Promise<any>}
92 */
93 SQLite.prototype.readTransaction = function (fn) { return; };
94 SQLite.prototype.startNextTransaction = function () { };
95 /**
96 * @returns {Promise<any>}
97 */
98 SQLite.prototype.close = function () { return; };
99 SQLite.prototype.start = function () { };
100 /**
101 * Execute SQL on the opened database. Note, you must call `openDatabase` first, and
102 * ensure it resolved and successfully opened the database.
103 */
104 SQLite.prototype.executeSql = function (statement, params) { return; };
105 /**
106 * @param sql
107 * @param values
108 * @returns {Promise<any>}
109 */
110 SQLite.prototype.addStatement = function (sql, values) { return; };
111 /**
112 * @param sqlStatements {any}
113 * @returns {Promise<any>}
114 */
115 SQLite.prototype.sqlBatch = function (sqlStatements) { return; };
116 SQLite.prototype.abortallPendingTransactions = function () { };
117 /**
118 @param handler
119 @param response
120 */
121 SQLite.prototype.handleStatementSuccess = function (handler, response) { };
122 /**
123 * @param handler
124 * @param response
125 */
126 SQLite.prototype.handleStatementFailure = function (handler, response) { };
127 SQLite.prototype.run = function () { };
128 /**
129 * @param txFailure
130 */
131 SQLite.prototype.abort = function (txFailure) { };
132 SQLite.prototype.finish = function () { };
133 /**
134 * @param sqlerror
135 */
136 SQLite.prototype.abortFromQ = function (sqlerror) { };
137 /**
138 * @returns {Promise<any>}
139 */
140 SQLite.echoTest = function () { return; };
141 /**
142 * @param first
143 * @returns {Promise<any>}
144 */
145 SQLite.deleteDatabase = function (first) { return; };
146 __decorate([
147 plugin_1.InstanceProperty
148 ], SQLite.prototype, "databaseFeatures", void 0);
149 __decorate([
150 plugin_1.CordovaInstance({
151 sync: true
152 })
153 ], SQLite.prototype, "addTransaction", null);
154 __decorate([
155 plugin_1.CordovaInstance({
156 successIndex: 2,
157 errorIndex: 1
158 })
159 ], SQLite.prototype, "transaction", null);
160 __decorate([
161 plugin_1.CordovaInstance()
162 ], SQLite.prototype, "readTransaction", null);
163 __decorate([
164 plugin_1.CordovaInstance({
165 sync: true
166 })
167 ], SQLite.prototype, "startNextTransaction", null);
168 __decorate([
169 plugin_1.CordovaInstance()
170 ], SQLite.prototype, "close", null);
171 __decorate([
172 plugin_1.CordovaInstance({
173 sync: true
174 })
175 ], SQLite.prototype, "start", null);
176 __decorate([
177 plugin_1.CordovaInstance()
178 ], SQLite.prototype, "executeSql", null);
179 __decorate([
180 plugin_1.CordovaInstance()
181 ], SQLite.prototype, "addStatement", null);
182 __decorate([
183 plugin_1.CordovaInstance()
184 ], SQLite.prototype, "sqlBatch", null);
185 __decorate([
186 plugin_1.CordovaInstance({
187 sync: true
188 })
189 ], SQLite.prototype, "abortallPendingTransactions", null);
190 __decorate([
191 plugin_1.CordovaInstance({
192 sync: true
193 })
194 ], SQLite.prototype, "handleStatementSuccess", null);
195 __decorate([
196 plugin_1.CordovaInstance({
197 sync: true
198 })
199 ], SQLite.prototype, "handleStatementFailure", null);
200 __decorate([
201 plugin_1.CordovaInstance({
202 sync: true
203 })
204 ], SQLite.prototype, "run", null);
205 __decorate([
206 plugin_1.CordovaInstance({
207 sync: true
208 })
209 ], SQLite.prototype, "abort", null);
210 __decorate([
211 plugin_1.CordovaInstance({
212 sync: true
213 })
214 ], SQLite.prototype, "finish", null);
215 __decorate([
216 plugin_1.CordovaInstance({
217 sync: true
218 })
219 ], SQLite.prototype, "abortFromQ", null);
220 __decorate([
221 plugin_1.Cordova()
222 ], SQLite, "echoTest", null);
223 __decorate([
224 plugin_1.Cordova()
225 ], SQLite, "deleteDatabase", null);
226 SQLite = __decorate([
227 plugin_1.Plugin({
228 pluginName: 'SQLite',
229 pluginRef: 'sqlitePlugin',
230 plugin: 'cordova-sqlite-storage',
231 repo: 'https://github.com/litehelpers/Cordova-sqlite-storage'
232 })
233 ], SQLite);
234 return SQLite;
235}());
236exports.SQLite = SQLite;
237//# sourceMappingURL=sqlite.js.map
\No newline at end of file