metal-orm 1.1.18 → 1.1.20
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/README.md +2 -2
- package/dist/index.cjs +181 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -2
- package/dist/index.d.ts +81 -2
- package/dist/index.js +172 -50
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +9 -0
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +5 -0
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +23 -2
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +9 -0
- package/src/core/dialect/mssql/functions.ts +10 -0
- package/src/core/dialect/mysql/functions.ts +9 -0
- package/src/core/dialect/postgres/functions.ts +21 -0
- package/src/core/dialect/sqlite/functions.ts +10 -0
- package/src/core/functions/vector.ts +141 -0
- package/src/index.ts +1 -0
- package/src/schema/column-types.ts +34 -1
- package/src/schema/table.ts +6 -0
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ You don’t have to use decorators, but when you do, you’re still on the same
|
|
|
175
175
|
<a id="installation"></a>
|
|
176
176
|
## Installation 📦
|
|
177
177
|
|
|
178
|
-
**Requirements:** Node.js ≥
|
|
178
|
+
**Requirements:** Node.js ≥ 22.0.0. For TypeScript projects, use TS 5.6+ to get the standard decorators API and typings.
|
|
179
179
|
|
|
180
180
|
```bash
|
|
181
181
|
# npm
|
|
@@ -196,7 +196,7 @@ MetalORM compiles SQL; you bring your own driver:
|
|
|
196
196
|
| SQLite | `sqlite3` | `npm install sqlite3` |
|
|
197
197
|
| SQLite | `better-sqlite3` | `npm install better-sqlite3` |
|
|
198
198
|
| PostgreSQL | `pg` | `npm install pg` |
|
|
199
|
-
| SQL Server | `tedious` | `npm install tedious`
|
|
199
|
+
| SQL Server | `tedious` | `npm install tedious` (Node 22+) |
|
|
200
200
|
|
|
201
201
|
Pick the matching dialect (`MySqlDialect`, `SQLiteDialect`, `PostgresDialect`, `MSSQLDialect`) when compiling queries.
|
|
202
202
|
|
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __esm = (
|
|
6
|
-
return
|
|
5
|
+
var __esm = (fn9, res) => function __init() {
|
|
6
|
+
return fn9 && (res = (0, fn9[__getOwnPropNames(fn9)[0]])(fn9 = 0)), res;
|
|
7
7
|
};
|
|
8
8
|
var __export = (target, all) => {
|
|
9
9
|
for (var name in all)
|
|
@@ -182,6 +182,7 @@ __export(index_exports, {
|
|
|
182
182
|
concatWs: () => concatWs,
|
|
183
183
|
correlateBy: () => correlateBy,
|
|
184
184
|
cos: () => cos,
|
|
185
|
+
cosineDistance: () => cosineDistance,
|
|
185
186
|
cot: () => cot,
|
|
186
187
|
count: () => count,
|
|
187
188
|
countAll: () => countAll,
|
|
@@ -218,12 +219,14 @@ __export(index_exports, {
|
|
|
218
219
|
denseRank: () => denseRank,
|
|
219
220
|
diffSchema: () => diffSchema,
|
|
220
221
|
div: () => div,
|
|
222
|
+
dotProduct: () => dotProduct,
|
|
221
223
|
dtoToOpenApiSchema: () => dtoToOpenApiSchema,
|
|
222
224
|
endOfMonth: () => endOfMonth,
|
|
223
225
|
entityRef: () => entityRef,
|
|
224
226
|
entityRefs: () => entityRefs,
|
|
225
227
|
eq: () => eq,
|
|
226
228
|
esel: () => esel,
|
|
229
|
+
euclideanDistance: () => euclideanDistance,
|
|
227
230
|
exclude: () => exclude,
|
|
228
231
|
executeFilteredPaged: () => executeFilteredPaged,
|
|
229
232
|
executeHydrated: () => executeHydrated,
|
|
@@ -281,6 +284,7 @@ __export(index_exports, {
|
|
|
281
284
|
inList: () => inList,
|
|
282
285
|
inSubquery: () => inSubquery,
|
|
283
286
|
initcap: () => initcap,
|
|
287
|
+
innerProduct: () => innerProduct,
|
|
284
288
|
insertInto: () => insertInto,
|
|
285
289
|
instr: () => instr,
|
|
286
290
|
introspectSchema: () => introspectSchema,
|
|
@@ -309,6 +313,8 @@ __export(index_exports, {
|
|
|
309
313
|
jsonPath: () => jsonPath,
|
|
310
314
|
jsonSet: () => jsonSet,
|
|
311
315
|
jsonify: () => jsonify,
|
|
316
|
+
l1Distance: () => l1Distance,
|
|
317
|
+
l2Distance: () => l2Distance,
|
|
312
318
|
lag: () => lag,
|
|
313
319
|
lastValue: () => lastValue,
|
|
314
320
|
lead: () => lead,
|
|
@@ -336,6 +342,7 @@ __export(index_exports, {
|
|
|
336
342
|
lt: () => lt,
|
|
337
343
|
lte: () => lte,
|
|
338
344
|
ltrim: () => ltrim,
|
|
345
|
+
manhattanDistance: () => manhattanDistance,
|
|
339
346
|
mapFields: () => mapFields,
|
|
340
347
|
materializeAs: () => materializeAs,
|
|
341
348
|
max: () => max,
|
|
@@ -455,6 +462,8 @@ __export(index_exports, {
|
|
|
455
462
|
validateTreeTable: () => validateTreeTable,
|
|
456
463
|
valueToOperand: () => valueToOperand,
|
|
457
464
|
variance: () => variance,
|
|
465
|
+
vectorDistance: () => vectorDistance,
|
|
466
|
+
vectorMatch: () => vectorMatch,
|
|
458
467
|
visitExpression: () => visitExpression,
|
|
459
468
|
visitOperand: () => visitOperand,
|
|
460
469
|
weekOfYear: () => weekOfYear,
|
|
@@ -575,7 +584,9 @@ var STANDARD_COLUMN_TYPES = [
|
|
|
575
584
|
"DATETIME",
|
|
576
585
|
"TIMESTAMP",
|
|
577
586
|
"TIMESTAMPTZ",
|
|
578
|
-
"BOOLEAN"
|
|
587
|
+
"BOOLEAN",
|
|
588
|
+
"VECTOR",
|
|
589
|
+
"HALFVEC"
|
|
579
590
|
];
|
|
580
591
|
var STANDARD_TYPE_SET = new Set(STANDARD_COLUMN_TYPES.map((t) => t.toLowerCase()));
|
|
581
592
|
var normalizeColumnType = (type) => {
|
|
@@ -685,6 +696,27 @@ var col = {
|
|
|
685
696
|
* @param values - Enum values
|
|
686
697
|
*/
|
|
687
698
|
enum: (values) => ({ name: "", type: "ENUM", args: values }),
|
|
699
|
+
/**
|
|
700
|
+
* Creates a vector column definition
|
|
701
|
+
* @param dimensions - Vector dimensions
|
|
702
|
+
* @param options - Vector options (e.g. elementType: 'float16' | 'float32')
|
|
703
|
+
*/
|
|
704
|
+
vector: (dimensions, options) => ({
|
|
705
|
+
name: "",
|
|
706
|
+
type: "VECTOR",
|
|
707
|
+
args: [dimensions],
|
|
708
|
+
vectorOptions: { dimensions, ...options }
|
|
709
|
+
}),
|
|
710
|
+
/**
|
|
711
|
+
* Creates a half-precision (float16) vector column definition (pgvector halfvec / SQL Server float16 vector / sqlite-vec float16)
|
|
712
|
+
* @param dimensions - Vector dimensions
|
|
713
|
+
*/
|
|
714
|
+
halfvec: (dimensions) => ({
|
|
715
|
+
name: "",
|
|
716
|
+
type: "HALFVEC",
|
|
717
|
+
args: [dimensions],
|
|
718
|
+
vectorOptions: { dimensions, elementType: "float16" }
|
|
719
|
+
}),
|
|
688
720
|
/**
|
|
689
721
|
* Creates a column definition with a custom SQL type.
|
|
690
722
|
* Useful for dialect-specific types without polluting the standard set.
|
|
@@ -2158,13 +2190,13 @@ var FunctionTableFormatter = class {
|
|
|
2158
2190
|
* @param dialect - The dialect instance for compiling operands.
|
|
2159
2191
|
* @returns SQL function table expression (e.g., "LATERAL schema.func(args) WITH ORDINALITY AS alias(col1, col2)").
|
|
2160
2192
|
*/
|
|
2161
|
-
static format(
|
|
2162
|
-
const schemaPart = this.formatSchema(
|
|
2163
|
-
const args = this.formatArgs(
|
|
2164
|
-
const base = this.formatBase(
|
|
2165
|
-
const lateral = this.formatLateral(
|
|
2166
|
-
const alias = this.formatAlias(
|
|
2167
|
-
const colAliases = this.formatColumnAliases(
|
|
2193
|
+
static format(fn9, ctx, dialect) {
|
|
2194
|
+
const schemaPart = this.formatSchema(fn9, dialect);
|
|
2195
|
+
const args = this.formatArgs(fn9, ctx, dialect);
|
|
2196
|
+
const base = this.formatBase(fn9, schemaPart, args);
|
|
2197
|
+
const lateral = this.formatLateral(fn9);
|
|
2198
|
+
const alias = this.formatAlias(fn9, dialect);
|
|
2199
|
+
const colAliases = this.formatColumnAliases(fn9, dialect);
|
|
2168
2200
|
return `${lateral}${base}${alias}${colAliases}`;
|
|
2169
2201
|
}
|
|
2170
2202
|
/**
|
|
@@ -2174,9 +2206,9 @@ var FunctionTableFormatter = class {
|
|
|
2174
2206
|
* @returns Schema prefix (e.g., "schema.") or empty string.
|
|
2175
2207
|
* @internal
|
|
2176
2208
|
*/
|
|
2177
|
-
static formatSchema(
|
|
2178
|
-
if (!
|
|
2179
|
-
const quoted = dialect ? dialect.quoteIdentifier(
|
|
2209
|
+
static formatSchema(fn9, dialect) {
|
|
2210
|
+
if (!fn9.schema) return "";
|
|
2211
|
+
const quoted = dialect ? dialect.quoteIdentifier(fn9.schema) : fn9.schema;
|
|
2180
2212
|
return `${quoted}.`;
|
|
2181
2213
|
}
|
|
2182
2214
|
/**
|
|
@@ -2187,8 +2219,8 @@ var FunctionTableFormatter = class {
|
|
|
2187
2219
|
* @returns Comma-separated function arguments.
|
|
2188
2220
|
* @internal
|
|
2189
2221
|
*/
|
|
2190
|
-
static formatArgs(
|
|
2191
|
-
return (
|
|
2222
|
+
static formatArgs(fn9, ctx, dialect) {
|
|
2223
|
+
return (fn9.args || []).map((a) => {
|
|
2192
2224
|
if (ctx && dialect) {
|
|
2193
2225
|
return dialect.compileOperand(a, ctx);
|
|
2194
2226
|
}
|
|
@@ -2204,9 +2236,9 @@ var FunctionTableFormatter = class {
|
|
|
2204
2236
|
* @returns Base function call expression (e.g., "schema.func(args) WITH ORDINALITY").
|
|
2205
2237
|
* @internal
|
|
2206
2238
|
*/
|
|
2207
|
-
static formatBase(
|
|
2208
|
-
const ordinality =
|
|
2209
|
-
return `${schemaPart}${
|
|
2239
|
+
static formatBase(fn9, schemaPart, args) {
|
|
2240
|
+
const ordinality = fn9.withOrdinality ? " WITH ORDINALITY" : "";
|
|
2241
|
+
return `${schemaPart}${fn9.name}(${args})${ordinality}`;
|
|
2210
2242
|
}
|
|
2211
2243
|
/**
|
|
2212
2244
|
* Formats the LATERAL keyword if present.
|
|
@@ -2214,8 +2246,8 @@ var FunctionTableFormatter = class {
|
|
|
2214
2246
|
* @returns "LATERAL " or empty string.
|
|
2215
2247
|
* @internal
|
|
2216
2248
|
*/
|
|
2217
|
-
static formatLateral(
|
|
2218
|
-
return
|
|
2249
|
+
static formatLateral(fn9) {
|
|
2250
|
+
return fn9.lateral ? "LATERAL " : "";
|
|
2219
2251
|
}
|
|
2220
2252
|
/**
|
|
2221
2253
|
* Formats the table alias for the function table.
|
|
@@ -2224,9 +2256,9 @@ var FunctionTableFormatter = class {
|
|
|
2224
2256
|
* @returns " AS alias" or empty string.
|
|
2225
2257
|
* @internal
|
|
2226
2258
|
*/
|
|
2227
|
-
static formatAlias(
|
|
2228
|
-
if (!
|
|
2229
|
-
const quoted = dialect ? dialect.quoteIdentifier(
|
|
2259
|
+
static formatAlias(fn9, dialect) {
|
|
2260
|
+
if (!fn9.alias) return "";
|
|
2261
|
+
const quoted = dialect ? dialect.quoteIdentifier(fn9.alias) : fn9.alias;
|
|
2230
2262
|
return ` AS ${quoted}`;
|
|
2231
2263
|
}
|
|
2232
2264
|
/**
|
|
@@ -2236,9 +2268,9 @@ var FunctionTableFormatter = class {
|
|
|
2236
2268
|
* @returns "(col1, col2, ...)" or empty string.
|
|
2237
2269
|
* @internal
|
|
2238
2270
|
*/
|
|
2239
|
-
static formatColumnAliases(
|
|
2240
|
-
if (!
|
|
2241
|
-
const aliases =
|
|
2271
|
+
static formatColumnAliases(fn9, dialect) {
|
|
2272
|
+
if (!fn9.columnAliases || !fn9.columnAliases.length) return "";
|
|
2273
|
+
const aliases = fn9.columnAliases.map((col2) => dialect ? dialect.quoteIdentifier(col2) : col2).join(", ");
|
|
2242
2274
|
return `(${aliases})`;
|
|
2243
2275
|
}
|
|
2244
2276
|
};
|
|
@@ -2520,24 +2552,24 @@ var SqlDialectBase = class extends Dialect {
|
|
|
2520
2552
|
}
|
|
2521
2553
|
return this.compileTableSource(tableSource);
|
|
2522
2554
|
}
|
|
2523
|
-
compileFunctionTable(
|
|
2524
|
-
const key =
|
|
2555
|
+
compileFunctionTable(fn9, ctx) {
|
|
2556
|
+
const key = fn9.key ?? fn9.name;
|
|
2525
2557
|
if (ctx) {
|
|
2526
2558
|
const renderer = this.tableFunctionStrategy.getRenderer(key);
|
|
2527
2559
|
if (renderer) {
|
|
2528
|
-
const compiledArgs = (
|
|
2560
|
+
const compiledArgs = (fn9.args ?? []).map((arg) => this.compileOperand(arg, ctx));
|
|
2529
2561
|
return renderer({
|
|
2530
|
-
node:
|
|
2562
|
+
node: fn9,
|
|
2531
2563
|
compiledArgs,
|
|
2532
2564
|
compileOperand: (operand) => this.compileOperand(operand, ctx),
|
|
2533
2565
|
quoteIdentifier: this.quoteIdentifier.bind(this)
|
|
2534
2566
|
});
|
|
2535
2567
|
}
|
|
2536
|
-
if (
|
|
2568
|
+
if (fn9.key) {
|
|
2537
2569
|
throw new Error(`Table function "${key}" is not supported by dialect "${this.dialect}".`);
|
|
2538
2570
|
}
|
|
2539
2571
|
}
|
|
2540
|
-
return FunctionTableFormatter.format(
|
|
2572
|
+
return FunctionTableFormatter.format(fn9, ctx, this);
|
|
2541
2573
|
}
|
|
2542
2574
|
compileDerivedTable(table, ctx) {
|
|
2543
2575
|
if (!table.alias) {
|
|
@@ -2726,6 +2758,26 @@ var PostgresFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
2726
2758
|
const pathArray = this.formatJsonbPathArray(pathNode);
|
|
2727
2759
|
return `jsonb_set(${compiledArgs[0]}, ${pathArray}, ${compiledArgs[2]}::jsonb, true)`;
|
|
2728
2760
|
});
|
|
2761
|
+
this.add("VECTOR_DISTANCE", ({ node, compiledArgs }) => {
|
|
2762
|
+
if (compiledArgs.length !== 3) throw new Error("VECTOR_DISTANCE expects 3 arguments (metric, v1, v2)");
|
|
2763
|
+
const metric = node.args[0]?.type === "Literal" ? String(node.args[0].value).toLowerCase() : compiledArgs[0].replace(/['"]/g, "").toLowerCase();
|
|
2764
|
+
const [, v1, v2] = compiledArgs;
|
|
2765
|
+
switch (metric) {
|
|
2766
|
+
case "cosine":
|
|
2767
|
+
return `(${v1} <=> ${v2})`;
|
|
2768
|
+
case "euclidean":
|
|
2769
|
+
case "l2":
|
|
2770
|
+
return `(${v1} <-> ${v2})`;
|
|
2771
|
+
case "dot":
|
|
2772
|
+
case "inner_product":
|
|
2773
|
+
return `(${v1} <#> ${v2})`;
|
|
2774
|
+
case "manhattan":
|
|
2775
|
+
case "l1":
|
|
2776
|
+
return `(${v1} <~> ${v2})`;
|
|
2777
|
+
default:
|
|
2778
|
+
return `(${v1} <=> ${v2})`;
|
|
2779
|
+
}
|
|
2780
|
+
});
|
|
2729
2781
|
}
|
|
2730
2782
|
formatJsonbPathArray(pathNode) {
|
|
2731
2783
|
const rawPath = String(pathNode.value ?? "");
|
|
@@ -2957,6 +3009,14 @@ var MysqlFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
2957
3009
|
if (compiledArgs.length !== 2) throw new Error("ARRAY_APPEND expects 2 arguments (array, value)");
|
|
2958
3010
|
return `JSON_ARRAY_APPEND(${compiledArgs[0]}, '$', ${compiledArgs[1]})`;
|
|
2959
3011
|
});
|
|
3012
|
+
this.add("VECTOR_DISTANCE", ({ node, compiledArgs }) => {
|
|
3013
|
+
if (compiledArgs.length !== 3) throw new Error("VECTOR_DISTANCE expects 3 arguments (metric, v1, v2)");
|
|
3014
|
+
let metric = node.args[0]?.type === "Literal" ? String(node.args[0].value).toUpperCase() : compiledArgs[0].replace(/['"]/g, "").toUpperCase();
|
|
3015
|
+
if (metric === "L2") metric = "EUCLIDEAN";
|
|
3016
|
+
if (metric === "INNER_PRODUCT") metric = "DOT";
|
|
3017
|
+
const [, v1, v2] = compiledArgs;
|
|
3018
|
+
return `DISTANCE(${v1}, ${v2}, '${metric}')`;
|
|
3019
|
+
});
|
|
2960
3020
|
}
|
|
2961
3021
|
};
|
|
2962
3022
|
|
|
@@ -3193,6 +3253,15 @@ var SqliteFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
3193
3253
|
return `json_array_append(${compiledArgs[0]}, '$', ${compiledArgs[1]})`;
|
|
3194
3254
|
});
|
|
3195
3255
|
this.add("CHR", ({ compiledArgs }) => `CHAR(${compiledArgs[0]})`);
|
|
3256
|
+
this.add("VECTOR_DISTANCE", ({ node, compiledArgs }) => {
|
|
3257
|
+
if (compiledArgs.length !== 3) throw new Error("VECTOR_DISTANCE expects 3 arguments (metric, v1, v2)");
|
|
3258
|
+
const metric = node.args[0]?.type === "Literal" ? String(node.args[0].value).toLowerCase() : compiledArgs[0].replace(/['"]/g, "").toLowerCase();
|
|
3259
|
+
const [, v1, v2] = compiledArgs;
|
|
3260
|
+
if (metric === "euclidean" || metric === "l2") {
|
|
3261
|
+
return `vec_distance_L2(${v1}, ${v2})`;
|
|
3262
|
+
}
|
|
3263
|
+
return `vec_distance_cosine(${v1}, ${v2})`;
|
|
3264
|
+
});
|
|
3196
3265
|
}
|
|
3197
3266
|
};
|
|
3198
3267
|
|
|
@@ -3394,6 +3463,15 @@ var MssqlFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
3394
3463
|
this.add("ARRAY_APPEND", () => {
|
|
3395
3464
|
throw new Error("ARRAY_APPEND is not supported on SQL Server");
|
|
3396
3465
|
});
|
|
3466
|
+
this.add("VECTOR_DISTANCE", ({ node, compiledArgs }) => {
|
|
3467
|
+
if (compiledArgs.length !== 3) throw new Error("VECTOR_DISTANCE expects 3 arguments (metric, v1, v2)");
|
|
3468
|
+
let metric = node.args[0]?.type === "Literal" ? String(node.args[0].value).toLowerCase() : compiledArgs[0].replace(/['"]/g, "").toLowerCase();
|
|
3469
|
+
if (metric === "l2") metric = "euclidean";
|
|
3470
|
+
if (metric === "l1") metric = "manhattan";
|
|
3471
|
+
if (metric === "inner_product") metric = "dot";
|
|
3472
|
+
const [, v1, v2] = compiledArgs;
|
|
3473
|
+
return `VECTOR_DISTANCE('${metric}', ${v1}, ${v2})`;
|
|
3474
|
+
});
|
|
3397
3475
|
}
|
|
3398
3476
|
};
|
|
3399
3477
|
|
|
@@ -13843,6 +13921,50 @@ var fn7 = (key, args) => ({
|
|
|
13843
13921
|
var afn3 = (key, args) => asType(fn7(key, args));
|
|
13844
13922
|
var arrayAppend = (array, value) => afn3("ARRAY_APPEND", [array, value]);
|
|
13845
13923
|
|
|
13924
|
+
// src/core/functions/vector.ts
|
|
13925
|
+
var isColumnDef7 = (val) => !!val && typeof val === "object" && "type" in val && "name" in val;
|
|
13926
|
+
var toOperand8 = (input) => {
|
|
13927
|
+
if (isOperandNode(input)) return input;
|
|
13928
|
+
if (isColumnDef7(input)) return columnOperand(input);
|
|
13929
|
+
if (Array.isArray(input) || input instanceof Float32Array) {
|
|
13930
|
+
const formatted = `[${Array.from(input).join(", ")}]`;
|
|
13931
|
+
return valueToOperand(formatted);
|
|
13932
|
+
}
|
|
13933
|
+
return valueToOperand(input);
|
|
13934
|
+
};
|
|
13935
|
+
var fn8 = (key, args) => ({
|
|
13936
|
+
type: "Function",
|
|
13937
|
+
name: key,
|
|
13938
|
+
fn: key,
|
|
13939
|
+
args
|
|
13940
|
+
});
|
|
13941
|
+
var vectorDistance = (metric, v1, v2) => {
|
|
13942
|
+
const metricOp = valueToOperand(metric.toLowerCase());
|
|
13943
|
+
return asType(fn8("VECTOR_DISTANCE", [metricOp, toOperand8(v1), toOperand8(v2)]));
|
|
13944
|
+
};
|
|
13945
|
+
var cosineDistance = (v1, v2) => vectorDistance("cosine", v1, v2);
|
|
13946
|
+
var l2Distance = (v1, v2) => vectorDistance("euclidean", v1, v2);
|
|
13947
|
+
var euclideanDistance = (v1, v2) => vectorDistance("euclidean", v1, v2);
|
|
13948
|
+
var innerProduct = (v1, v2) => vectorDistance("dot", v1, v2);
|
|
13949
|
+
var dotProduct = (v1, v2) => vectorDistance("dot", v1, v2);
|
|
13950
|
+
var l1Distance = (v1, v2) => vectorDistance("manhattan", v1, v2);
|
|
13951
|
+
var manhattanDistance = (v1, v2) => vectorDistance("manhattan", v1, v2);
|
|
13952
|
+
var vectorMatch = (column, vector, k) => {
|
|
13953
|
+
const match = {
|
|
13954
|
+
type: "BinaryExpression",
|
|
13955
|
+
left: toOperand8(column),
|
|
13956
|
+
operator: "MATCH",
|
|
13957
|
+
right: toOperand8(vector)
|
|
13958
|
+
};
|
|
13959
|
+
const kNode = {
|
|
13960
|
+
type: "BinaryExpression",
|
|
13961
|
+
left: valueToOperand("k"),
|
|
13962
|
+
operator: "=",
|
|
13963
|
+
right: valueToOperand(k)
|
|
13964
|
+
};
|
|
13965
|
+
return { type: "LogicalExpression", operator: "AND", operands: [match, kNode] };
|
|
13966
|
+
};
|
|
13967
|
+
|
|
13846
13968
|
// src/orm/als.ts
|
|
13847
13969
|
var AsyncLocalStorage = class {
|
|
13848
13970
|
store;
|
|
@@ -14158,12 +14280,12 @@ var TypeScriptGenerator = class {
|
|
|
14158
14280
|
printBinaryExpression(binary) {
|
|
14159
14281
|
const left2 = this.printOperand(binary.left);
|
|
14160
14282
|
const right2 = this.printOperand(binary.right);
|
|
14161
|
-
const
|
|
14283
|
+
const fn9 = this.mapOp(binary.operator);
|
|
14162
14284
|
const args = [left2, right2];
|
|
14163
14285
|
if (binary.escape) {
|
|
14164
14286
|
args.push(this.printOperand(binary.escape));
|
|
14165
14287
|
}
|
|
14166
|
-
return `${
|
|
14288
|
+
return `${fn9}(${args.join(", ")})`;
|
|
14167
14289
|
}
|
|
14168
14290
|
/**
|
|
14169
14291
|
* Prints a logical expression to TypeScript code
|
|
@@ -14195,13 +14317,13 @@ var TypeScriptGenerator = class {
|
|
|
14195
14317
|
*/
|
|
14196
14318
|
printInExpression(inExpr) {
|
|
14197
14319
|
const left2 = this.printOperand(inExpr.left);
|
|
14198
|
-
const
|
|
14320
|
+
const fn9 = this.mapOp(inExpr.operator);
|
|
14199
14321
|
if (Array.isArray(inExpr.right)) {
|
|
14200
14322
|
const values = inExpr.right.map((v) => this.printOperand(v)).join(", ");
|
|
14201
|
-
return `${
|
|
14323
|
+
return `${fn9}(${left2}, [${values}])`;
|
|
14202
14324
|
}
|
|
14203
14325
|
const subquery = this.inlineChain(this.buildSelectLines(inExpr.right.query));
|
|
14204
|
-
return `${
|
|
14326
|
+
return `${fn9}(${left2}, (${subquery}))`;
|
|
14205
14327
|
}
|
|
14206
14328
|
/**
|
|
14207
14329
|
* Prints a null expression to TypeScript code
|
|
@@ -14210,8 +14332,8 @@ var TypeScriptGenerator = class {
|
|
|
14210
14332
|
*/
|
|
14211
14333
|
printNullExpression(nullExpr) {
|
|
14212
14334
|
const left2 = this.printOperand(nullExpr.left);
|
|
14213
|
-
const
|
|
14214
|
-
return `${
|
|
14335
|
+
const fn9 = this.mapOp(nullExpr.operator);
|
|
14336
|
+
return `${fn9}(${left2})`;
|
|
14215
14337
|
}
|
|
14216
14338
|
/**
|
|
14217
14339
|
* Prints a BETWEEN expression to TypeScript code
|
|
@@ -14255,9 +14377,9 @@ var TypeScriptGenerator = class {
|
|
|
14255
14377
|
* @param fn - Function node
|
|
14256
14378
|
* @returns TypeScript code representation
|
|
14257
14379
|
*/
|
|
14258
|
-
printFunctionOperand(
|
|
14259
|
-
const args =
|
|
14260
|
-
return `${
|
|
14380
|
+
printFunctionOperand(fn9) {
|
|
14381
|
+
const args = fn9.args.map((a) => this.printOperand(a)).join(", ");
|
|
14382
|
+
return `${fn9.name.toLowerCase()}(${args})`;
|
|
14261
14383
|
}
|
|
14262
14384
|
/**
|
|
14263
14385
|
* Prints a JSON path operand to TypeScript code
|
|
@@ -15872,9 +15994,9 @@ var OrmSession = class {
|
|
|
15872
15994
|
* @returns The result of the function
|
|
15873
15995
|
* @throws If the transaction fails
|
|
15874
15996
|
*/
|
|
15875
|
-
async transaction(
|
|
15997
|
+
async transaction(fn9) {
|
|
15876
15998
|
if (!this.executor.capabilities.transactions) {
|
|
15877
|
-
const result = await
|
|
15999
|
+
const result = await fn9(this);
|
|
15878
16000
|
await this.commit();
|
|
15879
16001
|
return result;
|
|
15880
16002
|
}
|
|
@@ -15890,7 +16012,7 @@ var OrmSession = class {
|
|
|
15890
16012
|
}
|
|
15891
16013
|
this.transactionDepth += 1;
|
|
15892
16014
|
try {
|
|
15893
|
-
const result = await
|
|
16015
|
+
const result = await fn9(this);
|
|
15894
16016
|
this.throwIfRollbackOnly();
|
|
15895
16017
|
await this.flushWithHooks();
|
|
15896
16018
|
this.throwIfRollbackOnly();
|
|
@@ -16404,7 +16526,7 @@ var Orm = class {
|
|
|
16404
16526
|
* @returns The result of the function
|
|
16405
16527
|
* @throws If the transaction fails
|
|
16406
16528
|
*/
|
|
16407
|
-
async transaction(
|
|
16529
|
+
async transaction(fn9) {
|
|
16408
16530
|
const executor = this.executorFactory.createTransactionalExecutor();
|
|
16409
16531
|
const session = new OrmSession({
|
|
16410
16532
|
orm: this,
|
|
@@ -16412,7 +16534,7 @@ var Orm = class {
|
|
|
16412
16534
|
cacheManager: this.cacheManager
|
|
16413
16535
|
});
|
|
16414
16536
|
try {
|
|
16415
|
-
return await session.transaction(() =>
|
|
16537
|
+
return await session.transaction(() => fn9(session));
|
|
16416
16538
|
} finally {
|
|
16417
16539
|
await session.dispose();
|
|
16418
16540
|
}
|
|
@@ -21701,10 +21823,10 @@ async function runChunk(task, chunkIndex, totalChunks, rowsInChunk, timing, onCh
|
|
|
21701
21823
|
}
|
|
21702
21824
|
return result;
|
|
21703
21825
|
}
|
|
21704
|
-
async function maybeTransaction(session, transactional,
|
|
21705
|
-
if (!transactional) return
|
|
21826
|
+
async function maybeTransaction(session, transactional, fn9) {
|
|
21827
|
+
if (!transactional) return fn9();
|
|
21706
21828
|
const ormSession = session;
|
|
21707
|
-
return ormSession.transaction(
|
|
21829
|
+
return ormSession.transaction(fn9);
|
|
21708
21830
|
}
|
|
21709
21831
|
function aggregateOutcomes(outcomes) {
|
|
21710
21832
|
const result = {
|
|
@@ -22171,6 +22293,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22171
22293
|
concatWs,
|
|
22172
22294
|
correlateBy,
|
|
22173
22295
|
cos,
|
|
22296
|
+
cosineDistance,
|
|
22174
22297
|
cot,
|
|
22175
22298
|
count,
|
|
22176
22299
|
countAll,
|
|
@@ -22207,12 +22330,14 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22207
22330
|
denseRank,
|
|
22208
22331
|
diffSchema,
|
|
22209
22332
|
div,
|
|
22333
|
+
dotProduct,
|
|
22210
22334
|
dtoToOpenApiSchema,
|
|
22211
22335
|
endOfMonth,
|
|
22212
22336
|
entityRef,
|
|
22213
22337
|
entityRefs,
|
|
22214
22338
|
eq,
|
|
22215
22339
|
esel,
|
|
22340
|
+
euclideanDistance,
|
|
22216
22341
|
exclude,
|
|
22217
22342
|
executeFilteredPaged,
|
|
22218
22343
|
executeHydrated,
|
|
@@ -22270,6 +22395,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22270
22395
|
inList,
|
|
22271
22396
|
inSubquery,
|
|
22272
22397
|
initcap,
|
|
22398
|
+
innerProduct,
|
|
22273
22399
|
insertInto,
|
|
22274
22400
|
instr,
|
|
22275
22401
|
introspectSchema,
|
|
@@ -22298,6 +22424,8 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22298
22424
|
jsonPath,
|
|
22299
22425
|
jsonSet,
|
|
22300
22426
|
jsonify,
|
|
22427
|
+
l1Distance,
|
|
22428
|
+
l2Distance,
|
|
22301
22429
|
lag,
|
|
22302
22430
|
lastValue,
|
|
22303
22431
|
lead,
|
|
@@ -22325,6 +22453,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22325
22453
|
lt,
|
|
22326
22454
|
lte,
|
|
22327
22455
|
ltrim,
|
|
22456
|
+
manhattanDistance,
|
|
22328
22457
|
mapFields,
|
|
22329
22458
|
materializeAs,
|
|
22330
22459
|
max,
|
|
@@ -22444,6 +22573,8 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22444
22573
|
validateTreeTable,
|
|
22445
22574
|
valueToOperand,
|
|
22446
22575
|
variance,
|
|
22576
|
+
vectorDistance,
|
|
22577
|
+
vectorMatch,
|
|
22447
22578
|
visitExpression,
|
|
22448
22579
|
visitOperand,
|
|
22449
22580
|
weekOfYear,
|