@atscript/db-sqlite 0.1.147 → 0.1.148

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/dist/index.cjs CHANGED
@@ -78,7 +78,9 @@ var BetterSqlite3Driver = class {
78
78
  registerFunction(name, fn, opts) {
79
79
  this.db.function(name, { deterministic: opts?.deterministic ?? false }, fn);
80
80
  }
81
+ /** Idempotent: closing an already closed database is a no-op. */
81
82
  close() {
83
+ if (!this.db.open) return;
82
84
  this.db.close();
83
85
  }
84
86
  };
@@ -714,10 +716,14 @@ var SqliteAdapter = class SqliteAdapter extends _atscript_db.BaseDbAdapter {
714
716
  calendarBucketUnits() {
715
717
  return this._hasBucketFn ? _atscript_db.ALL_BUCKET_UNITS : super.calendarBucketUnits();
716
718
  }
717
- /** Every aggregate function, `countDistinct` included. */
719
+ /** Every aggregate function: `countDistinct`, `first` and `last` included. */
718
720
  aggregateFns() {
719
721
  return _atscript_db.ALL_AGGREGATE_FNS;
720
722
  }
723
+ /** Arithmetic in an aggregate `$select` (`{ $expr }`, `{ $fn, $expr }`). */
724
+ supportsAggregateExpressions() {
725
+ return true;
726
+ }
721
727
  /** Computed view columns and first-row joins. */
722
728
  viewCapabilities() {
723
729
  return _atscript_db.ALL_VIEW_CAPABILITIES;
@@ -940,6 +946,29 @@ var SqliteAdapter = class SqliteAdapter extends _atscript_db.BaseDbAdapter {
940
946
  };
941
947
  });
942
948
  }
949
+ supportsInsertIgnore() {
950
+ return true;
951
+ }
952
+ /**
953
+ * Per row `INSERT … ON CONFLICT DO NOTHING` (covers the primary key and every
954
+ * unique index; NOT NULL / CHECK / FK still raise — never `INSERT OR IGNORE`).
955
+ * `changes === 0` marks a skipped row.
956
+ */
957
+ async insertManyIgnore(data) {
958
+ return this.withTransaction(async () => {
959
+ const slots = [];
960
+ const tableName = this.resolveTableName();
961
+ for (const row of data) {
962
+ const built = buildInsert(tableName, row);
963
+ const sql = `${built.sql} ON CONFLICT DO NOTHING`;
964
+ const params = built.params;
965
+ this._log(sql, params);
966
+ const result = await this._stmt(() => this._wrapConstraintError(() => this.driver.run(sql, params)));
967
+ slots.push(result.changes === 0 ? null : { insertedId: this._resolveInsertedId(row, result.lastInsertRowid) });
968
+ }
969
+ return slots;
970
+ });
971
+ }
943
972
  async findOne(query) {
944
973
  const where = buildWhere(query.filter);
945
974
  const controls = {
@@ -1821,7 +1850,7 @@ function createAdapter(connection, options) {
1821
1850
  transactionWaitTimeoutMs,
1822
1851
  transactionWaitWarnMs
1823
1852
  };
1824
- return new _atscript_db.DbSpace(() => new SqliteAdapter(driver, adapterOptions));
1853
+ return new _atscript_db.DbSpace(() => new SqliteAdapter(driver, adapterOptions), { onClose: () => driver.close() });
1825
1854
  }
1826
1855
  //#endregion
1827
1856
  exports.BetterSqlite3Driver = BetterSqlite3Driver;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TReferencingForeignKey, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair, TViewCapability } from "@atscript/db";
1
+ import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TReferencingForeignKey, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair, TViewCapability } from "@atscript/db";
2
2
  import { TMetadataMap } from "@atscript/typescript/utils";
3
3
  import { FilterExpr as FilterExpr$1 } from "@uniqu/core";
4
4
  import { TFilterVisitorOptions, TSqlFragment, TSqlFragment as TSqlFragment$1 } from "@atscript/db-sql-tools";
@@ -121,6 +121,7 @@ declare class BetterSqlite3Driver implements TSqliteDriver {
121
121
  registerFunction(name: string, fn: (...args: any[]) => unknown, opts?: {
122
122
  deterministic?: boolean;
123
123
  }): void;
124
+ /** Idempotent: closing an already closed database is a no-op. */
124
125
  close(): void;
125
126
  }
126
127
  //#endregion
