This repository has been archived by the owner on Jul 7, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
sqlite.js
58 lines (52 loc) · 2.3 KB
/
sqlite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**************************************************************************************
* (c) 2015-2021, Master Technology
* Licensed under the MIT license or contact me for a support, changes, enhancements,
* and/or if you require a commercial licensing
*
* Any questions please feel free to put a issue up on github
* Nathan@master-technology.com http://nativescript.tools
* Version 2.7.0 - Android
*************************************************************************************/
/* global global, require, module */
"use strict";
const DBInternal = require("nativescript-sqlite/sqlite-internal");
function Database(dbname, options, callback) {
if (typeof options === 'function') {
callback = options;
//noinspection JSUnusedAssignment
options = {};
} else {
//noinspection JSUnusedAssignment
options = options || {};
}
if (options && options.multithreading && typeof global.Worker === 'function') {
// We don't want this value passed into the worker; to try and start another worker (which would fail).
delete options.multithreading;
if (!DBInternal.HAS_COMMERCIAL) {
throw new Error("Multithreading is a commercial only feature; see https://nativescript.tools/product/10");
}
// We have to wrap this in a try/catch because of Webpack 4
try {
const multiSQL = require("nativescript-sqlite-commercial/commercial-multi");
return new multiSQL(dbname, options, callback);
} catch (err) {
console.warn("Multithreading is a commercial only feature; see https://nativescript.tools/product/10");
}
}
return new DBInternal(dbname, options, callback);
}
// Copy static Properties & Static functions over so that they still work
for (let item in DBInternal) {
if (DBInternal.hasOwnProperty(item)) {
Database[item] = DBInternal[item];
}
}
if (global.TNS_WEBPACK && global.TNS_WEBPACK >= 5) {
if (global._MT_HAS_SQLITE) {
Database.HAS_COMMERCIAL = (global._MT_HAS_SQLITE & 1) === 1;
Database.HAS_ENCRYPTION = (global._MT_HAS_SQLITE & 2) === 2;
Database.HAS_SYNC = (global._MT_HAS_SQLITE & 4) === 4;
Database.HAS_KEYSTORE = (global._MT_HAS_SQLITE & 8) === 8;
}
}
module.exports = Database;