metal-orm 1.1.25 → 1.1.26
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 +393 -460
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -201
- package/dist/index.d.ts +128 -201
- package/dist/index.js +387 -458
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/dialect/abstract.ts +7 -229
- package/src/core/dialect/base/sql-dialect-composer.ts +294 -0
- package/src/core/dialect/base/standard-sql-services.ts +2 -6
- package/src/core/dialect/base/upsert-strategy.ts +1 -2
- package/src/core/dialect/dialect-factory.ts +17 -49
- package/src/core/dialect/mssql/index.ts +56 -27
- package/src/core/dialect/mysql/index.ts +69 -36
- package/src/core/dialect/postgres/index.ts +71 -43
- package/src/core/dialect/sqlite/index.ts +68 -38
- package/src/index.ts +1 -1
- package/src/core/dialect/base/sql-dialect.ts +0 -217
package/dist/index.cjs
CHANGED
|
@@ -74,7 +74,6 @@ __export(index_exports, {
|
|
|
74
74
|
DefaultMorphToReference: () => DefaultMorphToReference,
|
|
75
75
|
DefaultTypeStrategy: () => DefaultTypeStrategy,
|
|
76
76
|
DeleteQueryBuilder: () => DeleteQueryBuilder,
|
|
77
|
-
DialectBase: () => DialectBase,
|
|
78
77
|
DialectFactory: () => DialectFactory,
|
|
79
78
|
DomainEventBus: () => DomainEventBus,
|
|
80
79
|
Email: () => Email,
|
|
@@ -120,7 +119,6 @@ __export(index_exports, {
|
|
|
120
119
|
RelationKinds: () => RelationKinds,
|
|
121
120
|
STANDARD_COLUMN_TYPES: () => STANDARD_COLUMN_TYPES,
|
|
122
121
|
SelectQueryBuilder: () => SelectQueryBuilder,
|
|
123
|
-
SqlDialectBase: () => SqlDialectBase,
|
|
124
122
|
SqlServerDialect: () => SqlServerDialect,
|
|
125
123
|
SqliteDialect: () => SqliteDialect,
|
|
126
124
|
SqliteReturningStrategy: () => SqliteReturningStrategy,
|
|
@@ -202,6 +200,7 @@ __export(index_exports, {
|
|
|
202
200
|
columnToOpenApiSchema: () => columnToOpenApiSchema,
|
|
203
201
|
columnTypeToOpenApiFormat: () => columnTypeToOpenApiFormat,
|
|
204
202
|
columnTypeToOpenApiType: () => columnTypeToOpenApiType,
|
|
203
|
+
composeSqlDialect: () => composeSqlDialect,
|
|
205
204
|
computePaginationMetadata: () => computePaginationMetadata,
|
|
206
205
|
computeSchemaHash: () => computeSchemaHash,
|
|
207
206
|
concat: () => concat,
|
|
@@ -221,11 +220,16 @@ __export(index_exports, {
|
|
|
221
220
|
createExecutorFromQueryRunner: () => createExecutorFromQueryRunner,
|
|
222
221
|
createMssqlCompilerSet: () => createMssqlCompilerSet,
|
|
223
222
|
createMssqlExecutor: () => createMssqlExecutor,
|
|
223
|
+
createMySqlDialect: () => createMySqlDialect,
|
|
224
224
|
createMysqlExecutor: () => createMysqlExecutor,
|
|
225
225
|
createPooledExecutorFactory: () => createPooledExecutorFactory,
|
|
226
|
+
createPostgresDialect: () => createPostgresDialect,
|
|
226
227
|
createPostgresExecutor: () => createPostgresExecutor,
|
|
227
228
|
createQueryLoggingExecutor: () => createQueryLoggingExecutor,
|
|
228
229
|
createRef: () => createRef,
|
|
230
|
+
createSqlDialect: () => createSqlDialect,
|
|
231
|
+
createSqlServerDialect: () => createSqlServerDialect,
|
|
232
|
+
createSqliteDialect: () => createSqliteDialect,
|
|
229
233
|
createSqliteExecutor: () => createSqliteExecutor,
|
|
230
234
|
createTediousExecutor: () => createTediousExecutor,
|
|
231
235
|
createTediousMssqlClient: () => createTediousMssqlClient,
|
|
@@ -2004,159 +2008,6 @@ var SelectAstNormalizer = class {
|
|
|
2004
2008
|
}
|
|
2005
2009
|
};
|
|
2006
2010
|
|
|
2007
|
-
// src/core/dialect/abstract.ts
|
|
2008
|
-
var DialectBase = class _DialectBase {
|
|
2009
|
-
expressionCompilerRegistry;
|
|
2010
|
-
selectAstNormalizer;
|
|
2011
|
-
functionStrategy;
|
|
2012
|
-
tableFunctionStrategy;
|
|
2013
|
-
constructor(functionStrategy, tableFunctionStrategy) {
|
|
2014
|
-
this.functionStrategy = functionStrategy ?? new StandardFunctionStrategy();
|
|
2015
|
-
this.tableFunctionStrategy = tableFunctionStrategy ?? new StandardTableFunctionStrategy();
|
|
2016
|
-
this.selectAstNormalizer = new SelectAstNormalizer((kind) => this.supportsSetOperation(kind));
|
|
2017
|
-
this.expressionCompilerRegistry = new ExpressionCompilerRegistry({
|
|
2018
|
-
quoteIdentifier: (id) => this.quoteIdentifier(id),
|
|
2019
|
-
compileSelectAst: (ast, ctx) => this.compileSelectAst(ast, ctx),
|
|
2020
|
-
compileSelectForExists: (ast, ctx) => this.compileSelectForExists(ast, ctx),
|
|
2021
|
-
compileJsonPath: (node) => this.compileJsonPath(node),
|
|
2022
|
-
compileFunctionOperand: (node, ctx) => this.compileFunctionOperand(node, ctx),
|
|
2023
|
-
describe: () => this.constructor.name
|
|
2024
|
-
});
|
|
2025
|
-
}
|
|
2026
|
-
compileSelect(ast) {
|
|
2027
|
-
const ctx = this.createCompilerContext();
|
|
2028
|
-
const normalized = this.normalizeSelectAst(ast);
|
|
2029
|
-
const rawSql = this.compileSelectAst(normalized, ctx).trim();
|
|
2030
|
-
return {
|
|
2031
|
-
sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
|
|
2032
|
-
params: [...ctx.params]
|
|
2033
|
-
};
|
|
2034
|
-
}
|
|
2035
|
-
compileInsert(ast) {
|
|
2036
|
-
const ctx = this.createCompilerContext();
|
|
2037
|
-
const rawSql = this.compileInsertAst(ast, ctx).trim();
|
|
2038
|
-
return {
|
|
2039
|
-
sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
|
|
2040
|
-
params: [...ctx.params]
|
|
2041
|
-
};
|
|
2042
|
-
}
|
|
2043
|
-
compileUpdate(ast) {
|
|
2044
|
-
const ctx = this.createCompilerContext();
|
|
2045
|
-
const rawSql = this.compileUpdateAst(ast, ctx).trim();
|
|
2046
|
-
return {
|
|
2047
|
-
sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
|
|
2048
|
-
params: [...ctx.params]
|
|
2049
|
-
};
|
|
2050
|
-
}
|
|
2051
|
-
compileDelete(ast) {
|
|
2052
|
-
const ctx = this.createCompilerContext();
|
|
2053
|
-
const rawSql = this.compileDeleteAst(ast, ctx).trim();
|
|
2054
|
-
return {
|
|
2055
|
-
sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
|
|
2056
|
-
params: [...ctx.params]
|
|
2057
|
-
};
|
|
2058
|
-
}
|
|
2059
|
-
supportsDmlReturningClause() {
|
|
2060
|
-
return false;
|
|
2061
|
-
}
|
|
2062
|
-
compileWhere(where, ctx) {
|
|
2063
|
-
if (!where) return "";
|
|
2064
|
-
return ` WHERE ${this.compileExpression(where, ctx)}`;
|
|
2065
|
-
}
|
|
2066
|
-
compileReturning(returning, _ctx) {
|
|
2067
|
-
void _ctx;
|
|
2068
|
-
if (!returning || returning.length === 0) return "";
|
|
2069
|
-
throw new Error("RETURNING is not supported by this dialect.");
|
|
2070
|
-
}
|
|
2071
|
-
compileSelectForExists(ast, ctx) {
|
|
2072
|
-
const normalized = this.normalizeSelectAst(ast);
|
|
2073
|
-
const full = this.compileSelectAst(normalized, ctx).trim().replace(/;$/, "");
|
|
2074
|
-
if (normalized.setOps && normalized.setOps.length > 0) {
|
|
2075
|
-
return `SELECT 1 FROM (${full}) AS _exists`;
|
|
2076
|
-
}
|
|
2077
|
-
const upper2 = full.toUpperCase();
|
|
2078
|
-
const fromIndex = upper2.indexOf(" FROM ");
|
|
2079
|
-
if (fromIndex === -1) return full;
|
|
2080
|
-
return `SELECT 1${full.slice(fromIndex)}`;
|
|
2081
|
-
}
|
|
2082
|
-
createCompilerContext() {
|
|
2083
|
-
const params = [];
|
|
2084
|
-
let counter = 0;
|
|
2085
|
-
return {
|
|
2086
|
-
params,
|
|
2087
|
-
addParameter: (value) => {
|
|
2088
|
-
counter += 1;
|
|
2089
|
-
params.push(value);
|
|
2090
|
-
return this.formatPlaceholder(counter);
|
|
2091
|
-
}
|
|
2092
|
-
};
|
|
2093
|
-
}
|
|
2094
|
-
formatPlaceholder(_index) {
|
|
2095
|
-
void _index;
|
|
2096
|
-
return "?";
|
|
2097
|
-
}
|
|
2098
|
-
supportsSetOperation(_kind) {
|
|
2099
|
-
void _kind;
|
|
2100
|
-
return true;
|
|
2101
|
-
}
|
|
2102
|
-
normalizeSelectAst(ast) {
|
|
2103
|
-
return this.selectAstNormalizer.normalize(ast);
|
|
2104
|
-
}
|
|
2105
|
-
registerExpressionCompiler(type, compiler) {
|
|
2106
|
-
this.expressionCompilerRegistry.registerExpressionCompiler(type, compiler);
|
|
2107
|
-
}
|
|
2108
|
-
registerOperandCompiler(type, compiler) {
|
|
2109
|
-
this.expressionCompilerRegistry.registerOperandCompiler(type, compiler);
|
|
2110
|
-
}
|
|
2111
|
-
compileExpression(node, ctx) {
|
|
2112
|
-
return this.expressionCompilerRegistry.compileExpression(node, ctx);
|
|
2113
|
-
}
|
|
2114
|
-
compileOperand(node, ctx) {
|
|
2115
|
-
return this.expressionCompilerRegistry.compileOperand(node, ctx);
|
|
2116
|
-
}
|
|
2117
|
-
compileOrderingTerm(term, ctx) {
|
|
2118
|
-
return this.expressionCompilerRegistry.compileOrderingTerm(term, ctx);
|
|
2119
|
-
}
|
|
2120
|
-
compileJsonPath(_node) {
|
|
2121
|
-
void _node;
|
|
2122
|
-
throw new Error("JSON Path not supported by this dialect");
|
|
2123
|
-
}
|
|
2124
|
-
compileFunctionOperand(fnNode, ctx) {
|
|
2125
|
-
const compiledArgs = fnNode.args.map((arg) => this.compileOperand(arg, ctx));
|
|
2126
|
-
const renderer = this.functionStrategy.getRenderer(fnNode.name);
|
|
2127
|
-
if (renderer) {
|
|
2128
|
-
return renderer({
|
|
2129
|
-
node: fnNode,
|
|
2130
|
-
compiledArgs,
|
|
2131
|
-
compileOperand: (operand) => this.compileOperand(operand, ctx)
|
|
2132
|
-
});
|
|
2133
|
-
}
|
|
2134
|
-
return `${fnNode.name}(${compiledArgs.join(", ")})`;
|
|
2135
|
-
}
|
|
2136
|
-
/** Creates a minimal dialect implementation for isolated compiler tests. */
|
|
2137
|
-
static create(functionStrategy, tableFunctionStrategy) {
|
|
2138
|
-
class TestDialect extends _DialectBase {
|
|
2139
|
-
dialect = "sqlite";
|
|
2140
|
-
quoteIdentifier(id) {
|
|
2141
|
-
return `"${id}"`;
|
|
2142
|
-
}
|
|
2143
|
-
compileSelectAst() {
|
|
2144
|
-
throw new Error("Not implemented");
|
|
2145
|
-
}
|
|
2146
|
-
compileInsertAst() {
|
|
2147
|
-
throw new Error("Not implemented");
|
|
2148
|
-
}
|
|
2149
|
-
compileUpdateAst() {
|
|
2150
|
-
throw new Error("Not implemented");
|
|
2151
|
-
}
|
|
2152
|
-
compileDeleteAst() {
|
|
2153
|
-
throw new Error("Not implemented");
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
|
-
return new TestDialect(functionStrategy, tableFunctionStrategy);
|
|
2157
|
-
}
|
|
2158
|
-
};
|
|
2159
|
-
|
|
2160
2011
|
// src/core/dialect/base/pagination-strategy.ts
|
|
2161
2012
|
var StandardLimitOffsetPagination = class {
|
|
2162
2013
|
/**
|
|
@@ -2181,19 +2032,19 @@ var NoReturningStrategy = class {
|
|
|
2181
2032
|
if (!returning || returning.length === 0) return "";
|
|
2182
2033
|
throw new Error("RETURNING is not supported by this dialect.");
|
|
2183
2034
|
}
|
|
2184
|
-
formatReturningColumns(returning,
|
|
2035
|
+
formatReturningColumns(returning, quoteIdentifier5) {
|
|
2185
2036
|
return returning.map((column) => {
|
|
2186
|
-
const tablePart = column.table ? `${
|
|
2187
|
-
const aliasPart = column.alias ? ` AS ${
|
|
2188
|
-
return `${tablePart}${
|
|
2037
|
+
const tablePart = column.table ? `${quoteIdentifier5(column.table)}.` : "";
|
|
2038
|
+
const aliasPart = column.alias ? ` AS ${quoteIdentifier5(column.alias)}` : "";
|
|
2039
|
+
return `${tablePart}${quoteIdentifier5(column.name)}${aliasPart}`;
|
|
2189
2040
|
}).join(", ");
|
|
2190
2041
|
}
|
|
2191
2042
|
};
|
|
2192
2043
|
var StandardReturningStrategy = class extends NoReturningStrategy {
|
|
2193
|
-
compileReturning(returning, _ctx,
|
|
2044
|
+
compileReturning(returning, _ctx, quoteIdentifier5) {
|
|
2194
2045
|
void _ctx;
|
|
2195
2046
|
if (!returning || returning.length === 0) return "";
|
|
2196
|
-
return ` RETURNING ${this.formatReturningColumns(returning,
|
|
2047
|
+
return ` RETURNING ${this.formatReturningColumns(returning, quoteIdentifier5)}`;
|
|
2197
2048
|
}
|
|
2198
2049
|
};
|
|
2199
2050
|
|
|
@@ -2324,13 +2175,13 @@ var CteCompiler = class {
|
|
|
2324
2175
|
* @param stripTrailingSemicolon - Function to remove trailing semicolons from SQL.
|
|
2325
2176
|
* @returns SQL WITH clause string (e.g., "WITH cte_name AS (...) ") or empty string if no CTEs.
|
|
2326
2177
|
*/
|
|
2327
|
-
static compileCtes(ast, ctx,
|
|
2178
|
+
static compileCtes(ast, ctx, quoteIdentifier5, compileSelectAst, normalizeSelectAst, stripTrailingSemicolon) {
|
|
2328
2179
|
if (!ast.ctes || ast.ctes.length === 0) return "";
|
|
2329
2180
|
const hasRecursive = ast.ctes.some((cte) => cte.recursive);
|
|
2330
2181
|
const prefix = hasRecursive ? "WITH RECURSIVE " : "WITH ";
|
|
2331
2182
|
const cteDefs = ast.ctes.map((cte) => {
|
|
2332
|
-
const name =
|
|
2333
|
-
const cols = cte.columns && cte.columns.length ? `(${cte.columns.map((c) =>
|
|
2183
|
+
const name = quoteIdentifier5(cte.name);
|
|
2184
|
+
const cols = cte.columns && cte.columns.length ? `(${cte.columns.map((c) => quoteIdentifier5(c)).join(", ")})` : "";
|
|
2334
2185
|
const query = stripTrailingSemicolon(compileSelectAst(normalizeSelectAst(cte.query), ctx));
|
|
2335
2186
|
return `${name}${cols} AS (${query})`;
|
|
2336
2187
|
}).join(", ");
|
|
@@ -2553,138 +2404,174 @@ var StandardDeleteCompiler = class {
|
|
|
2553
2404
|
}
|
|
2554
2405
|
};
|
|
2555
2406
|
|
|
2556
|
-
// src/core/dialect/base/sql-dialect.ts
|
|
2557
|
-
var
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
compileUpsertClause: (ast, ctx) => this.compileUpsertClause(ast, ctx),
|
|
2583
|
-
compileSetTarget: (column, table) => this.compileSetTarget(column, table),
|
|
2584
|
-
renderOrderByNulls: (order) => this.renderOrderByNulls(order),
|
|
2585
|
-
renderOrderByCollation: (order) => this.renderOrderByCollation(order)
|
|
2586
|
-
};
|
|
2587
|
-
this.sourceCompiler = new StandardSqlSourceCompiler(services);
|
|
2588
|
-
const standardSelect = new StandardSelectCompiler(services, this.sourceCompiler);
|
|
2589
|
-
const standardInsert = new StandardInsertCompiler(services, this.sourceCompiler);
|
|
2590
|
-
this.standardUpdateCompiler = new StandardUpdateCompiler(services, this.sourceCompiler);
|
|
2591
|
-
const standardDelete = new StandardDeleteCompiler(services, this.sourceCompiler);
|
|
2592
|
-
const overrides = options.compilerFactory?.({
|
|
2593
|
-
services,
|
|
2594
|
-
sources: this.sourceCompiler
|
|
2595
|
-
}) ?? {};
|
|
2596
|
-
this.compilerSet = {
|
|
2597
|
-
select: overrides.select ?? standardSelect,
|
|
2598
|
-
insert: overrides.insert ?? standardInsert,
|
|
2599
|
-
update: overrides.update ?? this.standardUpdateCompiler,
|
|
2600
|
-
delete: overrides.delete ?? standardDelete
|
|
2407
|
+
// src/core/dialect/base/sql-dialect-composer.ts
|
|
2408
|
+
var terminate = (sql) => {
|
|
2409
|
+
const trimmed = sql.trim();
|
|
2410
|
+
return trimmed.endsWith(";") ? trimmed : `${trimmed};`;
|
|
2411
|
+
};
|
|
2412
|
+
var composeSqlDialect = (config) => {
|
|
2413
|
+
const functionStrategy = config.functionStrategy ?? new StandardFunctionStrategy();
|
|
2414
|
+
const tableFunctionStrategy = config.tableFunctionStrategy ?? new StandardTableFunctionStrategy();
|
|
2415
|
+
const paginationStrategy = config.paginationStrategy ?? new StandardLimitOffsetPagination();
|
|
2416
|
+
const returningStrategy = config.returningStrategy ?? new NoReturningStrategy();
|
|
2417
|
+
const upsertStrategy = config.upsertStrategy ?? new NoUpsertStrategy();
|
|
2418
|
+
const selectAstNormalizer = new SelectAstNormalizer(
|
|
2419
|
+
(kind) => config.supportsSetOperation?.(kind) ?? true
|
|
2420
|
+
);
|
|
2421
|
+
let compilerSet;
|
|
2422
|
+
let expressionRegistry2;
|
|
2423
|
+
const createCompilerContext = () => {
|
|
2424
|
+
const params = [];
|
|
2425
|
+
let counter = 0;
|
|
2426
|
+
return {
|
|
2427
|
+
params,
|
|
2428
|
+
addParameter(value) {
|
|
2429
|
+
counter += 1;
|
|
2430
|
+
params.push(value);
|
|
2431
|
+
return config.formatPlaceholder?.(counter) ?? "?";
|
|
2432
|
+
}
|
|
2601
2433
|
};
|
|
2602
|
-
}
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
}
|
|
2640
|
-
compileSetTarget(column, table) {
|
|
2641
|
-
return
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
}
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
}
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2434
|
+
};
|
|
2435
|
+
const compileSelectAst = (ast, ctx) => compilerSet.select.compile(ast, ctx);
|
|
2436
|
+
const normalizeSelectAst = (ast) => selectAstNormalizer.normalize(ast);
|
|
2437
|
+
const compileSelectForExists = (ast, ctx) => {
|
|
2438
|
+
const normalized = normalizeSelectAst(ast);
|
|
2439
|
+
const full = compileSelectAst(normalized, ctx).trim().replace(/;$/, "");
|
|
2440
|
+
if (normalized.setOps && normalized.setOps.length > 0) {
|
|
2441
|
+
return `SELECT 1 FROM (${full}) AS _exists`;
|
|
2442
|
+
}
|
|
2443
|
+
const fromIndex = full.toUpperCase().indexOf(" FROM ");
|
|
2444
|
+
return fromIndex === -1 ? full : `SELECT 1${full.slice(fromIndex)}`;
|
|
2445
|
+
};
|
|
2446
|
+
const compileJsonPath = (node) => {
|
|
2447
|
+
if (!config.compileJsonPath) {
|
|
2448
|
+
throw new Error(`JSON Path not supported by dialect "${config.name}".`);
|
|
2449
|
+
}
|
|
2450
|
+
return config.compileJsonPath(node);
|
|
2451
|
+
};
|
|
2452
|
+
const compileFunctionOperand = (node, ctx) => {
|
|
2453
|
+
const compiledArgs = node.args.map((arg) => expressionRegistry2.compileOperand(arg, ctx));
|
|
2454
|
+
const renderer = functionStrategy.getRenderer(node.name);
|
|
2455
|
+
if (renderer) {
|
|
2456
|
+
return renderer({
|
|
2457
|
+
node,
|
|
2458
|
+
compiledArgs,
|
|
2459
|
+
compileOperand: (operand) => expressionRegistry2.compileOperand(operand, ctx)
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
return `${node.name}(${compiledArgs.join(", ")})`;
|
|
2463
|
+
};
|
|
2464
|
+
expressionRegistry2 = new ExpressionCompilerRegistry({
|
|
2465
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
2466
|
+
compileSelectAst,
|
|
2467
|
+
compileSelectForExists,
|
|
2468
|
+
compileJsonPath,
|
|
2469
|
+
compileFunctionOperand,
|
|
2470
|
+
describe: () => config.describe ?? config.name
|
|
2471
|
+
});
|
|
2472
|
+
const compileSetTarget = (column, table) => {
|
|
2473
|
+
if (config.compileSetTarget) return config.compileSetTarget(column, table);
|
|
2474
|
+
const columnTable = column.table ?? table.alias ?? table.name;
|
|
2475
|
+
const tableQualifier = table.alias && column.table === table.name ? table.alias : columnTable;
|
|
2476
|
+
return tableQualifier ? `${config.quoteIdentifier(tableQualifier)}.${config.quoteIdentifier(column.name)}` : config.quoteIdentifier(column.name);
|
|
2477
|
+
};
|
|
2478
|
+
let standardUpdate;
|
|
2479
|
+
const services = {
|
|
2480
|
+
getDialectName: () => config.name,
|
|
2481
|
+
getPaginationStrategy: () => paginationStrategy,
|
|
2482
|
+
getTableFunctionStrategy: () => tableFunctionStrategy,
|
|
2483
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
2484
|
+
compileOperand: (node, ctx) => expressionRegistry2.compileOperand(node, ctx),
|
|
2485
|
+
compileExpression: (node, ctx) => expressionRegistry2.compileExpression(node, ctx),
|
|
2486
|
+
compileOrderingTerm: (term, ctx) => expressionRegistry2.compileOrderingTerm(term, ctx),
|
|
2487
|
+
normalizeSelectAst,
|
|
2488
|
+
compileSelectAst,
|
|
2489
|
+
compileReturning: (returning, ctx) => returningStrategy.compileReturning(returning, ctx, config.quoteIdentifier),
|
|
2490
|
+
compileUpsertClause: (ast, ctx) => upsertStrategy.compile(ast, ctx, {
|
|
2491
|
+
getDialectName: () => config.name,
|
|
2492
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
2493
|
+
compileOperand: (node, compilerContext) => expressionRegistry2.compileOperand(node, compilerContext),
|
|
2494
|
+
compileExpression: (node, compilerContext) => expressionRegistry2.compileExpression(node, compilerContext),
|
|
2495
|
+
compileUpdateAssignments: (assignments, table, compilerContext) => standardUpdate.compileAssignments(assignments, table, compilerContext)
|
|
2496
|
+
}),
|
|
2497
|
+
compileSetTarget,
|
|
2498
|
+
renderOrderByNulls: (order) => config.renderOrderByNulls?.(order) ?? (order.nulls ? ` NULLS ${order.nulls}` : ""),
|
|
2499
|
+
renderOrderByCollation: (order) => config.renderOrderByCollation?.(order) ?? (order.collation ? ` COLLATE ${order.collation}` : "")
|
|
2500
|
+
};
|
|
2501
|
+
const sources = new StandardSqlSourceCompiler(services);
|
|
2502
|
+
const standardSelect = new StandardSelectCompiler(services, sources);
|
|
2503
|
+
const standardInsert = new StandardInsertCompiler(services, sources);
|
|
2504
|
+
standardUpdate = new StandardUpdateCompiler(services, sources);
|
|
2505
|
+
const standardDelete = new StandardDeleteCompiler(services, sources);
|
|
2506
|
+
const overrides = config.compilerFactory?.({ services, sources }) ?? {};
|
|
2507
|
+
compilerSet = {
|
|
2508
|
+
select: overrides.select ?? standardSelect,
|
|
2509
|
+
insert: overrides.insert ?? standardInsert,
|
|
2510
|
+
update: overrides.update ?? standardUpdate,
|
|
2511
|
+
delete: overrides.delete ?? standardDelete
|
|
2512
|
+
};
|
|
2513
|
+
const expressionApi = {
|
|
2514
|
+
registerExpressionCompiler(type, compiler) {
|
|
2515
|
+
expressionRegistry2.registerExpressionCompiler(type, compiler);
|
|
2516
|
+
},
|
|
2517
|
+
registerOperandCompiler(type, compiler) {
|
|
2518
|
+
expressionRegistry2.registerOperandCompiler(type, compiler);
|
|
2519
|
+
},
|
|
2520
|
+
compileExpression(node, ctx) {
|
|
2521
|
+
return expressionRegistry2.compileExpression(node, ctx);
|
|
2522
|
+
},
|
|
2523
|
+
compileOperand(node, ctx) {
|
|
2524
|
+
return expressionRegistry2.compileOperand(node, ctx);
|
|
2525
|
+
},
|
|
2526
|
+
compileOrderingTerm(term, ctx) {
|
|
2527
|
+
return expressionRegistry2.compileOrderingTerm(term, ctx);
|
|
2528
|
+
}
|
|
2529
|
+
};
|
|
2530
|
+
config.configureExpressions?.(expressionApi);
|
|
2531
|
+
const dialect = {
|
|
2532
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
2533
|
+
supportsDmlReturningClause: () => config.supportsDmlReturning ?? false,
|
|
2534
|
+
compileSelect(ast) {
|
|
2535
|
+
const ctx = createCompilerContext();
|
|
2536
|
+
return {
|
|
2537
|
+
sql: terminate(compileSelectAst(normalizeSelectAst(ast), ctx)),
|
|
2538
|
+
params: [...ctx.params]
|
|
2539
|
+
};
|
|
2540
|
+
},
|
|
2541
|
+
compileInsert(ast) {
|
|
2542
|
+
const ctx = createCompilerContext();
|
|
2543
|
+
return {
|
|
2544
|
+
sql: terminate(compilerSet.insert.compile(ast, ctx)),
|
|
2545
|
+
params: [...ctx.params]
|
|
2546
|
+
};
|
|
2547
|
+
},
|
|
2548
|
+
compileUpdate(ast) {
|
|
2549
|
+
const ctx = createCompilerContext();
|
|
2550
|
+
return {
|
|
2551
|
+
sql: terminate(compilerSet.update.compile(ast, ctx)),
|
|
2552
|
+
params: [...ctx.params]
|
|
2553
|
+
};
|
|
2554
|
+
},
|
|
2555
|
+
compileDelete(ast) {
|
|
2556
|
+
const ctx = createCompilerContext();
|
|
2557
|
+
return {
|
|
2558
|
+
sql: terminate(compilerSet.delete.compile(ast, ctx)),
|
|
2559
|
+
params: [...ctx.params]
|
|
2560
|
+
};
|
|
2561
|
+
}
|
|
2562
|
+
};
|
|
2563
|
+
const runtime = {
|
|
2564
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
2565
|
+
createCompilerContext,
|
|
2566
|
+
compileOperand: (node, ctx) => expressionRegistry2.compileOperand(node, ctx),
|
|
2567
|
+
compileExpression: (node, ctx) => expressionRegistry2.compileExpression(node, ctx),
|
|
2568
|
+
compileOrderingTerm: (term, ctx) => expressionRegistry2.compileOrderingTerm(term, ctx),
|
|
2569
|
+
normalizeSelectAst,
|
|
2570
|
+
compileSelectAst
|
|
2571
|
+
};
|
|
2572
|
+
return { dialect, runtime };
|
|
2687
2573
|
};
|
|
2574
|
+
var createSqlDialect = (config) => composeSqlDialect(config).dialect;
|
|
2688
2575
|
|
|
2689
2576
|
// src/core/dialect/postgres/functions.ts
|
|
2690
2577
|
var PostgresFunctionStrategy = class extends StandardFunctionStrategy {
|
|
@@ -2847,15 +2734,15 @@ var PostgresTableFunctionStrategy = class extends StandardTableFunctionStrategy
|
|
|
2847
2734
|
this.registerOverrides();
|
|
2848
2735
|
}
|
|
2849
2736
|
registerOverrides() {
|
|
2850
|
-
this.add("ARRAY_UNNEST", ({ node, compiledArgs, quoteIdentifier }) => {
|
|
2737
|
+
this.add("ARRAY_UNNEST", ({ node, compiledArgs, quoteIdentifier: quoteIdentifier5 }) => {
|
|
2851
2738
|
const lateral = node.lateral ?? true;
|
|
2852
2739
|
const withOrd = node.withOrdinality ?? false;
|
|
2853
2740
|
const base = `unnest(${compiledArgs.join(", ")})${withOrd ? " WITH ORDINALITY" : ""}`;
|
|
2854
2741
|
if (node.columnAliases?.length && !node.alias) {
|
|
2855
2742
|
throw new Error("tvf(ARRAY_UNNEST) with columnAliases requires an alias.");
|
|
2856
2743
|
}
|
|
2857
|
-
const alias = node.alias ? ` AS ${
|
|
2858
|
-
const cols = node.columnAliases?.length ? `(${node.columnAliases.map(
|
|
2744
|
+
const alias = node.alias ? ` AS ${quoteIdentifier5(node.alias)}` : "";
|
|
2745
|
+
const cols = node.columnAliases?.length ? `(${node.columnAliases.map(quoteIdentifier5).join(", ")})` : "";
|
|
2859
2746
|
return `${lateral ? "LATERAL " : ""}${base}${alias}${cols}`;
|
|
2860
2747
|
});
|
|
2861
2748
|
}
|
|
@@ -2920,52 +2807,68 @@ var PostgresUpsertStrategy = class {
|
|
|
2920
2807
|
};
|
|
2921
2808
|
|
|
2922
2809
|
// src/core/dialect/postgres/index.ts
|
|
2923
|
-
var
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2810
|
+
var quoteIdentifier = (id) => `"${id}"`;
|
|
2811
|
+
var createPostgresDialect = () => {
|
|
2812
|
+
const composition = composeSqlDialect({
|
|
2813
|
+
name: "postgres",
|
|
2814
|
+
quoteIdentifier,
|
|
2815
|
+
formatPlaceholder: (index) => `$${index}`,
|
|
2816
|
+
functionStrategy: new PostgresFunctionStrategy(),
|
|
2817
|
+
tableFunctionStrategy: new PostgresTableFunctionStrategy(),
|
|
2818
|
+
returningStrategy: new PostgresReturningStrategy(),
|
|
2819
|
+
upsertStrategy: new PostgresUpsertStrategy(),
|
|
2820
|
+
supportsDmlReturning: true,
|
|
2821
|
+
compileSetTarget: (column, _table) => {
|
|
2822
|
+
void _table;
|
|
2823
|
+
return quoteIdentifier(column.name);
|
|
2824
|
+
},
|
|
2825
|
+
compileJsonPath(node) {
|
|
2826
|
+
const column = `${quoteIdentifier(node.column.table)}.${quoteIdentifier(node.column.name)}`;
|
|
2827
|
+
return `${column}->>'${node.path}'`;
|
|
2828
|
+
},
|
|
2829
|
+
configureExpressions(api) {
|
|
2830
|
+
api.registerExpressionCompiler("BitwiseExpression", (node, ctx) => {
|
|
2831
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
2832
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
2833
|
+
const operator = node.operator === "^" ? "#" : node.operator;
|
|
2834
|
+
return `${left2} ${operator} ${right2}`;
|
|
2835
|
+
});
|
|
2836
|
+
api.registerOperandCompiler("BitwiseExpression", (node, ctx) => {
|
|
2837
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
2838
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
2839
|
+
const operator = node.operator === "^" ? "#" : node.operator;
|
|
2840
|
+
return `(${left2} ${operator} ${right2})`;
|
|
2841
|
+
});
|
|
2842
|
+
}
|
|
2843
|
+
});
|
|
2844
|
+
const procedures = new PostgresProcedureCompiler(composition.runtime);
|
|
2845
|
+
return {
|
|
2846
|
+
...composition.dialect,
|
|
2847
|
+
compileProcedureCall: (ast) => procedures.compileProcedureCall(ast)
|
|
2848
|
+
};
|
|
2849
|
+
};
|
|
2850
|
+
var PostgresDialect = class {
|
|
2851
|
+
impl = createPostgresDialect();
|
|
2952
2852
|
quoteIdentifier(id) {
|
|
2953
|
-
return
|
|
2853
|
+
return this.impl.quoteIdentifier(id);
|
|
2954
2854
|
}
|
|
2955
|
-
|
|
2956
|
-
return
|
|
2855
|
+
supportsDmlReturningClause() {
|
|
2856
|
+
return this.impl.supportsDmlReturningClause();
|
|
2957
2857
|
}
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
return `${column}->>'${node.path}'`;
|
|
2858
|
+
compileSelect(ast) {
|
|
2859
|
+
return this.impl.compileSelect(ast);
|
|
2961
2860
|
}
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2861
|
+
compileInsert(ast) {
|
|
2862
|
+
return this.impl.compileInsert(ast);
|
|
2863
|
+
}
|
|
2864
|
+
compileUpdate(ast) {
|
|
2865
|
+
return this.impl.compileUpdate(ast);
|
|
2866
|
+
}
|
|
2867
|
+
compileDelete(ast) {
|
|
2868
|
+
return this.impl.compileDelete(ast);
|
|
2966
2869
|
}
|
|
2967
2870
|
compileProcedureCall(ast) {
|
|
2968
|
-
return this.
|
|
2871
|
+
return this.impl.compileProcedureCall(ast);
|
|
2969
2872
|
}
|
|
2970
2873
|
};
|
|
2971
2874
|
|
|
@@ -3145,38 +3048,57 @@ var MySqlUpsertStrategy = class {
|
|
|
3145
3048
|
};
|
|
3146
3049
|
|
|
3147
3050
|
// src/core/dialect/mysql/index.ts
|
|
3148
|
-
var
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
}
|
|
3051
|
+
var quoteIdentifier2 = (id) => `\`${id}\``;
|
|
3052
|
+
var createMySqlDialect = () => {
|
|
3053
|
+
const composition = composeSqlDialect({
|
|
3054
|
+
name: "mysql",
|
|
3055
|
+
quoteIdentifier: quoteIdentifier2,
|
|
3056
|
+
functionStrategy: new MysqlFunctionStrategy(),
|
|
3057
|
+
upsertStrategy: new MySqlUpsertStrategy(),
|
|
3058
|
+
compileJsonPath(node) {
|
|
3059
|
+
const column = `${quoteIdentifier2(node.column.table)}.${quoteIdentifier2(node.column.name)}`;
|
|
3060
|
+
return `${column}->'${node.path}'`;
|
|
3061
|
+
},
|
|
3062
|
+
configureExpressions(api) {
|
|
3063
|
+
api.registerExpressionCompiler(
|
|
3064
|
+
"IsDistinctExpression",
|
|
3065
|
+
(node, ctx) => {
|
|
3066
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
3067
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
3068
|
+
const spaceship = `${left2} <=> ${right2}`;
|
|
3069
|
+
return node.operator === "IS NOT DISTINCT FROM" ? spaceship : `NOT (${spaceship})`;
|
|
3070
|
+
}
|
|
3071
|
+
);
|
|
3072
|
+
}
|
|
3073
|
+
});
|
|
3074
|
+
const procedures = new MySqlProcedureCompiler(composition.runtime);
|
|
3075
|
+
return {
|
|
3076
|
+
...composition.dialect,
|
|
3077
|
+
compileProcedureCall: (ast) => procedures.compileProcedureCall(ast)
|
|
3078
|
+
};
|
|
3079
|
+
};
|
|
3080
|
+
var MySqlDialect = class {
|
|
3081
|
+
impl = createMySqlDialect();
|
|
3171
3082
|
quoteIdentifier(id) {
|
|
3172
|
-
return
|
|
3083
|
+
return this.impl.quoteIdentifier(id);
|
|
3173
3084
|
}
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3085
|
+
supportsDmlReturningClause() {
|
|
3086
|
+
return this.impl.supportsDmlReturningClause();
|
|
3087
|
+
}
|
|
3088
|
+
compileSelect(ast) {
|
|
3089
|
+
return this.impl.compileSelect(ast);
|
|
3090
|
+
}
|
|
3091
|
+
compileInsert(ast) {
|
|
3092
|
+
return this.impl.compileInsert(ast);
|
|
3093
|
+
}
|
|
3094
|
+
compileUpdate(ast) {
|
|
3095
|
+
return this.impl.compileUpdate(ast);
|
|
3096
|
+
}
|
|
3097
|
+
compileDelete(ast) {
|
|
3098
|
+
return this.impl.compileDelete(ast);
|
|
3177
3099
|
}
|
|
3178
3100
|
compileProcedureCall(ast) {
|
|
3179
|
-
return this.
|
|
3101
|
+
return this.impl.compileProcedureCall(ast);
|
|
3180
3102
|
}
|
|
3181
3103
|
};
|
|
3182
3104
|
|
|
@@ -3319,15 +3241,15 @@ var SqliteFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
3319
3241
|
|
|
3320
3242
|
// src/core/dialect/sqlite/returning.ts
|
|
3321
3243
|
var SqliteReturningStrategy = class {
|
|
3322
|
-
compileReturning(returning, _ctx,
|
|
3244
|
+
compileReturning(returning, _ctx, quoteIdentifier5) {
|
|
3323
3245
|
void _ctx;
|
|
3324
3246
|
if (!returning || returning.length === 0) return "";
|
|
3325
|
-
return ` RETURNING ${this.formatReturningColumns(returning,
|
|
3247
|
+
return ` RETURNING ${this.formatReturningColumns(returning, quoteIdentifier5)}`;
|
|
3326
3248
|
}
|
|
3327
|
-
formatReturningColumns(returning,
|
|
3249
|
+
formatReturningColumns(returning, quoteIdentifier5) {
|
|
3328
3250
|
return returning.map((column) => {
|
|
3329
|
-
const alias = column.alias ? ` AS ${
|
|
3330
|
-
return `${
|
|
3251
|
+
const alias = column.alias ? ` AS ${quoteIdentifier5(column.alias)}` : "";
|
|
3252
|
+
return `${quoteIdentifier5(column.name)}${alias}`;
|
|
3331
3253
|
}).join(", ");
|
|
3332
3254
|
}
|
|
3333
3255
|
};
|
|
@@ -3358,42 +3280,60 @@ var SqliteUpsertStrategy = class {
|
|
|
3358
3280
|
};
|
|
3359
3281
|
|
|
3360
3282
|
// src/core/dialect/sqlite/index.ts
|
|
3361
|
-
var
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3283
|
+
var quoteIdentifier3 = (id) => `"${id}"`;
|
|
3284
|
+
var createSqliteDialect = () => composeSqlDialect({
|
|
3285
|
+
name: "sqlite",
|
|
3286
|
+
quoteIdentifier: quoteIdentifier3,
|
|
3287
|
+
functionStrategy: new SqliteFunctionStrategy(),
|
|
3288
|
+
returningStrategy: new SqliteReturningStrategy(),
|
|
3289
|
+
upsertStrategy: new SqliteUpsertStrategy(),
|
|
3290
|
+
supportsDmlReturning: true,
|
|
3291
|
+
compileSetTarget: (column, _table) => {
|
|
3292
|
+
void _table;
|
|
3293
|
+
return quoteIdentifier3(column.name);
|
|
3294
|
+
},
|
|
3295
|
+
compileJsonPath(node) {
|
|
3296
|
+
const column = `${quoteIdentifier3(node.column.table)}.${quoteIdentifier3(node.column.name)}`;
|
|
3297
|
+
return `json_extract(${column}, '${node.path}')`;
|
|
3298
|
+
},
|
|
3299
|
+
configureExpressions(api) {
|
|
3300
|
+
api.registerExpressionCompiler("BitwiseExpression", (node, ctx) => {
|
|
3301
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
3302
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
3373
3303
|
if (node.operator === "^") {
|
|
3374
3304
|
return `(${left2} | ${right2}) & ~(${left2} & ${right2})`;
|
|
3375
3305
|
}
|
|
3376
3306
|
return `${left2} ${node.operator} ${right2}`;
|
|
3377
3307
|
});
|
|
3378
|
-
|
|
3379
|
-
const left2 =
|
|
3380
|
-
const right2 =
|
|
3308
|
+
api.registerOperandCompiler("BitwiseExpression", (node, ctx) => {
|
|
3309
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
3310
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
3381
3311
|
if (node.operator === "^") {
|
|
3382
3312
|
return `((${left2} | ${right2}) & ~(${left2} & ${right2}))`;
|
|
3383
3313
|
}
|
|
3384
3314
|
return `(${left2} ${node.operator} ${right2})`;
|
|
3385
3315
|
});
|
|
3386
3316
|
}
|
|
3317
|
+
}).dialect;
|
|
3318
|
+
var SqliteDialect = class {
|
|
3319
|
+
impl = createSqliteDialect();
|
|
3387
3320
|
quoteIdentifier(id) {
|
|
3388
|
-
return
|
|
3321
|
+
return this.impl.quoteIdentifier(id);
|
|
3389
3322
|
}
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
return `json_extract(${column}, '${node.path}')`;
|
|
3323
|
+
supportsDmlReturningClause() {
|
|
3324
|
+
return this.impl.supportsDmlReturningClause();
|
|
3393
3325
|
}
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3326
|
+
compileSelect(ast) {
|
|
3327
|
+
return this.impl.compileSelect(ast);
|
|
3328
|
+
}
|
|
3329
|
+
compileInsert(ast) {
|
|
3330
|
+
return this.impl.compileInsert(ast);
|
|
3331
|
+
}
|
|
3332
|
+
compileUpdate(ast) {
|
|
3333
|
+
return this.impl.compileUpdate(ast);
|
|
3334
|
+
}
|
|
3335
|
+
compileDelete(ast) {
|
|
3336
|
+
return this.impl.compileDelete(ast);
|
|
3397
3337
|
}
|
|
3398
3338
|
};
|
|
3399
3339
|
|
|
@@ -3523,22 +3463,22 @@ var MssqlFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
3523
3463
|
|
|
3524
3464
|
// src/core/dialect/mssql/output.ts
|
|
3525
3465
|
var MssqlOutputStrategy = class {
|
|
3526
|
-
compileReturning(returning, _ctx,
|
|
3466
|
+
compileReturning(returning, _ctx, quoteIdentifier5) {
|
|
3527
3467
|
void _ctx;
|
|
3528
|
-
return this.compileOutput(returning, "inserted",
|
|
3468
|
+
return this.compileOutput(returning, "inserted", quoteIdentifier5);
|
|
3529
3469
|
}
|
|
3530
|
-
compileOutput(returning, prefix,
|
|
3470
|
+
compileOutput(returning, prefix, quoteIdentifier5) {
|
|
3531
3471
|
if (!returning || returning.length === 0) return "";
|
|
3532
3472
|
const columns = returning.map((column) => {
|
|
3533
|
-
const alias = column.alias ? ` AS ${
|
|
3534
|
-
return `${prefix}.${
|
|
3473
|
+
const alias = column.alias ? ` AS ${quoteIdentifier5(column.alias)}` : "";
|
|
3474
|
+
return `${prefix}.${quoteIdentifier5(column.name)}${alias}`;
|
|
3535
3475
|
}).join(", ");
|
|
3536
3476
|
return ` OUTPUT ${columns}`;
|
|
3537
3477
|
}
|
|
3538
|
-
formatReturningColumns(returning,
|
|
3478
|
+
formatReturningColumns(returning, quoteIdentifier5) {
|
|
3539
3479
|
return returning.map((column) => {
|
|
3540
|
-
const alias = column.alias ? ` AS ${
|
|
3541
|
-
return `${
|
|
3480
|
+
const alias = column.alias ? ` AS ${quoteIdentifier5(column.alias)}` : "";
|
|
3481
|
+
return `${quoteIdentifier5(column.name)}${alias}`;
|
|
3542
3482
|
}).join(", ");
|
|
3543
3483
|
}
|
|
3544
3484
|
};
|
|
@@ -3820,34 +3760,49 @@ var MssqlProcedureCompiler = class {
|
|
|
3820
3760
|
};
|
|
3821
3761
|
|
|
3822
3762
|
// src/core/dialect/mssql/index.ts
|
|
3823
|
-
var
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3763
|
+
var quoteIdentifier4 = (id) => `[${id}]`;
|
|
3764
|
+
var createSqlServerDialect = () => {
|
|
3765
|
+
const composition = composeSqlDialect({
|
|
3766
|
+
name: "mssql",
|
|
3767
|
+
quoteIdentifier: quoteIdentifier4,
|
|
3768
|
+
formatPlaceholder: (index) => `@p${index}`,
|
|
3769
|
+
functionStrategy: new MssqlFunctionStrategy(),
|
|
3770
|
+
returningStrategy: new MssqlOutputStrategy(),
|
|
3771
|
+
compilerFactory: createMssqlCompilerSet,
|
|
3772
|
+
supportsDmlReturning: true,
|
|
3773
|
+
compileJsonPath(node) {
|
|
3774
|
+
const column = `${quoteIdentifier4(node.column.table)}.${quoteIdentifier4(node.column.name)}`;
|
|
3775
|
+
return `JSON_VALUE(${column}, '${node.path}')`;
|
|
3776
|
+
}
|
|
3777
|
+
});
|
|
3778
|
+
const procedures = new MssqlProcedureCompiler(composition.runtime);
|
|
3779
|
+
return {
|
|
3780
|
+
...composition.dialect,
|
|
3781
|
+
compileProcedureCall: (ast) => procedures.compileProcedureCall(ast)
|
|
3782
|
+
};
|
|
3783
|
+
};
|
|
3784
|
+
var SqlServerDialect = class {
|
|
3785
|
+
impl = createSqlServerDialect();
|
|
3839
3786
|
quoteIdentifier(id) {
|
|
3840
|
-
return
|
|
3787
|
+
return this.impl.quoteIdentifier(id);
|
|
3841
3788
|
}
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3789
|
+
supportsDmlReturningClause() {
|
|
3790
|
+
return this.impl.supportsDmlReturningClause();
|
|
3791
|
+
}
|
|
3792
|
+
compileSelect(ast) {
|
|
3793
|
+
return this.impl.compileSelect(ast);
|
|
3794
|
+
}
|
|
3795
|
+
compileInsert(ast) {
|
|
3796
|
+
return this.impl.compileInsert(ast);
|
|
3845
3797
|
}
|
|
3846
|
-
|
|
3847
|
-
return
|
|
3798
|
+
compileUpdate(ast) {
|
|
3799
|
+
return this.impl.compileUpdate(ast);
|
|
3800
|
+
}
|
|
3801
|
+
compileDelete(ast) {
|
|
3802
|
+
return this.impl.compileDelete(ast);
|
|
3848
3803
|
}
|
|
3849
3804
|
compileProcedureCall(ast) {
|
|
3850
|
-
return this.
|
|
3805
|
+
return this.impl.compileProcedureCall(ast);
|
|
3851
3806
|
}
|
|
3852
3807
|
};
|
|
3853
3808
|
|
|
@@ -3858,59 +3813,33 @@ var DialectFactory = class {
|
|
|
3858
3813
|
static ensureDefaults() {
|
|
3859
3814
|
if (this.defaultsInitialized) return;
|
|
3860
3815
|
this.defaultsInitialized = true;
|
|
3861
|
-
if (!this.registry.has("postgres"))
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
if (!this.registry.has("
|
|
3865
|
-
this.registry.set("mysql", () => new MySqlDialect());
|
|
3866
|
-
}
|
|
3867
|
-
if (!this.registry.has("sqlite")) {
|
|
3868
|
-
this.registry.set("sqlite", () => new SqliteDialect());
|
|
3869
|
-
}
|
|
3870
|
-
if (!this.registry.has("mssql")) {
|
|
3871
|
-
this.registry.set("mssql", () => new SqlServerDialect());
|
|
3872
|
-
}
|
|
3816
|
+
if (!this.registry.has("postgres")) this.registry.set("postgres", createPostgresDialect);
|
|
3817
|
+
if (!this.registry.has("mysql")) this.registry.set("mysql", createMySqlDialect);
|
|
3818
|
+
if (!this.registry.has("sqlite")) this.registry.set("sqlite", createSqliteDialect);
|
|
3819
|
+
if (!this.registry.has("mssql")) this.registry.set("mssql", createSqlServerDialect);
|
|
3873
3820
|
}
|
|
3874
|
-
/**
|
|
3875
|
-
* Register (or override) a dialect factory for a key.
|
|
3876
|
-
*
|
|
3877
|
-
* Implementations are structural: extending DialectBase/SqlDialectBase is
|
|
3878
|
-
* optional. A composed object satisfying Dialect is a valid registration.
|
|
3879
|
-
*/
|
|
3821
|
+
/** Register or replace a structural dialect factory. */
|
|
3880
3822
|
static register(key, factory) {
|
|
3881
3823
|
this.registry.set(key, factory);
|
|
3882
3824
|
}
|
|
3883
|
-
/**
|
|
3884
|
-
* Resolve a key into a Dialect instance.
|
|
3885
|
-
* Throws if the key is not registered.
|
|
3886
|
-
*/
|
|
3825
|
+
/** Resolve a key into a new Dialect instance. */
|
|
3887
3826
|
static create(key) {
|
|
3888
3827
|
this.ensureDefaults();
|
|
3889
3828
|
const factory = this.registry.get(key);
|
|
3890
3829
|
if (!factory) {
|
|
3891
3830
|
throw new Error(
|
|
3892
|
-
`Dialect "${String(
|
|
3893
|
-
key
|
|
3894
|
-
)}" is not registered. Use DialectFactory.register(...) to register it.`
|
|
3831
|
+
`Dialect "${String(key)}" is not registered. Use DialectFactory.register(...) to register it.`
|
|
3895
3832
|
);
|
|
3896
3833
|
}
|
|
3897
3834
|
return factory();
|
|
3898
3835
|
}
|
|
3899
|
-
/**
|
|
3900
|
-
* Clear all registrations (mainly for tests).
|
|
3901
|
-
* Built-ins will be re-registered lazily on the next create().
|
|
3902
|
-
*/
|
|
3836
|
+
/** Clear registrations; built-ins are restored lazily on the next create(). */
|
|
3903
3837
|
static clear() {
|
|
3904
3838
|
this.registry.clear();
|
|
3905
3839
|
this.defaultsInitialized = false;
|
|
3906
3840
|
}
|
|
3907
3841
|
};
|
|
3908
|
-
var resolveDialectInput = (dialect) =>
|
|
3909
|
-
if (typeof dialect === "string") {
|
|
3910
|
-
return DialectFactory.create(dialect);
|
|
3911
|
-
}
|
|
3912
|
-
return dialect;
|
|
3913
|
-
};
|
|
3842
|
+
var resolveDialectInput = (dialect) => typeof dialect === "string" ? DialectFactory.create(dialect) : dialect;
|
|
3914
3843
|
|
|
3915
3844
|
// src/core/ast/builders.ts
|
|
3916
3845
|
var isColumnNode = (col2) => "type" in col2 && col2.type === "Column";
|
|
@@ -22311,7 +22240,6 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22311
22240
|
DefaultMorphToReference,
|
|
22312
22241
|
DefaultTypeStrategy,
|
|
22313
22242
|
DeleteQueryBuilder,
|
|
22314
|
-
DialectBase,
|
|
22315
22243
|
DialectFactory,
|
|
22316
22244
|
DomainEventBus,
|
|
22317
22245
|
Email,
|
|
@@ -22357,7 +22285,6 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22357
22285
|
RelationKinds,
|
|
22358
22286
|
STANDARD_COLUMN_TYPES,
|
|
22359
22287
|
SelectQueryBuilder,
|
|
22360
|
-
SqlDialectBase,
|
|
22361
22288
|
SqlServerDialect,
|
|
22362
22289
|
SqliteDialect,
|
|
22363
22290
|
SqliteReturningStrategy,
|
|
@@ -22439,6 +22366,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22439
22366
|
columnToOpenApiSchema,
|
|
22440
22367
|
columnTypeToOpenApiFormat,
|
|
22441
22368
|
columnTypeToOpenApiType,
|
|
22369
|
+
composeSqlDialect,
|
|
22442
22370
|
computePaginationMetadata,
|
|
22443
22371
|
computeSchemaHash,
|
|
22444
22372
|
concat,
|
|
@@ -22458,11 +22386,16 @@ async function bulkUpsert(session, table, rows, options = {}) {
|
|
|
22458
22386
|
createExecutorFromQueryRunner,
|
|
22459
22387
|
createMssqlCompilerSet,
|
|
22460
22388
|
createMssqlExecutor,
|
|
22389
|
+
createMySqlDialect,
|
|
22461
22390
|
createMysqlExecutor,
|
|
22462
22391
|
createPooledExecutorFactory,
|
|
22392
|
+
createPostgresDialect,
|
|
22463
22393
|
createPostgresExecutor,
|
|
22464
22394
|
createQueryLoggingExecutor,
|
|
22465
22395
|
createRef,
|
|
22396
|
+
createSqlDialect,
|
|
22397
|
+
createSqlServerDialect,
|
|
22398
|
+
createSqliteDialect,
|
|
22466
22399
|
createSqliteExecutor,
|
|
22467
22400
|
createTediousExecutor,
|
|
22468
22401
|
createTediousMssqlClient,
|