@atscript/db-sqlite 0.1.154 → 0.1.155
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 +24 -0
- package/dist/index.d.cts +4 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +25 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -333,6 +333,9 @@ const sqliteDialect = {
|
|
|
333
333
|
},
|
|
334
334
|
calendarBucket: sqliteCalendarBucket,
|
|
335
335
|
jsonExtract: sqliteJsonExtract,
|
|
336
|
+
jsonExtractText: (quotedCol, path) => `json_extract(${quotedCol}, ${(0, _atscript_db_sql_tools.jsonDollarPath)(path)})`,
|
|
337
|
+
jsonExtractValue: (quotedCol, path) => `NULLIF(${quotedCol} -> ${(0, _atscript_db_sql_tools.jsonDollarPath)(path)}, 'null')`,
|
|
338
|
+
jsonFromText: (quotedCol) => `CASE WHEN json_valid(${quotedCol}) THEN ${quotedCol} ELSE json_quote(${quotedCol}) END`,
|
|
336
339
|
castDouble: (expr) => `CAST(${expr} AS REAL)`,
|
|
337
340
|
nullsPlacementSyntax: true,
|
|
338
341
|
createViewPrefix: "CREATE VIEW IF NOT EXISTS"
|
|
@@ -1323,6 +1326,20 @@ var SqliteAdapter = class SqliteAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1323
1326
|
this.driver.exec(ddl);
|
|
1324
1327
|
});
|
|
1325
1328
|
}
|
|
1329
|
+
async copyFromJsonColumn(source, targets) {
|
|
1330
|
+
return this._stmt(() => {
|
|
1331
|
+
const sql = (0, _atscript_db_sql_tools.buildJsonColumnCopy)(sqliteDialect, this.resolveTableName(), source, targets);
|
|
1332
|
+
this._log(sql);
|
|
1333
|
+
this.driver.exec(sql);
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
async jsonifyTextColumn(column) {
|
|
1337
|
+
return this._stmt(() => {
|
|
1338
|
+
const sql = (0, _atscript_db_sql_tools.buildJsonifyText)(sqliteDialect, this.resolveTableName(), column);
|
|
1339
|
+
this._log(sql);
|
|
1340
|
+
this.driver.exec(sql);
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1326
1343
|
async dropColumns(columns) {
|
|
1327
1344
|
return this._withExclusiveConnection(async () => {
|
|
1328
1345
|
await this.withTransaction(async () => {
|
|
@@ -1392,6 +1409,13 @@ var SqliteAdapter = class SqliteAdapter extends _atscript_db.BaseDbAdapter {
|
|
|
1392
1409
|
return this.driver.get(sql) != null;
|
|
1393
1410
|
});
|
|
1394
1411
|
}
|
|
1412
|
+
async countKeyViolations(columns, tableName) {
|
|
1413
|
+
return this._stmt(() => {
|
|
1414
|
+
const sql = (0, _atscript_db_sql_tools.buildKeyViolationCount)(sqliteDialect, `"${esc(tableName ?? this.resolveTableName())}"`, columns);
|
|
1415
|
+
this._log(sql);
|
|
1416
|
+
return this.driver.get(sql)?.violations ?? 0;
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1395
1419
|
/**
|
|
1396
1420
|
* Live foreign keys referencing `tableName`: `PRAGMA foreign_key_list` is
|
|
1397
1421
|
* outbound-only, so the tables in `sqlite_master` are scanned (a loop
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateOptions, 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, TDbUpdateOptions, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TJsonCopyTarget, 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";
|
|
@@ -427,6 +427,8 @@ declare class SqliteAdapter extends BaseDbAdapter {
|
|
|
427
427
|
syncColumns(diff: TColumnDiff): Promise<TSyncColumnResult>;
|
|
428
428
|
recreateTable(): Promise<void>;
|
|
429
429
|
dropTable(): Promise<void>;
|
|
430
|
+
copyFromJsonColumn(source: string, targets: readonly TJsonCopyTarget[]): Promise<void>;
|
|
431
|
+
jsonifyTextColumn(column: string): Promise<void>;
|
|
430
432
|
dropColumns(columns: string[]): Promise<void>;
|
|
431
433
|
dropIndexesForColumns(columns: string[]): Promise<void>;
|
|
432
434
|
dropTableByName(tableName: string): Promise<void>;
|
|
@@ -440,6 +442,7 @@ declare class SqliteAdapter extends BaseDbAdapter {
|
|
|
440
442
|
*/
|
|
441
443
|
dropTablesByName(tableNames: string[]): Promise<void>;
|
|
442
444
|
hasRows(tableName?: string): Promise<boolean>;
|
|
445
|
+
countKeyViolations(columns: readonly string[], tableName?: string): Promise<number>;
|
|
443
446
|
/**
|
|
444
447
|
* Live foreign keys referencing `tableName`: `PRAGMA foreign_key_list` is
|
|
445
448
|
* outbound-only, so the tables in `sqlite_master` are scanned (a loop
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDeleteResult, TDbFieldMeta, TDbInsertIgnoreSlot, TDbInsertManyResult, TDbInsertResult, TDbObjectKind, TDbUpdateOptions, 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, TDbUpdateOptions, TDbUpdateResult, TEnsureTableOptions, TExistingColumn, TFieldOps, TGenericLogger, TJsonCopyTarget, 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";
|
|
@@ -427,6 +427,8 @@ declare class SqliteAdapter extends BaseDbAdapter {
|
|
|
427
427
|
syncColumns(diff: TColumnDiff): Promise<TSyncColumnResult>;
|
|
428
428
|
recreateTable(): Promise<void>;
|
|
429
429
|
dropTable(): Promise<void>;
|
|
430
|
+
copyFromJsonColumn(source: string, targets: readonly TJsonCopyTarget[]): Promise<void>;
|
|
431
|
+
jsonifyTextColumn(column: string): Promise<void>;
|
|
430
432
|
dropColumns(columns: string[]): Promise<void>;
|
|
431
433
|
dropIndexesForColumns(columns: string[]): Promise<void>;
|
|
432
434
|
dropTableByName(tableName: string): Promise<void>;
|
|
@@ -440,6 +442,7 @@ declare class SqliteAdapter extends BaseDbAdapter {
|
|
|
440
442
|
*/
|
|
441
443
|
dropTablesByName(tableNames: string[]): Promise<void>;
|
|
442
444
|
hasRows(tableName?: string): Promise<boolean>;
|
|
445
|
+
countKeyViolations(columns: readonly string[], tableName?: string): Promise<number>;
|
|
443
446
|
/**
|
|
444
447
|
* Live foreign keys referencing `tableName`: `PRAGMA foreign_key_list` is
|
|
445
448
|
* outbound-only, so the tables in `sqlite_master` are scanned (a loop
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, defaultFulltextIndex, describeFulltext, fkColumns, searchIndexNotFoundMessage, searchTermInteger, splitFulltextFields, vectorIndexNotFoundMessage } from "@atscript/db";
|
|
3
3
|
import { resolveAggregateSearch } from "@atscript/db/agg";
|
|
4
|
-
import { EMPTY_AND, InsertSqlCache, SEARCH_SOURCE_ALIAS, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildPartitionedSelect, buildSelect, buildUpdate, buildVectorSearchCount, buildVectorSearchSelect, buildWhere as buildWhere$1, defaultValueForType, defaultValueToSqlLiteral, derivedColumnExpr, fillReplacePayload, fromSourceSql, geoWindowFromControls, jsonDollarPath, orFragment, orderByList, parseRegexString, refActionToSql, renameGeoDistance, replaceColumnsFor, sqlTimeZoneLiteral, stripPartitionRowNumber, toSqlValue, viewReadSource } from "@atscript/db-sql-tools";
|
|
4
|
+
import { EMPTY_AND, InsertSqlCache, SEARCH_SOURCE_ALIAS, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildJsonColumnCopy, buildJsonifyText, buildKeyViolationCount, buildPartitionedSelect, buildSelect, buildUpdate, buildVectorSearchCount, buildVectorSearchSelect, buildWhere as buildWhere$1, defaultValueForType, defaultValueToSqlLiteral, derivedColumnExpr, fillReplacePayload, fromSourceSql, geoWindowFromControls, jsonDollarPath, orFragment, orderByList, parseRegexString, refActionToSql, renameGeoDistance, replaceColumnsFor, sqlTimeZoneLiteral, stripPartitionRowNumber, toSqlValue, viewReadSource } 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
|
|
@@ -332,6 +332,9 @@ const sqliteDialect = {
|
|
|
332
332
|
},
|
|
333
333
|
calendarBucket: sqliteCalendarBucket,
|
|
334
334
|
jsonExtract: sqliteJsonExtract,
|
|
335
|
+
jsonExtractText: (quotedCol, path) => `json_extract(${quotedCol}, ${jsonDollarPath(path)})`,
|
|
336
|
+
jsonExtractValue: (quotedCol, path) => `NULLIF(${quotedCol} -> ${jsonDollarPath(path)}, 'null')`,
|
|
337
|
+
jsonFromText: (quotedCol) => `CASE WHEN json_valid(${quotedCol}) THEN ${quotedCol} ELSE json_quote(${quotedCol}) END`,
|
|
335
338
|
castDouble: (expr) => `CAST(${expr} AS REAL)`,
|
|
336
339
|
nullsPlacementSyntax: true,
|
|
337
340
|
createViewPrefix: "CREATE VIEW IF NOT EXISTS"
|
|
@@ -1322,6 +1325,20 @@ var SqliteAdapter = class SqliteAdapter extends BaseDbAdapter {
|
|
|
1322
1325
|
this.driver.exec(ddl);
|
|
1323
1326
|
});
|
|
1324
1327
|
}
|
|
1328
|
+
async copyFromJsonColumn(source, targets) {
|
|
1329
|
+
return this._stmt(() => {
|
|
1330
|
+
const sql = buildJsonColumnCopy(sqliteDialect, this.resolveTableName(), source, targets);
|
|
1331
|
+
this._log(sql);
|
|
1332
|
+
this.driver.exec(sql);
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
async jsonifyTextColumn(column) {
|
|
1336
|
+
return this._stmt(() => {
|
|
1337
|
+
const sql = buildJsonifyText(sqliteDialect, this.resolveTableName(), column);
|
|
1338
|
+
this._log(sql);
|
|
1339
|
+
this.driver.exec(sql);
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1325
1342
|
async dropColumns(columns) {
|
|
1326
1343
|
return this._withExclusiveConnection(async () => {
|
|
1327
1344
|
await this.withTransaction(async () => {
|
|
@@ -1391,6 +1408,13 @@ var SqliteAdapter = class SqliteAdapter extends BaseDbAdapter {
|
|
|
1391
1408
|
return this.driver.get(sql) != null;
|
|
1392
1409
|
});
|
|
1393
1410
|
}
|
|
1411
|
+
async countKeyViolations(columns, tableName) {
|
|
1412
|
+
return this._stmt(() => {
|
|
1413
|
+
const sql = buildKeyViolationCount(sqliteDialect, `"${esc(tableName ?? this.resolveTableName())}"`, columns);
|
|
1414
|
+
this._log(sql);
|
|
1415
|
+
return this.driver.get(sql)?.violations ?? 0;
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1394
1418
|
/**
|
|
1395
1419
|
* Live foreign keys referencing `tableName`: `PRAGMA foreign_key_list` is
|
|
1396
1420
|
* outbound-only, so the tables in `sqlite_master` are scanned (a loop
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-sqlite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.155",
|
|
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.
|
|
40
|
-
"@atscript/typescript": "^0.1.
|
|
39
|
+
"@atscript/core": "^0.1.105",
|
|
40
|
+
"@atscript/typescript": "^0.1.105",
|
|
41
41
|
"@types/better-sqlite3": "^7.6.13",
|
|
42
42
|
"@uniqu/core": "^0.1.15",
|
|
43
43
|
"better-sqlite3": "^12.6.2",
|
|
44
44
|
"sqlite-vec": "^0.1.9",
|
|
45
|
-
"unplugin-atscript": "^0.1.
|
|
45
|
+
"unplugin-atscript": "^0.1.105"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@atscript/core": "^0.1.
|
|
49
|
-
"@atscript/typescript": "^0.1.
|
|
48
|
+
"@atscript/core": "^0.1.105",
|
|
49
|
+
"@atscript/typescript": "^0.1.105",
|
|
50
50
|
"@uniqu/core": "^0.1.15",
|
|
51
51
|
"better-sqlite3": ">=11.0.0",
|
|
52
|
-
"@atscript/db": "^0.1.
|
|
53
|
-
"@atscript/db-sql-tools": "^0.1.
|
|
52
|
+
"@atscript/db": "^0.1.155",
|
|
53
|
+
"@atscript/db-sql-tools": "^0.1.155"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
56
56
|
"better-sqlite3": {
|