@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 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
@@ -1,3 +1,3 @@
1
1
  /** This package's own version, kept in step with its `package.json` by `rman version`
2
2
  * (see `.rmanrc` `version.stamp`) - never edit it by hand. */
3
- export declare const version = "6.0.13";
3
+ export declare const version = "6.1.1";
package/constants.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /** This package's own version, kept in step with its `package.json` by `rman version`
2
2
  * (see `.rmanrc` `version.stamp`) - never edit it by hand. */
3
- export const version = '6.0.13';
3
+ export const version = '6.1.1';
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.0.13",
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.0.13",
13
- "@sqb/connect": "^6.0.13",
14
- "@sqb/sqlite-dialect": "^6.0.13"
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
- intlDb = (await openDatabase(dbName));
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
  }
@@ -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. Otherwise prepares
37
- * and iterates the statement, wrapping it in a {@link SqliteCursor}
38
- * (returned directly in cursor mode, or eagerly drained up to
39
- * `fetchRows` rows otherwise).
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`. */
@@ -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. Otherwise prepares
83
- * and iterates the statement, wrapping it in a {@link SqliteCursor}
84
- * (returned directly in cursor mode, or eagerly drained up to
85
- * `fetchRows` rows otherwise).
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 });