@@ -267,8 +268,10 @@ declare class SqliteAdapter extends BaseDbAdapter {
267
268
  * none otherwise (`BUCKET_NOT_SUPPORTED`, a clean 400).
268
269
  */
269
270
  calendarBucketUnits(): ReadonlySet<BucketUnit>;
270
- /** Every aggregate function, `countDistinct` included. */
271
+ /** Every aggregate function: `countDistinct`, `first` and `last` included. */
271
272
  aggregateFns(): ReadonlySet<AggregateFn>;
273
+ /** Arithmetic in an aggregate `$select` (`{ $expr }`, `{ $fn, $expr }`). */
274
+ supportsAggregateExpressions(): boolean;
272
275
  /** Computed view columns and first-row joins. */
273
276
  viewCapabilities(): ReadonlySet<TViewCapability>;
274
277
  /** Whether the SQLite connection has the sqlite-vec extension loaded. */
@@ -338,6 +341,13 @@ declare class SqliteAdapter extends BaseDbAdapter {
338
341
  private _wrapConstraintError;
339
342
  insertOne(data: Record<string, unknown>): Promise<TDbInsertResult>;
340
343
  insertMany(data: Array<Record<string, unknown>>): Promise<TDbInsertManyResult>;
344
+ supportsInsertIgnore(): boolean;
345
+ /**
346
+ * Per row `INSERT … ON CONFLICT DO NOTHING` (covers the primary key and every
347
+ * unique index; NOT NULL / CHECK / FK still raise — never `INSERT OR IGNORE`).
348
+ * `changes === 0` marks a skipped row.
349
+ */
350
+ insertManyIgnore(data: Array<Record<string, unknown>>): Promise<TDbInsertIgnoreSlot[]>;
341
351
  findOne(query: DbQuery): Promise<Record<string, unknown> | null>;
342
352
  findMany(query: DbQuery): Promise<Array<Record<string, unknown>>>;
343
353
  /**
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TReferencingForeignKey, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair, TViewCapability } from "@atscript/db";
1
+ import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TReferencingForeignKey, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair, TViewCapability } from "@atscript/db";
2
2
  import { TFilterVisitorOptions, TSqlFragment, TSqlFragment as TSqlFragment$1 } from "@atscript/db-sql-tools";
3
3
  import { FilterExpr as FilterExpr$1 } from "@uniqu/core";
4
4
  import { TMetadataMap } from "@atscript/typescript/utils";
@@ -121,6 +121,7 @@ declare class BetterSqlite3Driver implements TSqliteDriver {
121
121
  registerFunction(name: string, fn: (...args: any[]) => unknown, opts?: {
122
122
  deterministic?: boolean;
123
123
  }): void;
124
+ /** Idempotent: closing an already closed database is a no-op. */
124
125
  close(): void;
125
126
  }
126
127
  //#endregion
@@ -267,8 +268,10 @@ declare class SqliteAdapter extends BaseDbAdapter {
267
268
  * none otherwise (`BUCKET_NOT_SUPPORTED`, a clean 400).
268
269
  */
269
270
  calendarBucketUnits(): ReadonlySet<BucketUnit>;
270
- /** Every aggregate function, `countDistinct` included. */
271
+ /** Every aggregate function: `countDistinct`, `first` and `last` included. */
271
272
  aggregateFns(): ReadonlySet<AggregateFn>;
273
+ /** Arithmetic in an aggregate `$select` (`{ $expr }`, `{ $fn, $expr }`). */
274
+ supportsAggregateExpressions(): boolean;
272
275
  /** Computed view columns and first-row joins. */
273
276
  viewCapabilities(): ReadonlySet<TViewCapability>;
274
277
  /** Whether the SQLite connection has the sqlite-vec extension loaded. */
@@ -338,6 +341,13 @@ declare class SqliteAdapter extends BaseDbAdapter {
338
341
  private _wrapConstraintError;
339
342
  insertOne(data: Record<string, unknown>): Promise<TDbInsertResult>;
340
343
  insertMany(data: Array<Record<string, unknown>>): Promise<TDbInsertManyResult>;
344
+ supportsInsertIgnore(): boolean;
345
+ /**
346
+ * Per row `INSERT … ON CONFLICT DO NOTHING` (covers the primary key and every
347
+ * unique index; NOT NULL / CHECK / FK still raise — never `INSERT OR IGNORE`).
348
+ * `changes === 0` marks a skipped row.
349
+ */
350
+ insertManyIgnore(data: Array<Record<string, unknown>>): Promise<TDbInsertIgnoreSlot[]>;
341
351
  findOne(query: DbQuery): Promise<Record<string, unknown> | null>;
342
352
  findMany(query: DbQuery): Promise<Array<Record<string, unknown>>>;
343
353
  /**
package/dist/index.mjs CHANGED
@@ -77,7 +77,9 @@ var BetterSqlite3Driver = class {
77
77
  registerFunction(name, fn, opts) {
78
78
  this.db.function(name, { deterministic: opts?.deterministic ?? false }, fn);
79
79
  }
80
+ /** Idempotent: closing an already closed database is a no-op. */
80
81
  close() {
82
+ if (!this.db.open) return;
81
83
  this.db.close();
82
84
  }
83
85
  };
@@ -713,10 +715,14 @@ var SqliteAdapter = class SqliteAdapter extends BaseDbAdapter {
713
715
  calendarBucketUnits() {
714
716
  return this._hasBucketFn ? ALL_BUCKET_UNITS : super.calendarBucketUnits();
715
717
  }
716
- /** Every aggregate function, `countDistinct` included. */
718
+ /** Every aggregate function: `countDistinct`, `first` and `last` included. */
717
719
  aggregateFns() {
718
720
  return ALL_AGGREGATE_FNS;
719
721
  }
722
+ /** Arithmetic in an aggregate `$select` (`{ $expr }`, `{ $fn, $expr }`). */
723
+ supportsAggregateExpressions() {
724
+ return true;
725
+ }
720
726
  /** Computed view columns and first-row joins. */
721
727
  viewCapabilities() {
722
728
  return ALL_VIEW_CAPABILITIES;
@@ -939,6 +945,29 @@ var SqliteAdapter = class SqliteAdapter extends BaseDbAdapter {
939
945
  };
940
946
  });
941
947
  }
948
+ supportsInsertIgnore() {
949
+ return true;
950
+ }
951
+ /**
952
+ * Per row `INSERT … ON CONFLICT DO NOTHING` (covers the primary key and every
953
+ * unique index; NOT NULL / CHECK / FK still raise — never `INSERT OR IGNORE`).
954
+ * `changes === 0` marks a skipped row.
955
+ */
956
+ async insertManyIgnore(data) {
957
+ return this.withTransaction(async () => {
958
+ const slots = [];
959
+ const tableName = this.resolveTableName();
960
+ for (const row of data) {
961
+ const built = buildInsert$1(tableName, row);
962
+ const sql = `${built.sql} ON CONFLICT DO NOTHING`;
963
+ const params = built.params;
964
+ this._log(sql, params);
965
+ const result = await this._stmt(() => this._wrapConstraintError(() => this.driver.run(sql, params)));
966
+ slots.push(result.changes === 0 ? null : { insertedId: this._resolveInsertedId(row, result.lastInsertRowid) });
967
+ }
968
+ return slots;
969
+ });
970
+ }
942
971
  async findOne(query) {
943
972
  const where = buildWhere(query.filter);
944
973
  const controls = {
@@ -1820,7 +1849,7 @@ function createAdapter(connection, options) {
1820
1849
  transactionWaitTimeoutMs,
1821
1850
  transactionWaitWarnMs
1822
1851
  };
1823
- return new DbSpace(() => new SqliteAdapter(driver, adapterOptions));
1852
+ return new DbSpace(() => new SqliteAdapter(driver, adapterOptions), { onClose: () => driver.close() });
1824
1853
  }
1825
1854
  //#endregion
1826
1855
  export { BetterSqlite3Driver, SqliteAdapter, SqliteTxGate, SqliteTxState, buildWhere, createAdapter, getSqliteTxGate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-sqlite",
3
- "version": "0.1.147",
3
+ "version": "0.1.148",
4
4
  "description": "SQLite adapter for @atscript/db with swappable driver support.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -36,21 +36,21 @@
36
36
  "access": "public"
37
37
  },
38
38
  "devDependencies": {
39
- "@atscript/core": "^0.1.99",
40
- "@atscript/typescript": "^0.1.99",
39
+ "@atscript/core": "^0.1.100",
40
+ "@atscript/typescript": "^0.1.100",
41
41
  "@types/better-sqlite3": "^7.6.13",
42
- "@uniqu/core": "^0.1.12",
42
+ "@uniqu/core": "^0.1.13",
43
43
  "better-sqlite3": "^12.6.2",
44
44
  "sqlite-vec": "^0.1.9",
45
- "unplugin-atscript": "^0.1.99"
45
+ "unplugin-atscript": "^0.1.100"
46
46
  },
47
47
  "peerDependencies": {
48
- "@atscript/core": "^0.1.99",
49
- "@atscript/typescript": "^0.1.99",
50
- "@uniqu/core": "^0.1.12",
48
+ "@atscript/core": "^0.1.100",
49
+ "@atscript/typescript": "^0.1.100",
50
+ "@uniqu/core": "^0.1.13",
51
51
  "better-sqlite3": ">=11.0.0",
52
- "@atscript/db": "^0.1.147",
53
- "@atscript/db-sql-tools": "^0.1.147"
52
+ "@atscript/db": "^0.1.148",
53
+ "@atscript/db-sql-tools": "^0.1.148"
54
54
  },
55
55
  "peerDependenciesMeta": {
56
56
  "better-sqlite3": {