Skip to content
This repository was archived by the owner on Jul 7, 2022. It is now read-only.

Commit aafc14d

Browse files
committed
Update for NS8 w/ webworkers
1 parent d42936b commit aafc14d

5 files changed

+95
-44
lines changed

src/nativescript.webpack.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,50 @@ module.exports = webpack => {
1515

1616
// Add all sqlite files
1717
webpack.Utils.addCopyRule('**/*.sqlite');
18+
webpack.Utils.addCopyRule('**/*.db');
1819

1920
// Used to update any existing configurations with more rules...
2021
webpack.chainWebpack((config, env) => {
21-
2222
// Update Externals to eliminate any warnings during building
2323
const externals = config.get('externals');
24+
let hasSync = false, hasCom = false, hasEnc = false, hasKey = false;
25+
2426
let dirname = path.resolve(__dirname, "../");
2527
if (!fs.existsSync(dirname+"/nativescript-sqlite-sync")) {
2628
console.warn("NativeScript-SQLite Sync not detected, disabling support!");
2729
externals.push('nativescript-sqlite-sync');
30+
} else {
31+
hasSync = true;
2832
}
2933
if (!fs.existsSync(dirname+"/nativescript-sqlite-commercial")) {
3034
console.warn("NativeScript-SQLite Commercial not detected, disabling support!");
3135
externals.push('nativescript-sqlite-commercial');
36+
} else {
37+
hasCom = true;
3238
}
3339
if (!fs.existsSync(dirname+"/nativescript-sqlite-encrypted")) {
3440
console.warn("NativeScript-SQLite Encrypted not detected, disabling support!");
3541
externals.push('nativescript-sqlite-encrypted');
42+
} else {
43+
hasEnc = true;
44+
}
45+
if (!fs.existsSync(dirname+"/nativescript-sqlite-keystore")) {
46+
console.warn("NativeScript-SQLite KeyStore not detected, disabling support!");
47+
externals.push('nativescript-sqlite-keystore');
48+
} else {
49+
hasKey = true;
3650
}
51+
3752
config.set('externals', externals);
3853

54+
config.module
55+
.rule('workers')
56+
.exclude.clear();
57+
3958
// Add TNS_WEBPACK to the defines...
4059
config.plugin('DefinePlugin').tap(args => {
4160
args[0]['global.TNS_WEBPACK'] = 5;
61+
args[0]['global._MT_HAS_SQLITE'] = (hasCom ? 1 : 0) + (hasEnc ? 2 : 0) + (hasSync ? 4 : 0) + (hasKey ? 8 : 0);
4262
return args;
4363
});
4464
});

src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-sqlite",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"description": "A sqlite NativeScript module for Android and iOS",
55
"main": "sqlite",
66
"nativescript": {

src/sqlite.android.js src/sqlite-internal.android.js

+20-31
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
/* global global, require, module */
1111

1212
"use strict";
13+
1314
const appModule = require("@nativescript/core/application");
1415
const fsModule = require("@nativescript/core/file-system");
1516

17+
18+
//import * as appModule from '@nativescript/core/application';
19+
//import * as fsModule from '@nativescript/core/file-system';
20+
1621
/*jshint undef: true */
1722
/*global java, android, Promise */
1823

@@ -245,28 +250,13 @@ function Database(dbname, options, callback) {
245250
options = options || {};
246251
}
247252

248-
249-
//noinspection JSUnresolvedVariable
250-
if (options && options.multithreading && typeof global.Worker === 'function') {
251-
// We don't want this passed into the worker; to try and start another worker (which would fail).
252-
delete options.multithreading;
253-
if (!Database.HAS_COMMERCIAL) {
254-
throw new Error("Commercial only feature; see http://nativescript.tools/product/10");
255-
}
256-
if (global.TNS_WEBPACK && global.TNS_WEBPACK >= 5 ) {
257-
console.warn("SQLite: Multithreading temporarily disabled on NS 8 because of bug in Webpack")
258-
} else {
259-
return new Database._multiSQL(dbname, options, callback);
260-
}
261-
}
262-
this._options = options;
253+
this._options = options;
263254

264255

265256
// Check to see if it has a path, or if it is a relative dbname
266257
// dbname = "" - Temporary Database
267258
// dbname = ":memory:" = memory database
268259
if (dbname !== "" && dbname !== ":memory:") {
269-
//var pkgName = appModule.android.context.getPackageName();
270260
//noinspection JSUnresolvedFunction
271261
dbname = _getContext().getDatabasePath(dbname).getAbsolutePath().toString();
272262
let path = dbname.substr(0, dbname.lastIndexOf('/') + 1);
@@ -837,7 +827,7 @@ Database.prototype.each = function(sql, params, callback, complete) {
837827

838828
/***
839829
* Converts a Mixed Array to a String Array
840-
* @param params
830+
* @param paramsIn
841831
* @returns {Array}
842832
* @private
843833
*/
@@ -941,7 +931,6 @@ Database.manualBackup = function(name) {
941931
success = false;
942932
}
943933

944-
945934
//Close the streams
946935
// noinspection JSUnresolvedFunction
947936
myOutput.flush();
@@ -1073,13 +1062,11 @@ function _getContext() {
10731062
}
10741063
}
10751064
} catch (err) {
1076-
console.log("Using Fallback");
1077-
/* In some cases Multidex has been the report */
1078-
/* the getNativeApplication calls .getInstance which fails */
1065+
console.log("SQLITE: Using Fallback");
1066+
// In some cases Multidex has been the report
1067+
// the getNativeApplication calls .getInstance which fails
10791068
}
10801069

1081-
1082-
10831070
//noinspection JSUnresolvedFunction,JSUnresolvedVariable
10841071
let ctx = java.lang.Class.forName("android.app.AppGlobals").getMethod("getInitialApplication", null).invoke(null, null);
10851072
if (ctx) return ctx;
@@ -1114,8 +1101,8 @@ function UsePlugin(loadedSrc, DBModule) {
11141101

11151102
function TryLoadingCommercialPlugin() {
11161103
try {
1117-
const sqlCom = require('nativescript-sqlite-commercial');
1118-
UsePlugin(sqlCom, Database);
1104+
const sqlCom = require('nativescript-sqlite-commercial');
1105+
UsePlugin(sqlCom, Database);
11191106
}
11201107
catch (e) {
11211108
/* Do Nothing if it doesn't exist as it is an optional plugin */
@@ -1124,19 +1111,21 @@ function TryLoadingCommercialPlugin() {
11241111

11251112
function TryLoadingEncryptionPlugin() {
11261113
try {
1127-
const sqlEnc = require('nativescript-sqlite-encrypted');
1128-
UsePlugin(sqlEnc, Database);
1114+
const sqlEnc = require('nativescript-sqlite-encrypted');
1115+
UsePlugin(sqlEnc, Database);
11291116
}
1130-
catch (e) { /* Do Nothing if it doesn't exist as it is an optional plugin */
1117+
catch (e) {
1118+
/* Do Nothing if it doesn't exist as it is an optional plugin */
11311119
}
11321120
}
11331121

11341122
function TryLoadingSyncPlugin() {
11351123
try {
1136-
const sqlSync = require('nativescript-sqlite-sync');
1137-
UsePlugin(sqlSync, Database);
1124+
const sqlSync = require('nativescript-sqlite-sync');
1125+
UsePlugin(sqlSync, Database);
11381126
}
1139-
catch (e) { /* Do Nothing if it doesn't exist as it is an optional plugin */
1127+
catch (e) {
1128+
/* Do Nothing if it doesn't exist as it is an optional plugin */
11401129
}
11411130
}
11421131

src/sqlite.ios.js src/sqlite-internal.ios.js

-11
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,6 @@ function Database(dbname, options, callback) {
8484
options = options || {};
8585
}
8686

87-
if (options && options.multithreading && typeof global.Worker === 'function') {
88-
delete options.multithreading;
89-
if (!Database.HAS_COMMERCIAL) {
90-
throw new Error("Commercial only feature; see http://nativescript.tools/product/10");
91-
}
92-
if (global.TNS_WEBPACK && global.TNS_WEBPACK >= 5 ) {
93-
console.warn("SQLite: Multithreading temporarily disabled on NS 8 because of bug in Webpack")
94-
} else {
95-
return new Database._multiSQL(dbname, options, callback);
96-
}
97-
}
9887
this._options = options;
9988

10089
// Check to see if it has a path, or if it is a relative dbname

src/sqlite.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**************************************************************************************
2+
* (c) 2015-2021, Master Technology
3+
* Licensed under the MIT license or contact me for a support, changes, enhancements,
4+
* and/or if you require a commercial licensing
5+
*
6+
* Any questions please feel free to put a issue up on github
7+
* Nathan@master-technology.com http://nativescript.tools
8+
* Version 2.7.0 - Android
9+
*************************************************************************************/
10+
/* global global, require, module */
11+
12+
"use strict";
13+
const DBInternal = require("nativescript-sqlite/sqlite-internal");
14+
15+
function Database(dbname, options, callback) {
16+
if (typeof options === 'function') {
17+
callback = options;
18+
//noinspection JSUnusedAssignment
19+
options = {};
20+
} else {
21+
//noinspection JSUnusedAssignment
22+
options = options || {};
23+
}
24+
25+
if (options && options.multithreading && typeof global.Worker === 'function') {
26+
// We don't want this passed into the worker; to try and start another worker (which would fail).
27+
delete options.multithreading;
28+
/* if (!DBInternal.HAS_COMMERCIAL) {
29+
throw new Error("Commercial only feature; see http://nativescript.tools/product/10");
30+
} */
31+
const multiSQL = require("nativescript-sqlite-commercial/commercial-multi");
32+
return new multiSQL(dbname, options, callback);
33+
}
34+
return new DBInternal(dbname, options, callback);
35+
}
36+
37+
// Copy static Properties & Static functions over so that they still work
38+
for (let item in DBInternal) {
39+
if (DBInternal.hasOwnProperty(item)) {
40+
Database[item] = DBInternal[item];
41+
}
42+
}
43+
44+
if (global.TNS_WEBPACK && global.TNS_WEBPACK >= 5) {
45+
if (global._MT_HAS_SQLITE) {
46+
Database.HAS_COMMERCIAL = (global._MT_HAS_SQLITE & 1) === 1;
47+
Database.HAS_ENCRYPTION = (global._MT_HAS_SQLITE & 2) === 2;
48+
Database.HAS_SYNC = (global._MT_HAS_SQLITE & 4) === 4;
49+
Database.HAS_KEYSTORE = (global._MT_HAS_SQLITE & 8) === 8;
50+
}
51+
}
52+
53+
module.exports = Database;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy