@sqb/sqlite 6.1.0 → 6.2.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/README.md +1 -1
- package/constants.d.ts +1 -1
- package/constants.js +1 -1
- package/package.json +4 -4
- package/sqlite-adapter.js +4 -1
- package/sqlite-connection.js +16 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ import { SqbClient } from '@sqb/connect';
|
|
|
42
42
|
|
|
43
43
|
const client = new SqbClient({
|
|
44
44
|
driver: 'sqlite',
|
|
45
|
-
database: '/path/to/database.db', // or ':memory:'
|
|
45
|
+
database: '/path/to/database.db', // or ':memory:' (optionally suffixed, e.g. ':memory:test1')
|
|
46
46
|
});
|
|
47
47
|
```
|
|
48
48
|
|
package/constants.d.ts
CHANGED
package/constants.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/sqlite",
|
|
3
3
|
"description": "SQB adapter for Node.js and Bun's native SQLite drivers",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.2.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"homepage": "https://www.sqbjs.org",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"tslib": "^2.8.1"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@sqb/builder": "^6.
|
|
13
|
-
"@sqb/connect": "^6.
|
|
14
|
-
"@sqb/sqlite-dialect": "^6.
|
|
12
|
+
"@sqb/builder": "^6.2.0",
|
|
13
|
+
"@sqb/connect": "^6.2.0",
|
|
14
|
+
"@sqb/sqlite-dialect": "^6.2.0"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
17
|
"module": "./index.js",
|
package/sqlite-adapter.js
CHANGED
|
@@ -45,7 +45,10 @@ export class SqliteAdapter {
|
|
|
45
45
|
intlDb._refCount++;
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
|
|
48
|
+
// SQLite only knows the bare `:memory:`; a `:memory:name` passed
|
|
49
|
+
// through as-is would open a file of that name. Every name gets its
|
|
50
|
+
// own `:memory:` handle, kept apart by the cache key.
|
|
51
|
+
intlDb = (await openDatabase(isMemory ? ':memory:' : dbName));
|
|
49
52
|
intlDb._refCount = isMemory ? 0 : 1;
|
|
50
53
|
dbCache.set(dbName, intlDb);
|
|
51
54
|
}
|
package/sqlite-connection.js
CHANGED
|
@@ -113,7 +113,7 @@ export class SqliteConnection {
|
|
|
113
113
|
const m2 = query.sql.match(/where (.+)/i);
|
|
114
114
|
sql += m2 ? ' where ' + m2[1] : '';
|
|
115
115
|
const selStmt = intlcon.prepare(sql);
|
|
116
|
-
this._fillSelectResult(out, selStmt, selStmt.all(params), query);
|
|
116
|
+
this._fillSelectResult(out, selStmt, selStmt.all(pickParams(sql, params)), query);
|
|
117
117
|
return out;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -182,6 +182,21 @@ function mapParams(params) {
|
|
|
182
182
|
out[':' + k] = params[k];
|
|
183
183
|
return out;
|
|
184
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Keeps only the (already `:`-prefixed) params that `sql` references:
|
|
187
|
+
* `node:sqlite` throws on a named parameter the statement doesn't have, and
|
|
188
|
+
* the `SET` values of an `UPDATE` are not part of its re-`SELECT`.
|
|
189
|
+
*/
|
|
190
|
+
function pickParams(sql, params) {
|
|
191
|
+
if (!params)
|
|
192
|
+
return params;
|
|
193
|
+
const used = new Set(sql.match(/:[\w$]+/g));
|
|
194
|
+
const out = {};
|
|
195
|
+
for (const k of Object.keys(params))
|
|
196
|
+
if (used.has(k))
|
|
197
|
+
out[k] = params[k];
|
|
198
|
+
return out;
|
|
199
|
+
}
|
|
185
200
|
/**
|
|
186
201
|
* Maps a SQLite declared column type to a {dataType, jsType} pair using
|
|
187
202
|
* SQLite's type affinity rules (https://www.sqlite.org/datatype3.html).
|