@sqb/sqljs 4.15.0 → 4.16.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 +3 -5
- package/esm/sqljs-adapter.js +12 -18
- package/esm/sqljs-connection.js +3 -7
- package/esm/sqljs-cursor.js +1 -5
- package/package.json +4 -4
package/esm/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const sqljs_adapter_js_1 = require("./sqljs-adapter.js");
|
|
5
|
-
connect_1.AdapterRegistry.register(new sqljs_adapter_js_1.SqljsAdapter());
|
|
1
|
+
import { AdapterRegistry } from '@sqb/connect';
|
|
2
|
+
import { SqljsAdapter } from './sqljs-adapter.js';
|
|
3
|
+
AdapterRegistry.register(new SqljsAdapter());
|
package/esm/sqljs-adapter.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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");
|
|
1
|
+
import '@sqb/sqlite-dialect';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import promisify from 'putil-promisify';
|
|
5
|
+
import initSqlJs from 'sql.js';
|
|
6
|
+
import { SqljsConnection } from './sqljs-connection.js';
|
|
12
7
|
const dbCache = new Map();
|
|
13
|
-
class SqljsAdapter {
|
|
8
|
+
export class SqljsAdapter {
|
|
14
9
|
constructor() {
|
|
15
10
|
this.driver = 'sqljs';
|
|
16
11
|
this.dialect = 'sqlite';
|
|
@@ -30,27 +25,27 @@ class SqljsAdapter {
|
|
|
30
25
|
dbName = config.database;
|
|
31
26
|
}
|
|
32
27
|
else {
|
|
33
|
-
dbName =
|
|
28
|
+
dbName = path.resolve(config.database);
|
|
34
29
|
}
|
|
35
30
|
let intlDb = dbCache.get(dbName);
|
|
36
31
|
if (intlDb) {
|
|
37
32
|
intlDb._refCount++;
|
|
38
33
|
}
|
|
39
34
|
else {
|
|
40
|
-
const SQL = await (
|
|
35
|
+
const SQL = await initSqlJs();
|
|
41
36
|
if (isMemory) {
|
|
42
37
|
intlDb = new SQL.Database();
|
|
43
38
|
intlDb._refCount = 0;
|
|
44
39
|
}
|
|
45
40
|
else {
|
|
46
|
-
const buf = await
|
|
41
|
+
const buf = await promisify.fromCallback(cb => fs.readFile(dbName, cb));
|
|
47
42
|
intlDb = new SQL.Database(buf);
|
|
48
43
|
intlDb._refCount = 1;
|
|
49
44
|
}
|
|
50
45
|
dbCache.set(dbName, intlDb);
|
|
51
46
|
}
|
|
52
47
|
const _intlDb = intlDb;
|
|
53
|
-
return new
|
|
48
|
+
return new SqljsConnection(_intlDb, () => {
|
|
54
49
|
if (isMemory)
|
|
55
50
|
return;
|
|
56
51
|
if (--_intlDb._refCount <= 0) {
|
|
@@ -60,8 +55,7 @@ class SqljsAdapter {
|
|
|
60
55
|
});
|
|
61
56
|
}
|
|
62
57
|
}
|
|
63
|
-
|
|
64
|
-
async function closeMemoryDatabase(name) {
|
|
58
|
+
export async function closeMemoryDatabase(name) {
|
|
65
59
|
const memoryDbName = name || ':memory:';
|
|
66
60
|
const memDb = dbCache.get(memoryDbName);
|
|
67
61
|
if (memDb) {
|
package/esm/sqljs-connection.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.SqljsConnection = void 0;
|
|
4
|
-
const sqljs_cursor_js_1 = require("./sqljs-cursor.js");
|
|
5
|
-
class SqljsConnection {
|
|
1
|
+
import { SqljsCursor } from './sqljs-cursor.js';
|
|
2
|
+
export class SqljsConnection {
|
|
6
3
|
constructor(db, _onClose) {
|
|
7
4
|
this._onClose = _onClose;
|
|
8
5
|
this.intlcon = db;
|
|
@@ -108,7 +105,7 @@ class SqljsConnection {
|
|
|
108
105
|
out.fields = this._convertFields(colNames);
|
|
109
106
|
const rowType = query.objectRows ? 'object' : 'array';
|
|
110
107
|
out.rowType = rowType;
|
|
111
|
-
const cursor = new
|
|
108
|
+
const cursor = new SqljsCursor(stmt, { rowType });
|
|
112
109
|
if (query.cursor) {
|
|
113
110
|
out.cursor = cursor;
|
|
114
111
|
stmt = undefined;
|
|
@@ -138,7 +135,6 @@ class SqljsConnection {
|
|
|
138
135
|
return result;
|
|
139
136
|
}
|
|
140
137
|
}
|
|
141
|
-
exports.SqljsConnection = SqljsConnection;
|
|
142
138
|
function assertDefined(d) {
|
|
143
139
|
if (d == null)
|
|
144
140
|
throw new Error('Invalid data');
|
package/esm/sqljs-cursor.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SqljsCursor = void 0;
|
|
4
|
-
class SqljsCursor {
|
|
1
|
+
export class SqljsCursor {
|
|
5
2
|
constructor(stmt, opts) {
|
|
6
3
|
this._rowType = opts.rowType;
|
|
7
4
|
this._stmt = stmt;
|
|
@@ -29,4 +26,3 @@ class SqljsCursor {
|
|
|
29
26
|
return rows;
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
exports.SqljsCursor = SqljsCursor;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/sqljs",
|
|
3
3
|
"description": "SQB serialization extension for sql.js driver",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.16.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"scripts": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"sql.js": "^1.11.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@sqb/builder": "^4.
|
|
33
|
-
"@sqb/connect": "^4.
|
|
34
|
-
"@sqb/sqlite-dialect": "^4.
|
|
32
|
+
"@sqb/builder": "^4.16.0",
|
|
33
|
+
"@sqb/connect": "^4.16.0",
|
|
34
|
+
"@sqb/sqlite-dialect": "^4.16.0",
|
|
35
35
|
"sql.js": "^1.8.0"
|
|
36
36
|
},
|
|
37
37
|
"main": "./cjs/index.js",
|