@sqb/sqljs 4.14.1 → 4.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.js +5 -3
- package/esm/sqljs-adapter.js +18 -12
- package/esm/sqljs-connection.js +7 -3
- package/esm/sqljs-cursor.js +5 -1
- package/package.json +24 -18
- package/cjs/package.json +0 -3
package/esm/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const connect_1 = require("@sqb/connect");
|
|
4
|
+
const sqljs_adapter_js_1 = require("./sqljs-adapter.js");
|
|
5
|
+
connect_1.AdapterRegistry.register(new sqljs_adapter_js_1.SqljsAdapter());
|
package/esm/sqljs-adapter.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqljsAdapter = void 0;
|
|
4
|
+
exports.closeMemoryDatabase = closeMemoryDatabase;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
require("@sqb/sqlite-dialect");
|
|
7
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
8
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
+
const putil_promisify_1 = tslib_1.__importDefault(require("putil-promisify"));
|
|
10
|
+
const sql_js_1 = tslib_1.__importDefault(require("sql.js"));
|
|
11
|
+
const sqljs_connection_js_1 = require("./sqljs-connection.js");
|
|
7
12
|
const dbCache = new Map();
|
|
8
|
-
|
|
13
|
+
class SqljsAdapter {
|
|
9
14
|
constructor() {
|
|
10
15
|
this.driver = 'sqljs';
|
|
11
16
|
this.dialect = 'sqlite';
|
|
@@ -25,27 +30,27 @@ export class SqljsAdapter {
|
|
|
25
30
|
dbName = config.database;
|
|
26
31
|
}
|
|
27
32
|
else {
|
|
28
|
-
dbName =
|
|
33
|
+
dbName = path_1.default.resolve(config.database);
|
|
29
34
|
}
|
|
30
35
|
let intlDb = dbCache.get(dbName);
|
|
31
36
|
if (intlDb) {
|
|
32
37
|
intlDb._refCount++;
|
|
33
38
|
}
|
|
34
39
|
else {
|
|
35
|
-
const SQL = await
|
|
40
|
+
const SQL = await (0, sql_js_1.default)();
|
|
36
41
|
if (isMemory) {
|
|
37
42
|
intlDb = new SQL.Database();
|
|
38
43
|
intlDb._refCount = 0;
|
|
39
44
|
}
|
|
40
45
|
else {
|
|
41
|
-
const buf = await
|
|
46
|
+
const buf = await putil_promisify_1.default.fromCallback(cb => fs_1.default.readFile(dbName, cb));
|
|
42
47
|
intlDb = new SQL.Database(buf);
|
|
43
48
|
intlDb._refCount = 1;
|
|
44
49
|
}
|
|
45
50
|
dbCache.set(dbName, intlDb);
|
|
46
51
|
}
|
|
47
52
|
const _intlDb = intlDb;
|
|
48
|
-
return new SqljsConnection(_intlDb, () => {
|
|
53
|
+
return new sqljs_connection_js_1.SqljsConnection(_intlDb, () => {
|
|
49
54
|
if (isMemory)
|
|
50
55
|
return;
|
|
51
56
|
if (--_intlDb._refCount <= 0) {
|
|
@@ -55,7 +60,8 @@ export class SqljsAdapter {
|
|
|
55
60
|
});
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
|
-
|
|
63
|
+
exports.SqljsAdapter = SqljsAdapter;
|
|
64
|
+
async function closeMemoryDatabase(name) {
|
|
59
65
|
const memoryDbName = name || ':memory:';
|
|
60
66
|
const memDb = dbCache.get(memoryDbName);
|
|
61
67
|
if (memDb) {
|
package/esm/sqljs-connection.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqljsConnection = void 0;
|
|
4
|
+
const sqljs_cursor_js_1 = require("./sqljs-cursor.js");
|
|
5
|
+
class SqljsConnection {
|
|
3
6
|
constructor(db, _onClose) {
|
|
4
7
|
this._onClose = _onClose;
|
|
5
8
|
this.intlcon = db;
|
|
@@ -105,7 +108,7 @@ export class SqljsConnection {
|
|
|
105
108
|
out.fields = this._convertFields(colNames);
|
|
106
109
|
const rowType = query.objectRows ? 'object' : 'array';
|
|
107
110
|
out.rowType = rowType;
|
|
108
|
-
const cursor = new SqljsCursor(stmt, { rowType });
|
|
111
|
+
const cursor = new sqljs_cursor_js_1.SqljsCursor(stmt, { rowType });
|
|
109
112
|
if (query.cursor) {
|
|
110
113
|
out.cursor = cursor;
|
|
111
114
|
stmt = undefined;
|
|
@@ -135,6 +138,7 @@ export class SqljsConnection {
|
|
|
135
138
|
return result;
|
|
136
139
|
}
|
|
137
140
|
}
|
|
141
|
+
exports.SqljsConnection = SqljsConnection;
|
|
138
142
|
function assertDefined(d) {
|
|
139
143
|
if (d == null)
|
|
140
144
|
throw new Error('Invalid data');
|
package/esm/sqljs-cursor.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqljsCursor = void 0;
|
|
4
|
+
class SqljsCursor {
|
|
2
5
|
constructor(stmt, opts) {
|
|
3
6
|
this._rowType = opts.rowType;
|
|
4
7
|
this._stmt = stmt;
|
|
@@ -26,3 +29,4 @@ export class SqljsCursor {
|
|
|
26
29
|
return rows;
|
|
27
30
|
}
|
|
28
31
|
}
|
|
32
|
+
exports.SqljsCursor = SqljsCursor;
|
package/package.json
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/sqljs",
|
|
3
3
|
"description": "SQB serialization extension for sql.js driver",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.15.0",
|
|
5
5
|
"author": "Panates",
|
|
6
|
-
"contributors": [
|
|
7
|
-
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
8
|
-
"Ilker Gurelli <i.gurelli@panates.com>"
|
|
9
|
-
],
|
|
10
6
|
"license": "Apache-2.0",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "https://github.com/sqbjs/sqb.git",
|
|
14
|
-
"directory": "packages/sqljs"
|
|
15
|
-
},
|
|
16
|
-
"type": "module",
|
|
17
|
-
"module": "./esm/index.js",
|
|
18
|
-
"main": "./cjs/index.js",
|
|
19
|
-
"types": "./types/index.d.ts",
|
|
20
7
|
"scripts": {
|
|
21
8
|
"compile": "tsc",
|
|
22
9
|
"prebuild": "npm run lint && npm run clean",
|
|
23
10
|
"build": "npm run build:cjs && npm run build:esm",
|
|
24
11
|
"build:cjs": "tsc -b tsconfig-build-cjs.json",
|
|
25
12
|
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
26
|
-
"postbuild": "cp README.md package.json ../../LICENSE ../../build/sqljs
|
|
13
|
+
"postbuild": "cp README.md package.json ../../LICENSE ../../build/sqljs",
|
|
27
14
|
"lint": "eslint . --max-warnings=0",
|
|
28
15
|
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
29
16
|
"format": "prettier . --write --log-level=warn",
|
|
@@ -42,11 +29,30 @@
|
|
|
42
29
|
"sql.js": "^1.11.0"
|
|
43
30
|
},
|
|
44
31
|
"peerDependencies": {
|
|
45
|
-
"@sqb/builder": "^4.
|
|
46
|
-
"@sqb/connect": "^4.
|
|
47
|
-
"@sqb/sqlite-dialect": "^4.
|
|
32
|
+
"@sqb/builder": "^4.15.0",
|
|
33
|
+
"@sqb/connect": "^4.15.0",
|
|
34
|
+
"@sqb/sqlite-dialect": "^4.15.0",
|
|
48
35
|
"sql.js": "^1.8.0"
|
|
49
36
|
},
|
|
37
|
+
"main": "./cjs/index.js",
|
|
38
|
+
"module": "./esm/index.js",
|
|
39
|
+
"types": "./types/index.d.ts",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"require": "./cjs/index.js",
|
|
43
|
+
"import": "./esm/index.js",
|
|
44
|
+
"types": "./types/index.d.ts"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"contributors": [
|
|
48
|
+
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
49
|
+
"Ilker Gurelli <i.gurelli@panates.com>"
|
|
50
|
+
],
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/sqbjs/sqb.git",
|
|
54
|
+
"directory": "packages/sqljs"
|
|
55
|
+
},
|
|
50
56
|
"engines": {
|
|
51
57
|
"node": ">=16.0",
|
|
52
58
|
"npm": ">=7.0.0"
|
package/cjs/package.json
DELETED