@sqb/sqlite 6.0.13 → 6.1.1
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.d.ts +5 -4
- package/sqlite-connection.js +16 -6
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.1.1",
|
|
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.1.1",
|
|
13
|
+
"@sqb/connect": "^6.1.1",
|
|
14
|
+
"@sqb/sqlite-dialect": "^6.1.1"
|
|
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.d.ts
CHANGED
|
@@ -33,10 +33,11 @@ export declare class SqliteConnection implements Adapter.Connection {
|
|
|
33
33
|
* runs the statement then a synthesized follow-up `SELECT` to emulate
|
|
34
34
|
* `RETURNING` (an `INSERT` is matched back by `ROWID`, an `UPDATE` by
|
|
35
35
|
* reusing the original `WHERE` clause) - `DELETE` isn't emulated here
|
|
36
|
-
* since there's nothing left to re-select afterward.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* since there's nothing left to re-select afterward. A statement that
|
|
37
|
+
* produces no result set (DDL, `PRAGMA`, ...) is simply run. Otherwise
|
|
38
|
+
* prepares and iterates the statement, wrapping it in a {@link
|
|
39
|
+
* SqliteCursor} (returned directly in cursor mode, or eagerly drained up
|
|
40
|
+
* to `fetchRows` rows otherwise).
|
|
40
41
|
*/
|
|
41
42
|
execute(query: QueryRequest): Promise<Adapter.Response>;
|
|
42
43
|
/** Copies a synthesized `SELECT` statement's rows/fields onto `out` - used to emulate `RETURNING` on `INSERT`/`UPDATE`. */
|
package/sqlite-connection.js
CHANGED
|
@@ -79,10 +79,11 @@ export class SqliteConnection {
|
|
|
79
79
|
* runs the statement then a synthesized follow-up `SELECT` to emulate
|
|
80
80
|
* `RETURNING` (an `INSERT` is matched back by `ROWID`, an `UPDATE` by
|
|
81
81
|
* reusing the original `WHERE` clause) - `DELETE` isn't emulated here
|
|
82
|
-
* since there's nothing left to re-select afterward.
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
82
|
+
* since there's nothing left to re-select afterward. A statement that
|
|
83
|
+
* produces no result set (DDL, `PRAGMA`, ...) is simply run. Otherwise
|
|
84
|
+
* prepares and iterates the statement, wrapping it in a {@link
|
|
85
|
+
* SqliteCursor} (returned directly in cursor mode, or eagerly drained up
|
|
86
|
+
* to `fetchRows` rows otherwise).
|
|
86
87
|
*/
|
|
87
88
|
async execute(query) {
|
|
88
89
|
assertDefined(this.intlcon);
|
|
@@ -119,11 +120,20 @@ export class SqliteConnection {
|
|
|
119
120
|
return out;
|
|
120
121
|
}
|
|
121
122
|
const stmt = intlcon.prepare(query.sql);
|
|
123
|
+
if (!stmt.columns().length) {
|
|
124
|
+
// A statement with no result set (DDL, PRAGMA, `INSERT OR REPLACE`,
|
|
125
|
+
// ...). `iterate()` is lazy - it would not run the statement until
|
|
126
|
+
// its first `next()` - so run it outright.
|
|
127
|
+
const info = stmt.run(params);
|
|
128
|
+
if (/^\s*(insert|replace|update|delete)\b/i.test(query.sql))
|
|
129
|
+
out.rowsAffected = info.changes;
|
|
130
|
+
if (query.autoCommit)
|
|
131
|
+
await this.commit();
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
122
134
|
const rowType = query.objectRows ? 'object' : 'array';
|
|
123
135
|
const iterator = stmt.iterate(params);
|
|
124
136
|
const columns = stmt.columns();
|
|
125
|
-
if (!columns.length)
|
|
126
|
-
return out;
|
|
127
137
|
out.fields = this._convertFields(columns);
|
|
128
138
|
out.rowType = rowType;
|
|
129
139
|
const cursor = new SqliteCursor(iterator, { rowType, columns });
|