uql-orm 0.19.0 → 0.20.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/CHANGELOG.md +66 -0
- package/README.md +1 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +3 -3
- package/dist/bunSql/bunSqlCockroachDialect.d.ts +1 -1
- package/dist/bunSql/bunSqlCockroachDialect.js +1 -1
- package/dist/dialect/abstractSqlDialect.d.ts +130 -58
- package/dist/dialect/abstractSqlDialect.d.ts.map +1 -1
- package/dist/dialect/abstractSqlDialect.js +226 -178
- package/dist/dialect/abstractSqlDialect.js.map +1 -1
- package/dist/dialect/jsonArrayElemMatchUtils.d.ts +5 -6
- package/dist/dialect/jsonArrayElemMatchUtils.d.ts.map +1 -1
- package/dist/dialect/jsonArrayElemMatchUtils.js +9 -19
- package/dist/dialect/jsonArrayElemMatchUtils.js.map +1 -1
- package/dist/dialect/jsonSql.d.ts +44 -0
- package/dist/dialect/jsonSql.d.ts.map +1 -0
- package/dist/dialect/jsonSql.js +57 -0
- package/dist/dialect/jsonSql.js.map +1 -0
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +42 -2
- package/dist/dialect/mysqlLikeSqlDialect.d.ts.map +1 -1
- package/dist/dialect/mysqlLikeSqlDialect.js +73 -22
- package/dist/dialect/mysqlLikeSqlDialect.js.map +1 -1
- package/dist/dialect/pgLikeSqlDialect.d.ts +28 -10
- package/dist/dialect/pgLikeSqlDialect.d.ts.map +1 -1
- package/dist/dialect/pgLikeSqlDialect.js +56 -49
- package/dist/dialect/pgLikeSqlDialect.js.map +1 -1
- package/dist/dialect/queryContext.d.ts +13 -1
- package/dist/dialect/queryContext.d.ts.map +1 -1
- package/dist/dialect/queryContext.js +17 -2
- package/dist/dialect/queryContext.js.map +1 -1
- package/dist/dialect/vectorSqlDialect.d.ts +54 -0
- package/dist/dialect/vectorSqlDialect.d.ts.map +1 -0
- package/dist/dialect/vectorSqlDialect.js +70 -0
- package/dist/dialect/vectorSqlDialect.js.map +1 -0
- package/dist/entity/decorator/index-decorator.d.ts +6 -13
- package/dist/entity/decorator/index-decorator.d.ts.map +1 -1
- package/dist/entity/decorator/index-decorator.js.map +1 -1
- package/dist/http/handler.d.ts +5 -1
- package/dist/http/handler.d.ts.map +1 -1
- package/dist/http/handler.js.map +1 -1
- package/dist/maria/mariaDialect.d.ts +15 -4
- package/dist/maria/mariaDialect.d.ts.map +1 -1
- package/dist/maria/mariaDialect.js +25 -13
- package/dist/maria/mariaDialect.js.map +1 -1
- package/dist/migrate/generator/mongoSchemaGenerator.d.ts +1 -1
- package/dist/migrate/generator/mongoSchemaGenerator.d.ts.map +1 -1
- package/dist/mongo/mongoDialect.d.ts +27 -6
- package/dist/mongo/mongoDialect.d.ts.map +1 -1
- package/dist/mongo/mongoDialect.js +107 -14
- package/dist/mongo/mongoDialect.js.map +1 -1
- package/dist/mongo/mongodbQuerier.d.ts.map +1 -1
- package/dist/mongo/mongodbQuerier.js +5 -4
- package/dist/mongo/mongodbQuerier.js.map +1 -1
- package/dist/mysql/mysqlDialect.d.ts +0 -1
- package/dist/mysql/mysqlDialect.d.ts.map +1 -1
- package/dist/mysql/mysqlDialect.js +0 -1
- package/dist/mysql/mysqlDialect.js.map +1 -1
- package/dist/postgres/postgresWireDriverCapabilities.d.ts +1 -1
- package/dist/postgres/postgresWireDriverCapabilities.js +1 -1
- package/dist/schema/schemaAST.d.ts.map +1 -1
- package/dist/schema/schemaAST.js +7 -19
- package/dist/schema/schemaAST.js.map +1 -1
- package/dist/schema/types.d.ts +1 -1
- package/dist/sqlite/sqliteDialect.d.ts +28 -8
- package/dist/sqlite/sqliteDialect.d.ts.map +1 -1
- package/dist/sqlite/sqliteDialect.js +65 -80
- package/dist/sqlite/sqliteDialect.js.map +1 -1
- package/dist/type/dialect.d.ts +199 -0
- package/dist/type/dialect.d.ts.map +1 -0
- package/dist/type/dialect.js +2 -0
- package/dist/type/dialect.js.map +1 -0
- package/dist/type/entity.d.ts +64 -43
- package/dist/type/entity.d.ts.map +1 -1
- package/dist/type/entity.js.map +1 -1
- package/dist/type/index.d.ts +5 -0
- package/dist/type/index.d.ts.map +1 -1
- package/dist/type/index.js +5 -0
- package/dist/type/index.js.map +1 -1
- package/dist/type/querier.d.ts +3 -5
- package/dist/type/querier.d.ts.map +1 -1
- package/dist/type/querier.js.map +1 -1
- package/dist/type/query.d.ts +5 -711
- package/dist/type/query.d.ts.map +1 -1
- package/dist/type/query.js +1 -51
- package/dist/type/query.js.map +1 -1
- package/dist/type/queryAggregate.d.ts +191 -0
- package/dist/type/queryAggregate.d.ts.map +1 -0
- package/dist/type/queryAggregate.js +39 -0
- package/dist/type/queryAggregate.js.map +1 -0
- package/dist/type/queryRaw.d.ts +35 -0
- package/dist/type/queryRaw.d.ts.map +1 -0
- package/dist/type/queryRaw.js +11 -0
- package/dist/type/queryRaw.js.map +1 -0
- package/dist/type/queryWhere.d.ts +271 -0
- package/dist/type/queryWhere.d.ts.map +1 -0
- package/dist/type/queryWhere.js +2 -0
- package/dist/type/queryWhere.js.map +1 -0
- package/dist/type/universalQuerier.d.ts +2 -1
- package/dist/type/universalQuerier.d.ts.map +1 -1
- package/dist/type/utility.d.ts +8 -1
- package/dist/type/utility.d.ts.map +1 -1
- package/dist/type/vector.d.ts +55 -0
- package/dist/type/vector.d.ts.map +1 -0
- package/dist/type/vector.js +2 -0
- package/dist/type/vector.js.map +1 -0
- package/dist/util/ansiSqlLiteral.d.ts +2 -0
- package/dist/util/ansiSqlLiteral.d.ts.map +1 -1
- package/dist/util/ansiSqlLiteral.js +5 -1
- package/dist/util/ansiSqlLiteral.js.map +1 -1
- package/dist/util/dialect.util.d.ts +5 -5
- package/dist/util/dialect.util.d.ts.map +1 -1
- package/dist/util/dialect.util.js +15 -10
- package/dist/util/dialect.util.js.map +1 -1
- package/dist/util/object.util.d.ts +12 -1
- package/dist/util/object.util.d.ts.map +1 -1
- package/dist/util/object.util.js +18 -0
- package/dist/util/object.util.js.map +1 -1
- package/dist/util/relationQuery.util.js +1 -1
- package/dist/util/relationQuery.util.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import SqlString from 'sqlstring';
|
|
2
|
-
import {
|
|
2
|
+
import { escapeSingleQuotes } from '../util/ansiSqlLiteral.js';
|
|
3
3
|
import { AbstractSqlDialect } from './abstractSqlDialect.js';
|
|
4
|
-
import {
|
|
4
|
+
import { JSON_PULL_ALIAS, jsonAssignCall, jsonPath, jsonRemoveCall, jsonSetTarget } from './jsonSql.js';
|
|
5
5
|
/**
|
|
6
6
|
* Shared JSON-array / JSON-object operator implementation between MySQL and MariaDB.
|
|
7
7
|
*
|
|
@@ -9,6 +9,8 @@ import { buildElemMatchConditions } from './jsonArrayElemMatchUtils.js';
|
|
|
9
9
|
* - `$size` (JSON_LENGTH)
|
|
10
10
|
* - `$all` (JSON_CONTAINS)
|
|
11
11
|
* - `$elemMatch` (JSON_TABLE, or fast JSON_CONTAINS for the simple case)
|
|
12
|
+
* - the update operators `$set` (JSON_SET), `$unset` (JSON_REMOVE), `$push` (JSON_MERGE_PRESERVE)
|
|
13
|
+
* and `$pull` (JSON_REPLACE over JSON_TABLE)
|
|
12
14
|
*/
|
|
13
15
|
export class MysqlLikeSqlDialect extends AbstractSqlDialect {
|
|
14
16
|
/** Default {@link DialectFeatures} for MySQL-compatible SQL dialects. */
|
|
@@ -27,6 +29,7 @@ export class MysqlLikeSqlDialect extends AbstractSqlDialect {
|
|
|
27
29
|
supportsTimestamptz: false,
|
|
28
30
|
defaultStringAsText: false,
|
|
29
31
|
};
|
|
32
|
+
serialPrimaryKey = 'BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY';
|
|
30
33
|
escapeIdChar = '`';
|
|
31
34
|
tableOptions = 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4';
|
|
32
35
|
beginTransactionCommand = 'START TRANSACTION';
|
|
@@ -55,30 +58,78 @@ export class MysqlLikeSqlDialect extends AbstractSqlDialect {
|
|
|
55
58
|
// MySQL/MariaDB null-safe inequality: true when values differ or one side is NULL.
|
|
56
59
|
return `NOT (${field} <=> ${ph})`;
|
|
57
60
|
}
|
|
61
|
+
/** How a surviving element is fed back into the array a `$pull` rebuilds. */
|
|
62
|
+
jsonPullElem(alias) {
|
|
63
|
+
return `${alias}.v`;
|
|
64
|
+
}
|
|
65
|
+
/** Condition keeping the elements a `$pull` does *not* remove, given the bound pulled value. */
|
|
66
|
+
jsonPullKeep(alias, operand) {
|
|
67
|
+
return `${alias}.v <> ${operand}`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `JSON_REPLACE` leaves an absent key (and a NULL column) untouched, which is what makes `$pull`
|
|
71
|
+
* a no-op there. The subquery reads the column, so its value binds exactly once.
|
|
72
|
+
*/
|
|
73
|
+
jsonPullKey(ctx, expr, escapedCol, key, value) {
|
|
74
|
+
const elements = `JSON_TABLE(${escapedCol}, ${jsonPath(key, '[*]')} COLUMNS (v JSON PATH '$')) ${JSON_PULL_ALIAS}`;
|
|
75
|
+
const kept = `SELECT COALESCE(JSON_ARRAYAGG(${this.jsonPullElem(JSON_PULL_ALIAS)}), JSON_ARRAY()) FROM ${elements} WHERE ${this.jsonPullKeep(JSON_PULL_ALIAS, this.jsonScalarParam(ctx, value))}`;
|
|
76
|
+
return `JSON_REPLACE(${expr}, ${jsonPath(key)}, (${kept}))`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Omitting the `COALESCE` on a NOT NULL column keeps MySQL's partial in-place JSON update
|
|
80
|
+
* applicable: it requires the target column as the direct `JSON_SET` input.
|
|
81
|
+
*/
|
|
82
|
+
jsonSet(ctx, expr, set, field) {
|
|
83
|
+
return jsonAssignCall((value) => this.jsonScalarParam(ctx, value), 'JSON_SET', jsonSetTarget(expr, field, `'{}'`), set);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `JSON_MERGE_PRESERVE` concatenates arrays and creates absent keys, so every pushed key is
|
|
87
|
+
* handled in one call that references `expr` once - unlike `JSON_ARRAY_APPEND`, which needs a
|
|
88
|
+
* second reference for the array source and returns NULL on MariaDB for an absent key.
|
|
89
|
+
*/
|
|
90
|
+
jsonPush(ctx, expr, push) {
|
|
91
|
+
const entries = Object.entries(push).map(([key, value]) => `'${escapeSingleQuotes(key)}', JSON_ARRAY(${this.jsonScalarParam(ctx, value)})`);
|
|
92
|
+
return `JSON_MERGE_PRESERVE(${expr}, JSON_OBJECT(${entries.join(', ')}))`;
|
|
93
|
+
}
|
|
94
|
+
jsonUnset(_ctx, expr, unset) {
|
|
95
|
+
return jsonRemoveCall('JSON_REMOVE', expr, unset);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* MySQL's `->`/`->>` take a full JSON path (`'$.a.b'`, never a bare key) and only apply to a
|
|
99
|
+
* column reference, so the whole dotted path goes into a single accessor instead of the base's
|
|
100
|
+
* chained `col->'a'->>'b'`, which the server rejects with "Invalid JSON path expression".
|
|
101
|
+
*/
|
|
102
|
+
getJsonPathScalarExpr(escapedColumn, jsonPathStr) {
|
|
103
|
+
return `(${escapedColumn}->>${jsonPath(jsonPathStr)})`;
|
|
104
|
+
}
|
|
105
|
+
getJsonPathJsonbExpr(escapedColumn, jsonPathStr) {
|
|
106
|
+
return `${escapedColumn}->${jsonPath(jsonPathStr)}`;
|
|
107
|
+
}
|
|
58
108
|
jsonAll(ctx, jsonField, value) {
|
|
59
109
|
return `JSON_CONTAINS(${jsonField}, ${this.addValue(ctx.values, JSON.stringify(value))})`;
|
|
60
110
|
}
|
|
61
111
|
jsonSize(ctx, jsonField, value) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
112
|
+
return this.buildFragment(ctx, (fragmentCtx) => this.buildSizeComparison(fragmentCtx, () => fragmentCtx.append(`JSON_LENGTH(${jsonField})`), value));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* `JSON_TABLE` needs its columns declared upfront, so the object form maps `fields` to columns.
|
|
116
|
+
* The scalar form's column is `JSON`, not `TEXT`, when `asJson` - `TEXT PATH '$'` silently reads
|
|
117
|
+
* a compound (array/object) element as `NULL`, since MySQL doesn't coerce those to text; only a
|
|
118
|
+
* true scalar element survives that coercion. A nested `$elemMatch` (each element being an array
|
|
119
|
+
* that itself gets exploded) always requests `asJson`, so this is what makes that case reach the
|
|
120
|
+
* inner elements at all rather than finding nothing.
|
|
121
|
+
*/
|
|
122
|
+
jsonElemFrom(jsonField, fields, alias, asJson = false) {
|
|
123
|
+
const columns = fields.length
|
|
124
|
+
? fields.map((field) => `${this.escapeId(field, true)} TEXT PATH ${jsonPath(field)}`).join(', ')
|
|
125
|
+
: `elem_text ${asJson ? 'JSON' : 'TEXT'} PATH '$'`;
|
|
126
|
+
return `JSON_TABLE(${jsonField}, '$[*]' COLUMNS (${columns})) AS ${alias}`;
|
|
127
|
+
}
|
|
128
|
+
jsonElemRef(alias, field, asJson = false) {
|
|
129
|
+
const ref = field === undefined ? `${alias}.elem_text` : `${alias}.${this.escapeId(field, true)}`;
|
|
130
|
+
// `JSON_TABLE` columns stay `TEXT` so the string operators keep working; the JSON form reads
|
|
131
|
+
// that text back as JSON.
|
|
132
|
+
return asJson ? this.jsonCast(ref) : ref;
|
|
82
133
|
}
|
|
83
134
|
}
|
|
84
135
|
//# sourceMappingURL=mysqlLikeSqlDialect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysqlLikeSqlDialect.js","sourceRoot":"","sources":["../../src/dialect/mysqlLikeSqlDialect.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAA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ryComparisonOptions, type QueryConflictPaths, type QueryContext, type QueryOptions, type QuerySizeComparisonOps, type QueryVectorSearch, type Type, type VectorDistance } from '../type/index.js';
|
|
2
2
|
import { AbstractSqlDialect } from './abstractSqlDialect.js';
|
|
3
3
|
/**
|
|
4
4
|
* Shared AST/quoting/JSONB/full-text-search/vector-search implementation between Postgres and
|
|
@@ -27,30 +27,48 @@ export declare abstract class PgLikeSqlDialect extends AbstractSqlDialect {
|
|
|
27
27
|
insert<E>(ctx: QueryContext, entity: Type<E>, payload: E | E[], opts?: QueryOptions): void;
|
|
28
28
|
upsert<E>(ctx: QueryContext, entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E | E[]): void;
|
|
29
29
|
/**
|
|
30
|
-
* Shared `INSERT ... ON CONFLICT (...) DO UPDATE/NOTHING RETURNING ...` builder,
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
30
|
+
* Shared `INSERT ... ON CONFLICT (...) DO UPDATE/NOTHING RETURNING ...` builder, assembling
|
|
31
|
+
* everything upfront rather than handing back fragments, for the `$N`-placeholder Postgres-wire
|
|
32
|
+
* dialects. `extraReturning` lets {@link PostgresDialect} append `(xmax = 0) AS "_created"` to
|
|
33
|
+
* detect insert-vs-update; CockroachDB has no `xmax`/`ctid` system columns, so it uses the default
|
|
34
|
+
* (empty) and `created` stays `undefined` in the result.
|
|
35
35
|
*/
|
|
36
36
|
protected buildUpsertOnConflict<E>(ctx: QueryContext, entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E | E[], extraReturning?: string): void;
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Full-text search: `to_tsvector(...) @@ websearch_to_tsquery(...)`. `websearch_to_tsquery` takes
|
|
39
|
+
* free-form user input (quoted phrases, `or`, `-negation`) and never raises a syntax error, unlike
|
|
40
|
+
* `to_tsquery`, which rejects anything unparseable - including a plain two-word search.
|
|
41
|
+
*/
|
|
38
42
|
compare<E>(ctx: QueryContext, entity: Type<E>, key: string, val: unknown, opts?: QueryComparisonOptions): void;
|
|
39
43
|
protected jsonAll(ctx: QueryContext, jsonField: string, value: unknown): string;
|
|
40
44
|
protected jsonSize(ctx: QueryContext, jsonField: string, value: number | QuerySizeComparisonOps): string;
|
|
41
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Object elements stay `jsonb` so each field can pick `->` or `->>`. Scalar elements are exploded
|
|
47
|
+
* as text unless they are compared as JSON, where `_text` would yield `text = jsonb`.
|
|
48
|
+
*/
|
|
49
|
+
protected jsonElemFrom(jsonField: string, fields: readonly string[], alias: string, asJson?: boolean): string;
|
|
50
|
+
protected jsonElemRef(alias: string, field?: string, asJson?: boolean): string;
|
|
42
51
|
protected get regexpOp(): string;
|
|
43
52
|
protected ilikeExpr(f: string, ph: string): string;
|
|
44
53
|
protected get neOp(): string;
|
|
45
54
|
protected formatIn(ctx: QueryContext, values: unknown[], negate: boolean): string;
|
|
46
55
|
protected numericCast(expr: string): string;
|
|
47
56
|
protected formatPersistableValue<E>(ctx: QueryContext, field: FieldOptions, value: unknown): void;
|
|
48
|
-
|
|
57
|
+
/**
|
|
58
|
+
* `create_if_missing => false` keeps an absent key (and a NULL column) untouched; `WITH
|
|
59
|
+
* ORDINALITY` keeps the surviving elements in their original order.
|
|
60
|
+
*/
|
|
61
|
+
protected jsonPullKey(ctx: QueryContext, expr: string, escapedCol: string, key: string, value: unknown): string;
|
|
62
|
+
protected jsonSet(ctx: QueryContext, expr: string, set: Record<string, unknown>, field?: FieldOptions): string;
|
|
63
|
+
/** The only fragment that references `expr` twice - safe here because placeholders are numbered. */
|
|
64
|
+
protected jsonPush(ctx: QueryContext, expr: string, push: Record<string, unknown>): string;
|
|
65
|
+
protected jsonUnset(ctx: QueryContext, expr: string, unset: readonly string[]): string;
|
|
66
|
+
/** Postgres binds JSON with a numbered placeholder and an explicit cast, per driver capability. */
|
|
67
|
+
protected jsonScalarParam(ctx: QueryContext, value: unknown): string;
|
|
49
68
|
/**
|
|
50
69
|
* Helper to add a JSON value to context with appropriate stringification and cast.
|
|
51
70
|
*/
|
|
52
71
|
private jsonVal;
|
|
53
|
-
escape(value: unknown): string;
|
|
54
72
|
/**
|
|
55
73
|
* pgvector distance operators. Not every dialect supports every metric - see
|
|
56
74
|
* {@link CockroachDialect.vectorOpsClass} for which ones each dialect actually has; the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgLikeSqlDialect.d.ts","sourceRoot":"","sources":["../../src/dialect/pgLikeSqlDialect.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,EAEjB,KAAK,
|
|
1
|
+
{"version":3,"file":"pgLikeSqlDialect.d.ts","sourceRoot":"","sources":["../../src/dialect/pgLikeSqlDialect.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,EAEjB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EAEjB,KAAK,sBAAsB,EAE3B,KAAK,iBAAiB,EACtB,KAAK,IAAI,EACT,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D;;;;;;;;GAQG;AACH,8BAAsB,gBAAiB,SAAQ,kBAAkB;IAC/D,kEAAkE;IAClE,mBAA4B,eAAe,EAAE,eAAe,CAc1D;IAEF,SAAkB,YAAY,QAAO;IAKrC,SAAkB,gBAAgB,EAAE,MAAM,CAAyD;IACnG,SAAkB,YAAY,MAAM;IACpC,SAAkB,uBAAuB,WAAW;IACpD,SAAkB,wBAAwB,YAAY;IACtD,SAAkB,0BAA0B,cAAc;IAC1D,SAAkB,mBAAmB,sBAAsB;IAC3D,SAAkB,cAAc,eAAe;IAC/C,SAAkB,aAAa,EAAE,MAAM,CAAS;IAEhD,SAAkB,cAAc,E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,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAE9F;IAED,mGAAmG;IACnG,UAAmB,eAAe,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAE5E;IAED;;OAEG;IACH,OAAO,CAAC,OAAO;IASf;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAMhC;IAEF,gFAAgF;IAChF,UAAmB,gBAAgB,CAAC,CAAC,EACnC,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EACnB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,iBAAiB,GACxB,IAAI,CASN;CACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getMeta } from '../entity/index.js';
|
|
2
2
|
import { QueryRaw, } from '../type/index.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { escapeSingleQuotes } from '../util/ansiSqlLiteral.js';
|
|
4
|
+
import { isJsonType } from '../util/index.js';
|
|
5
5
|
import { AbstractSqlDialect } from './abstractSqlDialect.js';
|
|
6
|
-
import {
|
|
6
|
+
import { JSON_PULL_ALIAS, jsonSetTarget } from './jsonSql.js';
|
|
7
7
|
/**
|
|
8
8
|
* Shared AST/quoting/JSONB/full-text-search/vector-search implementation between Postgres and
|
|
9
9
|
* CockroachDB (wire- and SQL-compatible for everything below, including `to_tsvector`/`to_tsquery`
|
|
@@ -67,11 +67,11 @@ export class PgLikeSqlDialect extends AbstractSqlDialect {
|
|
|
67
67
|
this.buildUpsertOnConflict(ctx, entity, conflictPaths, payload);
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* Shared `INSERT ... ON CONFLICT (...) DO UPDATE/NOTHING RETURNING ...` builder,
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
70
|
+
* Shared `INSERT ... ON CONFLICT (...) DO UPDATE/NOTHING RETURNING ...` builder, assembling
|
|
71
|
+
* everything upfront rather than handing back fragments, for the `$N`-placeholder Postgres-wire
|
|
72
|
+
* dialects. `extraReturning` lets {@link PostgresDialect} append `(xmax = 0) AS "_created"` to
|
|
73
|
+
* detect insert-vs-update; CockroachDB has no `xmax`/`ctid` system columns, so it uses the default
|
|
74
|
+
* (empty) and `created` stays `undefined` in the result.
|
|
75
75
|
*/
|
|
76
76
|
buildUpsertOnConflict(ctx, entity, conflictPaths, payload, extraReturning = '') {
|
|
77
77
|
const meta = getMeta(entity);
|
|
@@ -81,7 +81,11 @@ export class PgLikeSqlDialect extends AbstractSqlDialect {
|
|
|
81
81
|
super.insert(ctx, entity, payload);
|
|
82
82
|
ctx.append(` ON CONFLICT (${keysStr}) ${onConflict} ${this.returningId(entity)}${extraReturning}`);
|
|
83
83
|
}
|
|
84
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Full-text search: `to_tsvector(...) @@ websearch_to_tsquery(...)`. `websearch_to_tsquery` takes
|
|
86
|
+
* free-form user input (quoted phrases, `or`, `-negation`) and never raises a syntax error, unlike
|
|
87
|
+
* `to_tsquery`, which rejects anything unparseable - including a plain two-word search.
|
|
88
|
+
*/
|
|
85
89
|
compare(ctx, entity, key, val, opts = {}) {
|
|
86
90
|
if (key === '$text') {
|
|
87
91
|
const meta = getMeta(entity);
|
|
@@ -93,7 +97,9 @@ export class PgLikeSqlDialect extends AbstractSqlDialect {
|
|
|
93
97
|
return this.escapeId(columnName);
|
|
94
98
|
})
|
|
95
99
|
.join(` || ' ' || `);
|
|
96
|
-
|
|
100
|
+
// The config is bound once and its numbered placeholder reused by both calls.
|
|
101
|
+
const config = search.$config ? `${this.addValue(ctx.values, search.$config)}::regconfig, ` : '';
|
|
102
|
+
ctx.append(`to_tsvector(${config}${fields}) @@ websearch_to_tsquery(${config}`);
|
|
97
103
|
ctx.addValue(search.$value);
|
|
98
104
|
ctx.append(')');
|
|
99
105
|
return;
|
|
@@ -104,24 +110,21 @@ export class PgLikeSqlDialect extends AbstractSqlDialect {
|
|
|
104
110
|
return `${jsonField} @> ${this.jsonVal(ctx, value)}`;
|
|
105
111
|
}
|
|
106
112
|
jsonSize(ctx, jsonField, value) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (!hasOperators) {
|
|
121
|
-
return `${jsonField} @> ${this.jsonVal(ctx, [match])}`;
|
|
113
|
+
return this.buildFragment(ctx, (fragmentCtx) => this.buildSizeComparison(fragmentCtx, () => fragmentCtx.append(`jsonb_array_length(${jsonField})`), value));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Object elements stay `jsonb` so each field can pick `->` or `->>`. Scalar elements are exploded
|
|
117
|
+
* as text unless they are compared as JSON, where `_text` would yield `text = jsonb`.
|
|
118
|
+
*/
|
|
119
|
+
jsonElemFrom(jsonField, fields, alias, asJson = false) {
|
|
120
|
+
const fn = fields.length || asJson ? 'jsonb_array_elements' : 'jsonb_array_elements_text';
|
|
121
|
+
return `${fn}(${jsonField}) AS ${alias}`;
|
|
122
|
+
}
|
|
123
|
+
jsonElemRef(alias, field, asJson = false) {
|
|
124
|
+
if (field === undefined) {
|
|
125
|
+
return alias;
|
|
122
126
|
}
|
|
123
|
-
|
|
124
|
-
return `EXISTS (SELECT 1 FROM jsonb_array_elements(${jsonField}) AS elem WHERE ${conditions.join(' AND ')})`;
|
|
127
|
+
return asJson ? `${alias}->'${escapeSingleQuotes(field)}'` : `${alias}->>'${escapeSingleQuotes(field)}'`;
|
|
125
128
|
}
|
|
126
129
|
get regexpOp() {
|
|
127
130
|
return '~';
|
|
@@ -157,25 +160,32 @@ export class PgLikeSqlDialect extends AbstractSqlDialect {
|
|
|
157
160
|
}
|
|
158
161
|
super.formatPersistableValue(ctx, field, value);
|
|
159
162
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
163
|
+
/**
|
|
164
|
+
* `create_if_missing => false` keeps an absent key (and a NULL column) untouched; `WITH
|
|
165
|
+
* ORDINALITY` keeps the surviving elements in their original order.
|
|
166
|
+
*/
|
|
167
|
+
jsonPullKey(ctx, expr, escapedCol, key, value) {
|
|
168
|
+
const escapedKey = escapeSingleQuotes(key);
|
|
169
|
+
const kept = `SELECT jsonb_agg(${JSON_PULL_ALIAS}.val ORDER BY ${JSON_PULL_ALIAS}.ord) FROM jsonb_array_elements(${escapedCol}->'${escapedKey}') WITH ORDINALITY AS ${JSON_PULL_ALIAS}(val, ord) WHERE ${JSON_PULL_ALIAS}.val <> ${this.jsonVal(ctx, value)}`;
|
|
170
|
+
return `jsonb_set(${expr}, '{${escapedKey}}', COALESCE((${kept}), '[]'::jsonb), false)`;
|
|
171
|
+
}
|
|
172
|
+
jsonSet(ctx, expr, set, field) {
|
|
173
|
+
return `${jsonSetTarget(expr, field, `'{}'::jsonb`)} || ${this.jsonVal(ctx, set)}`;
|
|
174
|
+
}
|
|
175
|
+
/** The only fragment that references `expr` twice - safe here because placeholders are numbered. */
|
|
176
|
+
jsonPush(ctx, expr, push) {
|
|
177
|
+
return Object.entries(push).reduce((acc, [key, value]) => {
|
|
178
|
+
const escapedKey = escapeSingleQuotes(key);
|
|
179
|
+
const ph = this.jsonVal(ctx, value);
|
|
180
|
+
return `jsonb_set(${acc}, '{${escapedKey}}', COALESCE((${acc})->'${escapedKey}', '[]'::jsonb) || jsonb_build_array(${ph}))`;
|
|
181
|
+
}, expr);
|
|
182
|
+
}
|
|
183
|
+
jsonUnset(ctx, expr, unset) {
|
|
184
|
+
return `(${expr}) - ${this.addValue(ctx.values, [...unset])}::text[]`;
|
|
185
|
+
}
|
|
186
|
+
/** Postgres binds JSON with a numbered placeholder and an explicit cast, per driver capability. */
|
|
187
|
+
jsonScalarParam(ctx, value) {
|
|
188
|
+
return this.jsonVal(ctx, value);
|
|
179
189
|
}
|
|
180
190
|
/**
|
|
181
191
|
* Helper to add a JSON value to context with appropriate stringification and cast.
|
|
@@ -189,9 +199,6 @@ export class PgLikeSqlDialect extends AbstractSqlDialect {
|
|
|
189
199
|
const ph = this.addValue(ctx.values, json);
|
|
190
200
|
return this.features.explicitJsonCast ? `(${ph}::text)::${type}` : `${ph}::${type}`;
|
|
191
201
|
}
|
|
192
|
-
escape(value) {
|
|
193
|
-
return escapeAnsiSqlLiteral(value);
|
|
194
|
-
}
|
|
195
202
|
/**
|
|
196
203
|
* pgvector distance operators. Not every dialect supports every metric - see
|
|
197
204
|
* {@link CockroachDialect.vectorOpsClass} for which ones each dialect actually has; the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgLikeSqlDialect.js","sourceRoot":"","sources":["../../src/dialect/pgLikeSqlDialect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,
|
|
1
|
+
{"version":3,"file":"pgLikeSqlDialect.js","sourceRoot":"","sources":["../../src/dialect/pgLikeSqlDialect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EASL,QAAQ,GAMT,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE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AO,SAAS,GAAG,GAAG,CAAC;QACzB,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChE,OAAO,IAAI,OAAO,GAAG,CAAC;IACxB,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AACnC,CAAC"}
|
|
@@ -10,10 +10,15 @@ export declare class SqlQueryContext implements QueryContext {
|
|
|
10
10
|
readonly dialect: QueryDialect;
|
|
11
11
|
private readonly sqlChunks;
|
|
12
12
|
private readonly params;
|
|
13
|
+
private aliasCounter;
|
|
13
14
|
/**
|
|
14
15
|
* @param dialect The SQL dialect used to determine how values should be formatted as placeholders.
|
|
16
|
+
* @param params An existing values array to bind into instead of a fresh one - shared by a
|
|
17
|
+
* fragment context built via {@link AbstractSqlDialect.buildFragment}, so a bound value's
|
|
18
|
+
* placeholder is numbered correctly against the real query from the moment it's added, rather
|
|
19
|
+
* than needing to be reconciled after the fact.
|
|
15
20
|
*/
|
|
16
|
-
constructor(dialect: QueryDialect);
|
|
21
|
+
constructor(dialect: QueryDialect, params?: unknown[]);
|
|
17
22
|
/**
|
|
18
23
|
* Appends raw SQL string fragments to the query.
|
|
19
24
|
*
|
|
@@ -37,6 +42,13 @@ export declare class SqlQueryContext implements QueryContext {
|
|
|
37
42
|
* @returns The current context instance for method chaining.
|
|
38
43
|
*/
|
|
39
44
|
pushValue(...values: unknown[]): this;
|
|
45
|
+
/**
|
|
46
|
+
* A fresh alias unique within this context, e.g. `nextAlias('_uql_elem')` -> `'_uql_elem_1'`,
|
|
47
|
+
* `'_uql_elem_2'`, ... A fragment context (see the constructor) counts independently of the `ctx`
|
|
48
|
+
* it shares values with - fine today since no fragment-building hook also generates aliases, but
|
|
49
|
+
* worth widening (share this counter too, the same way `params` is shared) if one ever does.
|
|
50
|
+
*/
|
|
51
|
+
nextAlias(prefix: string): string;
|
|
40
52
|
/**
|
|
41
53
|
* Returns the complete SQL query string by joining all accumulated chunks.
|
|
42
54
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryContext.d.ts","sourceRoot":"","sources":["../../src/dialect/queryContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;;;GAMG;AACH,qBAAa,eAAgB,YAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"queryContext.d.ts","sourceRoot":"","sources":["../../src/dialect/queryContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;;;GAMG;AACH,qBAAa,eAAgB,YAAW,YAAY;IAahD,QAAQ,CAAC,OAAO,EAAE,YAAY;IAZhC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,YAAY,CAAK;IAEzB;;;;;;OAMG;IACH,YACW,OAAO,EAAE,YAAY,EAC9B,MAAM,GAAE,OAAO,EAAO,EAGvB;IAED;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAKxB;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAG7B;IAED;;;;;;OAMG;IACH,SAAS,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAGpC;IAED;;;;;OAKG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhC;IAED;;OAEG;IACH,IAAI,GAAG,WAEN;IAED;;OAEG;IACH,IAAI,MAAM,cAET;CACF"}
|
|
@@ -8,12 +8,18 @@
|
|
|
8
8
|
export class SqlQueryContext {
|
|
9
9
|
dialect;
|
|
10
10
|
sqlChunks = [];
|
|
11
|
-
params
|
|
11
|
+
params;
|
|
12
|
+
aliasCounter = 0;
|
|
12
13
|
/**
|
|
13
14
|
* @param dialect The SQL dialect used to determine how values should be formatted as placeholders.
|
|
15
|
+
* @param params An existing values array to bind into instead of a fresh one - shared by a
|
|
16
|
+
* fragment context built via {@link AbstractSqlDialect.buildFragment}, so a bound value's
|
|
17
|
+
* placeholder is numbered correctly against the real query from the moment it's added, rather
|
|
18
|
+
* than needing to be reconciled after the fact.
|
|
14
19
|
*/
|
|
15
|
-
constructor(dialect) {
|
|
20
|
+
constructor(dialect, params = []) {
|
|
16
21
|
this.dialect = dialect;
|
|
22
|
+
this.params = params;
|
|
17
23
|
}
|
|
18
24
|
/**
|
|
19
25
|
* Appends raw SQL string fragments to the query.
|
|
@@ -49,6 +55,15 @@ export class SqlQueryContext {
|
|
|
49
55
|
this.params.push(...values.map((v) => this.dialect.normalizeValue(v)));
|
|
50
56
|
return this;
|
|
51
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* A fresh alias unique within this context, e.g. `nextAlias('_uql_elem')` -> `'_uql_elem_1'`,
|
|
60
|
+
* `'_uql_elem_2'`, ... A fragment context (see the constructor) counts independently of the `ctx`
|
|
61
|
+
* it shares values with - fine today since no fragment-building hook also generates aliases, but
|
|
62
|
+
* worth widening (share this counter too, the same way `params` is shared) if one ever does.
|
|
63
|
+
*/
|
|
64
|
+
nextAlias(prefix) {
|
|
65
|
+
return `${prefix}_${++this.aliasCounter}`;
|
|
66
|
+
}
|
|
52
67
|
/**
|
|
53
68
|
* Returns the complete SQL query string by joining all accumulated chunks.
|
|
54
69
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryContext.js","sourceRoot":"","sources":["../../src/dialect/queryContext.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":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CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type VectorCast } from '../schema/canonicalType.js';
|
|
2
|
+
import type { EntityMeta, FieldOptions, QueryContext, QueryVectorSearch, VectorDistance } from '../type/index.js';
|
|
3
|
+
import { AbstractDialect } from './abstractDialect.js';
|
|
4
|
+
/**
|
|
5
|
+
* Vector similarity search for SQL dialects: the `ORDER BY <distance>` expression, its projection as
|
|
6
|
+
* a named score, and the index metadata the schema generator reads.
|
|
7
|
+
*
|
|
8
|
+
* A layer of its own because it is nearly self-contained - it needs only `escapeId` from the SQL
|
|
9
|
+
* dialect above it - unlike the JSON operators, which are woven into the generic comparison
|
|
10
|
+
* machinery (`neExpr`, `numericCast`, `formatIn`, ...) and belong with it.
|
|
11
|
+
*
|
|
12
|
+
* Two shapes exist across dialects: an operator (`"col" <=> $1`, Postgres/CockroachDB) or a function
|
|
13
|
+
* call (`VEC_DISTANCE_COSINE(col, ?)`, MariaDB/SQLite). Dialects pick one by either overriding
|
|
14
|
+
* {@link appendVectorSort} or filling {@link vectorDistanceFns}.
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class VectorSqlDialect extends AbstractDialect {
|
|
17
|
+
/** Vector index operator classes, keyed by distance metric. Partial: not every dialect supports every metric. */
|
|
18
|
+
readonly vectorOpsClass: ReadonlyMap<VectorDistance, string> | undefined;
|
|
19
|
+
readonly vectorExtension: string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Mapping of UQL vector distance metrics to native SQL functions.
|
|
22
|
+
* Override in dialects that use function-call syntax (e.g. SQLite, MariaDB).
|
|
23
|
+
* Dialects with operator-based syntax (e.g. Postgres) leave this empty and override `appendVectorSort` directly.
|
|
24
|
+
*/
|
|
25
|
+
protected readonly vectorDistanceFns: ReadonlyMap<VectorDistance, string>;
|
|
26
|
+
/** Quotes an identifier; supplied by the SQL dialect built on top of this layer. */
|
|
27
|
+
abstract escapeId(val: string, forbidQualified?: boolean, addDot?: boolean): string;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve common parameters for a vector similarity ORDER BY expression.
|
|
30
|
+
* Shared by all dialect overrides of `appendVectorSort`.
|
|
31
|
+
*/
|
|
32
|
+
protected resolveVectorSortParams<E>(meta: EntityMeta<E>, key: string, search: QueryVectorSearch): {
|
|
33
|
+
colName: string;
|
|
34
|
+
distance: VectorDistance;
|
|
35
|
+
field: FieldOptions | undefined;
|
|
36
|
+
vectorCast: VectorCast;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Append a vector similarity function call: `fn(col, ?)`.
|
|
40
|
+
* Used by dialects that express vector distance via SQL functions (SQLite, MariaDB).
|
|
41
|
+
*/
|
|
42
|
+
protected appendFunctionVectorSort<E>(ctx: QueryContext, meta: EntityMeta<E>, key: string, search: QueryVectorSearch): void;
|
|
43
|
+
/**
|
|
44
|
+
* Append a vector distance projection.
|
|
45
|
+
* Delegates to `appendVectorSort` so each dialect's distance syntax is written once.
|
|
46
|
+
*/
|
|
47
|
+
protected appendVectorProjection<E>(ctx: QueryContext, meta: EntityMeta<E>, key: string, search: QueryVectorSearch): void;
|
|
48
|
+
/**
|
|
49
|
+
* Append a vector similarity expression for `ORDER BY`.
|
|
50
|
+
* Default: auto-delegates to `appendFunctionVectorSort` when `vectorDistanceFns` has entries.
|
|
51
|
+
*/
|
|
52
|
+
protected appendVectorSort<E>(ctx: QueryContext, meta: EntityMeta<E>, key: string, search: QueryVectorSearch): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=vectorSqlDialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vectorSqlDialect.d.ts","sourceRoot":"","sources":["../../src/dialect/vectorSqlDialect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,KAAK,EACV,UAAU,EAEV,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACf,MAAM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