@atscript/db-sql-tools 0.1.148 → 0.1.150
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 +14 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.mts +14 -2
- package/dist/index.mjs +15 -3
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -80,6 +80,14 @@ const EMPTY_OR = {
|
|
|
80
80
|
sql: "0=1",
|
|
81
81
|
params: []
|
|
82
82
|
};
|
|
83
|
+
/** ORs predicate parts (parenthesized when several); no parts matches nothing. */
|
|
84
|
+
function orFragment(parts, params) {
|
|
85
|
+
if (parts.length === 0) return EMPTY_OR;
|
|
86
|
+
return {
|
|
87
|
+
sql: parts.length === 1 ? parts[0] : `(${parts.join(" OR ")})`,
|
|
88
|
+
params
|
|
89
|
+
};
|
|
90
|
+
}
|
|
83
91
|
//#endregion
|
|
84
92
|
//#region src/arith.ts
|
|
85
93
|
/**
|
|
@@ -220,6 +228,7 @@ function createFilterVisitor(dialect, options) {
|
|
|
220
228
|
params: []
|
|
221
229
|
};
|
|
222
230
|
case "$regex": return dialect.regex(col, value);
|
|
231
|
+
case _atscript_db.INTEGER_REGEX_OP: return dialect.regex(dialect.integerText ? dialect.integerText(col) : `CAST(${col} AS TEXT)`, value);
|
|
223
232
|
default: throw new Error(`Unsupported filter operator: ${String(op)}`);
|
|
224
233
|
}
|
|
225
234
|
},
|
|
@@ -1114,7 +1123,10 @@ function fillReplacePayload(data, columns, versionColumn) {
|
|
|
1114
1123
|
* `<col> = <col> + 1` to the SET list. The bump is **mandatory** whenever
|
|
1115
1124
|
* `versionColumn` is set, regardless of whether `expectedVersion` is
|
|
1116
1125
|
* supplied. If the version column doesn't auto-increment on every write,
|
|
1117
|
-
* OCC silently degrades to no protection.
|
|
1126
|
+
* OCC silently degrades to no protection. A caller that must not bump (a
|
|
1127
|
+
* version-exempt patch, `TDbUpdateOptions.keepVersion`) passes
|
|
1128
|
+
* `versionColumn: undefined`, which also drops the CAS predicate — callers
|
|
1129
|
+
* never combine that with `expectedVersion`.
|
|
1118
1130
|
* - `expectedVersion` — when supplied, the builder appends
|
|
1119
1131
|
* `AND <col> = ?` to the WHERE clause and pushes the value. Requires
|
|
1120
1132
|
* `versionColumn` (CAS targets that column); supplying `expectedVersion`
|
|
@@ -1482,6 +1494,7 @@ exports.jsonDollarPath = jsonDollarPath;
|
|
|
1482
1494
|
exports.mapQueryErrors = mapQueryErrors;
|
|
1483
1495
|
exports.normalizeGeoPointValue = normalizeGeoPointValue;
|
|
1484
1496
|
exports.numericOutOfRangeError = numericOutOfRangeError;
|
|
1497
|
+
exports.orFragment = orFragment;
|
|
1485
1498
|
exports.orderKeySql = orderKeySql;
|
|
1486
1499
|
exports.parseRegexString = parseRegexString;
|
|
1487
1500
|
exports.queryNodeToSql = queryNodeToSql;
|
package/dist/index.d.cts
CHANGED
|
@@ -25,6 +25,13 @@ interface SqlDialect {
|
|
|
25
25
|
toParam(value: unknown): unknown;
|
|
26
26
|
/** Handle $regex filter */
|
|
27
27
|
regex(quotedCol: string, value: unknown): TSqlFragment;
|
|
28
|
+
/**
|
|
29
|
+
* The canonical decimal text of an integer column (`29461277`, `-12` — no
|
|
30
|
+
* `.0`, no exponent), as an SQL expression over the quoted column. Backs
|
|
31
|
+
* `$regex` on integer fields. Defaults to `CAST(<col> AS TEXT)`.
|
|
32
|
+
* @since 0.1.150
|
|
33
|
+
*/
|
|
34
|
+
integerText?(quotedExpr: string): string;
|
|
28
35
|
/**
|
|
29
36
|
* Handle `$geoWithin` filter — circle search on a `db.geoPoint` column.
|
|
30
37
|
* The circle is pre-validated by the core layer (`center` is a `[lng, lat]`
|
|
@@ -174,6 +181,8 @@ declare function orderKeySql(dialect: SqlDialect, expr: string, desc: boolean):
|
|
|
174
181
|
declare function quotedJsonPathSegments(path: readonly string[]): string[];
|
|
175
182
|
declare const EMPTY_AND: TSqlFragment;
|
|
176
183
|
declare const EMPTY_OR: TSqlFragment;
|
|
184
|
+
/** ORs predicate parts (parenthesized when several); no parts matches nothing. */
|
|
185
|
+
declare function orFragment(parts: string[], params: unknown[]): TSqlFragment;
|
|
177
186
|
//#endregion
|
|
178
187
|
//#region src/arith.d.ts
|
|
179
188
|
/** Why {@link renderArith} cannot render an expression. */
|
|
@@ -489,7 +498,10 @@ declare function fillReplacePayload(data: Record<string, unknown>, columns: read
|
|
|
489
498
|
* `<col> = <col> + 1` to the SET list. The bump is **mandatory** whenever
|
|
490
499
|
* `versionColumn` is set, regardless of whether `expectedVersion` is
|
|
491
500
|
* supplied. If the version column doesn't auto-increment on every write,
|
|
492
|
-
* OCC silently degrades to no protection.
|
|
501
|
+
* OCC silently degrades to no protection. A caller that must not bump (a
|
|
502
|
+
* version-exempt patch, `TDbUpdateOptions.keepVersion`) passes
|
|
503
|
+
* `versionColumn: undefined`, which also drops the CAS predicate — callers
|
|
504
|
+
* never combine that with `expectedVersion`.
|
|
493
505
|
* - `expectedVersion` — when supplied, the builder appends
|
|
494
506
|
* `AND <col> = ?` to the WHERE clause and pushes the value. Requires
|
|
495
507
|
* `versionColumn` (CAS targets that column); supplying `expectedVersion`
|
|
@@ -626,4 +638,4 @@ declare function parseRegexString(value: unknown): {
|
|
|
626
638
|
flags: string;
|
|
627
639
|
};
|
|
628
640
|
//#endregion
|
|
629
|
-
export { AGG_FN_SQL, EMPTY_AND, EMPTY_OR, GEO_DISTANCE_ALIAS, PARTITION_ROW_NUMBER_ALIAS, SEARCH_SOURCE_ALIAS, SQL_DEFAULT, type SqlDialect, type TArithFailure, type TFilterVisitorOptions, type TGeoCircle, type TGeoSearchControls, type TGeoWindow, type TReplaceColumn, type TSqlFragment, VECTOR_DISTANCE_ALIAS, arithOverflowError, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildInsert, buildInsertMany, buildPartitionedSelect, buildProjection, buildSelect, buildUpdate, buildVectorSearchCount, buildVectorSearchSelect, buildWhere, chunkInsertRows, createFilterVisitor, defaultValueForType, defaultValueToSqlLiteral, derivedColumnExpr, fillReplacePayload, finalizeParams, foreignKeySql, geoWindowFromControls, groupKeySql, insertManyColumns, jsonDollarPath, mapQueryErrors, normalizeGeoPointValue, numericOutOfRangeError, orderKeySql, parseRegexString, queryNodeToSql, queryOpToSql, quotedJsonPathSegments, refActionToSql, renameGeoDistance, renderArith, replaceColumnsFor, sqlStringLiteral, sqlTimeZoneLiteral, stripPartitionRowNumber, toSqlValue, vectorDistanceSource };
|
|
641
|
+
export { AGG_FN_SQL, EMPTY_AND, EMPTY_OR, GEO_DISTANCE_ALIAS, PARTITION_ROW_NUMBER_ALIAS, SEARCH_SOURCE_ALIAS, SQL_DEFAULT, type SqlDialect, type TArithFailure, type TFilterVisitorOptions, type TGeoCircle, type TGeoSearchControls, type TGeoWindow, type TReplaceColumn, type TSqlFragment, VECTOR_DISTANCE_ALIAS, arithOverflowError, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildInsert, buildInsertMany, buildPartitionedSelect, buildProjection, buildSelect, buildUpdate, buildVectorSearchCount, buildVectorSearchSelect, buildWhere, chunkInsertRows, createFilterVisitor, defaultValueForType, defaultValueToSqlLiteral, derivedColumnExpr, fillReplacePayload, finalizeParams, foreignKeySql, geoWindowFromControls, groupKeySql, insertManyColumns, jsonDollarPath, mapQueryErrors, normalizeGeoPointValue, numericOutOfRangeError, orFragment, orderKeySql, parseRegexString, queryNodeToSql, queryOpToSql, quotedJsonPathSegments, refActionToSql, renameGeoDistance, renderArith, replaceColumnsFor, sqlStringLiteral, sqlTimeZoneLiteral, stripPartitionRowNumber, toSqlValue, vectorDistanceSource };
|
package/dist/index.d.mts
CHANGED
|
@@ -25,6 +25,13 @@ interface SqlDialect {
|
|
|
25
25
|
toParam(value: unknown): unknown;
|
|
26
26
|
/** Handle $regex filter */
|
|
27
27
|
regex(quotedCol: string, value: unknown): TSqlFragment;
|
|
28
|
+
/**
|
|
29
|
+
* The canonical decimal text of an integer column (`29461277`, `-12` — no
|
|
30
|
+
* `.0`, no exponent), as an SQL expression over the quoted column. Backs
|
|
31
|
+
* `$regex` on integer fields. Defaults to `CAST(<col> AS TEXT)`.
|
|
32
|
+
* @since 0.1.150
|
|
33
|
+
*/
|
|
34
|
+
integerText?(quotedExpr: string): string;
|
|
28
35
|
/**
|
|
29
36
|
* Handle `$geoWithin` filter — circle search on a `db.geoPoint` column.
|
|
30
37
|
* The circle is pre-validated by the core layer (`center` is a `[lng, lat]`
|
|
@@ -174,6 +181,8 @@ declare function orderKeySql(dialect: SqlDialect, expr: string, desc: boolean):
|
|
|
174
181
|
declare function quotedJsonPathSegments(path: readonly string[]): string[];
|
|
175
182
|
declare const EMPTY_AND: TSqlFragment;
|
|
176
183
|
declare const EMPTY_OR: TSqlFragment;
|
|
184
|
+
/** ORs predicate parts (parenthesized when several); no parts matches nothing. */
|
|
185
|
+
declare function orFragment(parts: string[], params: unknown[]): TSqlFragment;
|
|
177
186
|
//#endregion
|
|
178
187
|
//#region src/arith.d.ts
|
|
179
188
|
/** Why {@link renderArith} cannot render an expression. */
|
|
@@ -489,7 +498,10 @@ declare function fillReplacePayload(data: Record<string, unknown>, columns: read
|
|
|
489
498
|
* `<col> = <col> + 1` to the SET list. The bump is **mandatory** whenever
|
|
490
499
|
* `versionColumn` is set, regardless of whether `expectedVersion` is
|
|
491
500
|
* supplied. If the version column doesn't auto-increment on every write,
|
|
492
|
-
* OCC silently degrades to no protection.
|
|
501
|
+
* OCC silently degrades to no protection. A caller that must not bump (a
|
|
502
|
+
* version-exempt patch, `TDbUpdateOptions.keepVersion`) passes
|
|
503
|
+
* `versionColumn: undefined`, which also drops the CAS predicate — callers
|
|
504
|
+
* never combine that with `expectedVersion`.
|
|
493
505
|
* - `expectedVersion` — when supplied, the builder appends
|
|
494
506
|
* `AND <col> = ?` to the WHERE clause and pushes the value. Requires
|
|
495
507
|
* `versionColumn` (CAS targets that column); supplying `expectedVersion`
|
|
@@ -626,4 +638,4 @@ declare function parseRegexString(value: unknown): {
|
|
|
626
638
|
flags: string;
|
|
627
639
|
};
|
|
628
640
|
//#endregion
|
|
629
|
-
export { AGG_FN_SQL, EMPTY_AND, EMPTY_OR, GEO_DISTANCE_ALIAS, PARTITION_ROW_NUMBER_ALIAS, SEARCH_SOURCE_ALIAS, SQL_DEFAULT, type SqlDialect, type TArithFailure, type TFilterVisitorOptions, type TGeoCircle, type TGeoSearchControls, type TGeoWindow, type TReplaceColumn, type TSqlFragment, VECTOR_DISTANCE_ALIAS, arithOverflowError, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildInsert, buildInsertMany, buildPartitionedSelect, buildProjection, buildSelect, buildUpdate, buildVectorSearchCount, buildVectorSearchSelect, buildWhere, chunkInsertRows, createFilterVisitor, defaultValueForType, defaultValueToSqlLiteral, derivedColumnExpr, fillReplacePayload, finalizeParams, foreignKeySql, geoWindowFromControls, groupKeySql, insertManyColumns, jsonDollarPath, mapQueryErrors, normalizeGeoPointValue, numericOutOfRangeError, orderKeySql, parseRegexString, queryNodeToSql, queryOpToSql, quotedJsonPathSegments, refActionToSql, renameGeoDistance, renderArith, replaceColumnsFor, sqlStringLiteral, sqlTimeZoneLiteral, stripPartitionRowNumber, toSqlValue, vectorDistanceSource };
|
|
641
|
+
export { AGG_FN_SQL, EMPTY_AND, EMPTY_OR, GEO_DISTANCE_ALIAS, PARTITION_ROW_NUMBER_ALIAS, SEARCH_SOURCE_ALIAS, SQL_DEFAULT, type SqlDialect, type TArithFailure, type TFilterVisitorOptions, type TGeoCircle, type TGeoSearchControls, type TGeoWindow, type TReplaceColumn, type TSqlFragment, VECTOR_DISTANCE_ALIAS, arithOverflowError, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildInsert, buildInsertMany, buildPartitionedSelect, buildProjection, buildSelect, buildUpdate, buildVectorSearchCount, buildVectorSearchSelect, buildWhere, chunkInsertRows, createFilterVisitor, defaultValueForType, defaultValueToSqlLiteral, derivedColumnExpr, fillReplacePayload, finalizeParams, foreignKeySql, geoWindowFromControls, groupKeySql, insertManyColumns, jsonDollarPath, mapQueryErrors, normalizeGeoPointValue, numericOutOfRangeError, orFragment, orderKeySql, parseRegexString, queryNodeToSql, queryOpToSql, quotedJsonPathSegments, refActionToSql, renameGeoDistance, renderArith, replaceColumnsFor, sqlStringLiteral, sqlTimeZoneLiteral, stripPartitionRowNumber, toSqlValue, vectorDistanceSource };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DbError, aggregateExpressionsNotSupported, containsRelationFilter, fkColumns, isFieldRef, isResolvedRelationFilter } from "@atscript/db";
|
|
1
|
+
import { DbError, INTEGER_REGEX_OP, aggregateExpressionsNotSupported, containsRelationFilter, fkColumns, isFieldRef, isResolvedRelationFilter } from "@atscript/db";
|
|
2
2
|
import { BUCKET_UNITS, TIME_ZONE_NAME_RE, WEEK_STARTS, walkFilter } from "@uniqu/core";
|
|
3
3
|
import { assertAggregateFn, resolveAlias } from "@atscript/db/agg";
|
|
4
4
|
//#region src/dialect.ts
|
|
@@ -79,6 +79,14 @@ const EMPTY_OR = {
|
|
|
79
79
|
sql: "0=1",
|
|
80
80
|
params: []
|
|
81
81
|
};
|
|
82
|
+
/** ORs predicate parts (parenthesized when several); no parts matches nothing. */
|
|
83
|
+
function orFragment(parts, params) {
|
|
84
|
+
if (parts.length === 0) return EMPTY_OR;
|
|
85
|
+
return {
|
|
86
|
+
sql: parts.length === 1 ? parts[0] : `(${parts.join(" OR ")})`,
|
|
87
|
+
params
|
|
88
|
+
};
|
|
89
|
+
}
|
|
82
90
|
//#endregion
|
|
83
91
|
//#region src/arith.ts
|
|
84
92
|
/**
|
|
@@ -219,6 +227,7 @@ function createFilterVisitor(dialect, options) {
|
|
|
219
227
|
params: []
|
|
220
228
|
};
|
|
221
229
|
case "$regex": return dialect.regex(col, value);
|
|
230
|
+
case INTEGER_REGEX_OP: return dialect.regex(dialect.integerText ? dialect.integerText(col) : `CAST(${col} AS TEXT)`, value);
|
|
222
231
|
default: throw new Error(`Unsupported filter operator: ${String(op)}`);
|
|
223
232
|
}
|
|
224
233
|
},
|
|
@@ -1113,7 +1122,10 @@ function fillReplacePayload(data, columns, versionColumn) {
|
|
|
1113
1122
|
* `<col> = <col> + 1` to the SET list. The bump is **mandatory** whenever
|
|
1114
1123
|
* `versionColumn` is set, regardless of whether `expectedVersion` is
|
|
1115
1124
|
* supplied. If the version column doesn't auto-increment on every write,
|
|
1116
|
-
* OCC silently degrades to no protection.
|
|
1125
|
+
* OCC silently degrades to no protection. A caller that must not bump (a
|
|
1126
|
+
* version-exempt patch, `TDbUpdateOptions.keepVersion`) passes
|
|
1127
|
+
* `versionColumn: undefined`, which also drops the CAS predicate — callers
|
|
1128
|
+
* never combine that with `expectedVersion`.
|
|
1117
1129
|
* - `expectedVersion` — when supplied, the builder appends
|
|
1118
1130
|
* `AND <col> = ?` to the WHERE clause and pushes the value. Requires
|
|
1119
1131
|
* `versionColumn` (CAS targets that column); supplying `expectedVersion`
|
|
@@ -1442,4 +1454,4 @@ function parseRegexString(value) {
|
|
|
1442
1454
|
};
|
|
1443
1455
|
}
|
|
1444
1456
|
//#endregion
|
|
1445
|
-
export { AGG_FN_SQL, EMPTY_AND, EMPTY_OR, GEO_DISTANCE_ALIAS, PARTITION_ROW_NUMBER_ALIAS, SEARCH_SOURCE_ALIAS, SQL_DEFAULT, VECTOR_DISTANCE_ALIAS, arithOverflowError, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildInsert, buildInsertMany, buildPartitionedSelect, buildProjection, buildSelect, buildUpdate, buildVectorSearchCount, buildVectorSearchSelect, buildWhere, chunkInsertRows, createFilterVisitor, defaultValueForType, defaultValueToSqlLiteral, derivedColumnExpr, fillReplacePayload, finalizeParams, foreignKeySql, geoWindowFromControls, groupKeySql, insertManyColumns, jsonDollarPath, mapQueryErrors, normalizeGeoPointValue, numericOutOfRangeError, orderKeySql, parseRegexString, queryNodeToSql, queryOpToSql, quotedJsonPathSegments, refActionToSql, renameGeoDistance, renderArith, replaceColumnsFor, sqlStringLiteral, sqlTimeZoneLiteral, stripPartitionRowNumber, toSqlValue, vectorDistanceSource };
|
|
1457
|
+
export { AGG_FN_SQL, EMPTY_AND, EMPTY_OR, GEO_DISTANCE_ALIAS, PARTITION_ROW_NUMBER_ALIAS, SEARCH_SOURCE_ALIAS, SQL_DEFAULT, VECTOR_DISTANCE_ALIAS, arithOverflowError, buildAggregateCount, buildAggregateSelect, buildCreateView, buildDelete, buildGeoSearchCount, buildGeoSearchSelect, buildInsert, buildInsertMany, buildPartitionedSelect, buildProjection, buildSelect, buildUpdate, buildVectorSearchCount, buildVectorSearchSelect, buildWhere, chunkInsertRows, createFilterVisitor, defaultValueForType, defaultValueToSqlLiteral, derivedColumnExpr, fillReplacePayload, finalizeParams, foreignKeySql, geoWindowFromControls, groupKeySql, insertManyColumns, jsonDollarPath, mapQueryErrors, normalizeGeoPointValue, numericOutOfRangeError, orFragment, orderKeySql, parseRegexString, queryNodeToSql, queryOpToSql, quotedJsonPathSegments, refActionToSql, renameGeoDistance, renderArith, replaceColumnsFor, sqlStringLiteral, sqlTimeZoneLiteral, stripPartitionRowNumber, toSqlValue, vectorDistanceSource };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-sql-tools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.150",
|
|
4
4
|
"description": "Shared SQL builder utilities for @atscript database adapters.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@uniqu/core": "^0.1.13",
|
|
41
|
-
"unplugin-atscript": "^0.1.
|
|
41
|
+
"unplugin-atscript": "^0.1.101"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@uniqu/core": "^0.1.13",
|
|
45
|
-
"@atscript/db": "^0.1.
|
|
45
|
+
"@atscript/db": "^0.1.150"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "vp pack",
|