@atscript/db-sqlite 0.1.134 → 0.1.136

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
@@ -273,9 +273,27 @@ const sqliteDialect = {
273
273
  };
274
274
  },
275
275
  calendarBucket: sqliteCalendarBucket,
276
+ jsonExtract: sqliteJsonExtract,
276
277
  createViewPrefix: "CREATE VIEW IF NOT EXISTS"
277
278
  };
278
279
  /**
280
+ * Typed read of a JSON leaf (`SqlDialect.jsonExtract`): `json_type()` guards
281
+ * the declared type, so a missing path, JSON `null` or another JSON type
282
+ * yields NULL (no coercion). Booleans come back as 1/0 — the view's boolean
283
+ * formatter converts them.
284
+ */
285
+ function sqliteJsonExtract(quotedCol, path, type) {
286
+ const p = (0, _atscript_db_sql_tools.jsonDollarPath)(path);
287
+ const t = `json_type(${quotedCol}, ${p})`;
288
+ const v = `json_extract(${quotedCol}, ${p})`;
289
+ switch (type) {
290
+ case "string": return `CASE ${t} WHEN 'text' THEN ${v} END`;
291
+ case "number": return `CASE ${t} WHEN 'integer' THEN ${v} WHEN 'real' THEN ${v} END`;
292
+ case "boolean": return `CASE ${t} WHEN 'true' THEN 1 WHEN 'false' THEN 0 END`;
293
+ default: return type;
294
+ }
295
+ }
296
+ /**
279
297
  * Great-circle distance in meters from a JSON-stored `[lng, lat]` column to a
280
298
  * query point, via the haversine formula (mean earth radius 6 371 000 m).
281
299
  * NULL columns yield NULL — geo search excludes them, matching `$geoNear`.
@@ -671,6 +689,10 @@ var SqliteAdapter = class SqliteAdapter extends _atscript_db.BaseDbAdapter {
671
689
  calendarBucketUnits() {
672
690
  return this._hasBucketFn ? _atscript_db.ALL_BUCKET_UNITS : super.calendarBucketUnits();
673
691
  }
692
+ /** Every aggregate function, `countDistinct` included. */
693
+ aggregateFns() {
694
+ return _atscript_db.ALL_AGGREGATE_FNS;
695
+ }
674
696
  /** Whether the SQLite connection has the sqlite-vec extension loaded. */
675
697
  _supportsVector;
676
698
  /** Whether SQLite math functions (radians/asin/...) are available — geo search. */
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TReferencingForeignKey, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair } from "@atscript/db";
1
+ import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TReferencingForeignKey, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair } from "@atscript/db";
2
2
  import { TMetadataMap } from "@atscript/typescript/utils";
3
3
  import { FilterExpr as FilterExpr$1 } from "@uniqu/core";
4
4
  import { TSqlFragment, TSqlFragment as TSqlFragment$1 } from "@atscript/db-sql-tools";
@@ -267,6 +267,8 @@ declare class SqliteAdapter extends BaseDbAdapter {
267
267
  * none otherwise (`BUCKET_NOT_SUPPORTED`, a clean 400).
268
268
  */
269
269
  calendarBucketUnits(): ReadonlySet<BucketUnit>;
270
+ /** Every aggregate function, `countDistinct` included. */
271
+ aggregateFns(): ReadonlySet<AggregateFn>;
270
272
  /** Whether the SQLite connection has the sqlite-vec extension loaded. */
271
273
  private _supportsVector;
272
274
  /** Whether SQLite math functions (radians/asin/...) are available — geo search. */
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TReferencingForeignKey, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair } from "@atscript/db";
1
+ import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TReferencingForeignKey, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair } from "@atscript/db";
2
2
  import { 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";
@@ -267,6 +267,8 @@ declare class SqliteAdapter extends BaseDbAdapter {
267
267
  * none otherwise (`BUCKET_NOT_SUPPORTED`, a clean 400).
268
268
  */
269
269
  calendarBucketUnits(): ReadonlySet<BucketUnit>;
270
+ /** Every aggregate function, `countDistinct` included. */
271
+ aggregateFns(): ReadonlySet<AggregateFn>;
270
272
  /** Whether the SQLite connection has the sqlite-vec extension loaded. */
271
273
  private _supportsVector;
272
274
  /** Whether SQLite math functions (radians/asin/...) are available — geo search. */
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
- import { ALL_BUCKET_UNITS, BaseDbAdapter, DbError, DbSpace } from "@atscript/db";
2
+ import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, BaseDbAdapter, DbError, DbSpace } from "@atscript/db";
3
3
  import { resolveAggregateSearch } from "@atscript/db/agg";
4
- import { EMPTY_AND, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildInsert, buildSelect, buildUpdate, buildWhere as buildWhere$1, defaultValueForType, defaultValueToSqlLiteral, fillReplacePayload, geoWindowFromControls, parseRegexString, refActionToSql, renameGeoDistance, replaceColumnsFor, sqlTimeZoneLiteral, toSqlValue } from "@atscript/db-sql-tools";
4
+ import { EMPTY_AND, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildInsert, buildSelect, buildUpdate, buildWhere as buildWhere$1, defaultValueForType, defaultValueToSqlLiteral, fillReplacePayload, geoWindowFromControls, jsonDollarPath, parseRegexString, refActionToSql, renameGeoDistance, replaceColumnsFor, sqlTimeZoneLiteral, toSqlValue } from "@atscript/db-sql-tools";
5
5
  import { bucketer } from "@uniqu/core";
6
6
  import { AsyncLocalStorage } from "node:async_hooks";
7
7
  //#region src/better-sqlite3-driver.ts
@@ -272,9 +272,27 @@ const sqliteDialect = {
272
272
  };
273
273
  },
274
274
  calendarBucket: sqliteCalendarBucket,
275
+ jsonExtract: sqliteJsonExtract,
275
276
  createViewPrefix: "CREATE VIEW IF NOT EXISTS"
276
277
  };
277
278
  /**
279
+ * Typed read of a JSON leaf (`SqlDialect.jsonExtract`): `json_type()` guards
280
+ * the declared type, so a missing path, JSON `null` or another JSON type
281
+ * yields NULL (no coercion). Booleans come back as 1/0 — the view's boolean
282
+ * formatter converts them.
283
+ */
284
+ function sqliteJsonExtract(quotedCol, path, type) {
285
+ const p = jsonDollarPath(path);
286
+ const t = `json_type(${quotedCol}, ${p})`;
287
+ const v = `json_extract(${quotedCol}, ${p})`;
288
+ switch (type) {
289
+ case "string": return `CASE ${t} WHEN 'text' THEN ${v} END`;
290
+ case "number": return `CASE ${t} WHEN 'integer' THEN ${v} WHEN 'real' THEN ${v} END`;
291
+ case "boolean": return `CASE ${t} WHEN 'true' THEN 1 WHEN 'false' THEN 0 END`;
292
+ default: return type;
293
+ }
294
+ }
295
+ /**
278
296
  * Great-circle distance in meters from a JSON-stored `[lng, lat]` column to a
279
297
  * query point, via the haversine formula (mean earth radius 6 371 000 m).
280
298
  * NULL columns yield NULL — geo search excludes them, matching `$geoNear`.
@@ -670,6 +688,10 @@ var SqliteAdapter = class SqliteAdapter extends BaseDbAdapter {
670
688
  calendarBucketUnits() {
671
689
  return this._hasBucketFn ? ALL_BUCKET_UNITS : super.calendarBucketUnits();
672
690
  }
691
+ /** Every aggregate function, `countDistinct` included. */
692
+ aggregateFns() {
693
+ return ALL_AGGREGATE_FNS;
694
+ }
673
695
  /** Whether the SQLite connection has the sqlite-vec extension loaded. */
674
696
  _supportsVector;
675
697
  /** Whether SQLite math functions (radians/asin/...) are available — geo search. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-sqlite",
3
- "version": "0.1.134",
3
+ "version": "0.1.136",
4
4
  "description": "SQLite adapter for @atscript/db with swappable driver support.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -39,7 +39,7 @@
39
39
  "@atscript/core": "^0.1.92",
40
40
  "@atscript/typescript": "^0.1.92",
41
41
  "@types/better-sqlite3": "^7.6.13",
42
- "@uniqu/core": "^0.1.10",
42
+ "@uniqu/core": "^0.1.11",
43
43
  "better-sqlite3": "^12.6.2",
44
44
  "sqlite-vec": "^0.1.9",
45
45
  "unplugin-atscript": "^0.1.92"
@@ -47,10 +47,10 @@
47
47
  "peerDependencies": {
48
48
  "@atscript/core": "^0.1.92",
49
49
  "@atscript/typescript": "^0.1.92",
50
- "@uniqu/core": "^0.1.10",
50
+ "@uniqu/core": "^0.1.11",
51
51
  "better-sqlite3": ">=11.0.0",
52
- "@atscript/db": "^0.1.134",
53
- "@atscript/db-sql-tools": "^0.1.134"
52
+ "@atscript/db": "^0.1.136",
53
+ "@atscript/db-sql-tools": "^0.1.136"
54
54
  },
55
55
  "peerDependenciesMeta": {
56
56
  "better-sqlite3": {