metal-orm 1.1.24 → 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.
Files changed (35) hide show
  1. package/dist/index.cjs +770 -710
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +294 -318
  4. package/dist/index.d.ts +294 -318
  5. package/dist/index.js +745 -709
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/core/dialect/abstract.ts +7 -229
  9. package/src/core/dialect/base/returning-strategy.ts +40 -39
  10. package/src/core/dialect/base/sql-compiler-set.ts +33 -0
  11. package/src/core/dialect/base/sql-dialect-composer.ts +294 -0
  12. package/src/core/dialect/base/standard-sql-services.ts +2 -6
  13. package/src/core/dialect/base/upsert-strategy.ts +44 -0
  14. package/src/core/dialect/capabilities/procedure-compiler.ts +10 -8
  15. package/src/core/dialect/dialect-factory.ts +17 -49
  16. package/src/core/dialect/mssql/compiler-factory.ts +12 -0
  17. package/src/core/dialect/mssql/delete-compiler.ts +40 -0
  18. package/src/core/dialect/mssql/index.ts +52 -370
  19. package/src/core/dialect/mssql/insert-compiler.ts +112 -0
  20. package/src/core/dialect/mssql/output.ts +46 -0
  21. package/src/core/dialect/mssql/procedure-compiler.ts +81 -0
  22. package/src/core/dialect/mssql/select-compiler.ts +116 -0
  23. package/src/core/dialect/mssql/update-compiler.ts +37 -0
  24. package/src/core/dialect/mysql/index.ts +66 -126
  25. package/src/core/dialect/mysql/procedure-compiler.ts +67 -0
  26. package/src/core/dialect/mysql/upsert.ts +42 -0
  27. package/src/core/dialect/postgres/index.ts +75 -114
  28. package/src/core/dialect/postgres/procedure-compiler.ts +41 -0
  29. package/src/core/dialect/postgres/returning.ts +4 -0
  30. package/src/core/dialect/postgres/upsert.ts +43 -0
  31. package/src/core/dialect/sqlite/index.ts +65 -90
  32. package/src/core/dialect/sqlite/returning.ts +30 -0
  33. package/src/core/dialect/sqlite/upsert.ts +43 -0
  34. package/src/index.ts +22 -10
  35. package/src/core/dialect/base/sql-dialect.ts +0 -176
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,
@@ -92,13 +91,26 @@ __export(index_exports, {
92
91
  MorphMany: () => MorphMany,
93
92
  MorphOne: () => MorphOne,
94
93
  MorphTo: () => MorphTo,
94
+ MssqlDeleteCompiler: () => MssqlDeleteCompiler,
95
+ MssqlInsertCompiler: () => MssqlInsertCompiler,
96
+ MssqlOutputStrategy: () => MssqlOutputStrategy,
97
+ MssqlProcedureCompiler: () => MssqlProcedureCompiler,
98
+ MssqlSelectCompiler: () => MssqlSelectCompiler,
99
+ MssqlUpdateCompiler: () => MssqlUpdateCompiler,
95
100
  MySqlDialect: () => MySqlDialect,
101
+ MySqlProcedureCompiler: () => MySqlProcedureCompiler,
102
+ MySqlUpsertStrategy: () => MySqlUpsertStrategy,
96
103
  NestedSetStrategy: () => NestedSetStrategy,
104
+ NoReturningStrategy: () => NoReturningStrategy,
105
+ NoUpsertStrategy: () => NoUpsertStrategy,
97
106
  Orm: () => Orm,
98
107
  OrmSession: () => OrmSession,
99
108
  Pattern: () => Pattern,
100
109
  Pool: () => Pool,
101
110
  PostgresDialect: () => PostgresDialect,
111
+ PostgresProcedureCompiler: () => PostgresProcedureCompiler,
112
+ PostgresReturningStrategy: () => PostgresReturningStrategy,
113
+ PostgresUpsertStrategy: () => PostgresUpsertStrategy,
102
114
  PrimaryKey: () => PrimaryKey,
103
115
  ProcedureCallBuilder: () => ProcedureCallBuilder,
104
116
  PrototypeMaterializationStrategy: () => PrototypeMaterializationStrategy,
@@ -109,10 +121,15 @@ __export(index_exports, {
109
121
  SelectQueryBuilder: () => SelectQueryBuilder,
110
122
  SqlServerDialect: () => SqlServerDialect,
111
123
  SqliteDialect: () => SqliteDialect,
124
+ SqliteReturningStrategy: () => SqliteReturningStrategy,
125
+ SqliteUpsertStrategy: () => SqliteUpsertStrategy,
112
126
  StandardDeleteCompiler: () => StandardDeleteCompiler,
113
127
  StandardInsertCompiler: () => StandardInsertCompiler,
128
+ StandardLimitOffsetPagination: () => StandardLimitOffsetPagination,
129
+ StandardReturningStrategy: () => StandardReturningStrategy,
114
130
  StandardSelectCompiler: () => StandardSelectCompiler,
115
131
  StandardSqlSourceCompiler: () => StandardSqlSourceCompiler,
132
+ StandardTableFunctionStrategy: () => StandardTableFunctionStrategy,
116
133
  StandardUpdateCompiler: () => StandardUpdateCompiler,
117
134
  StringTypeStrategy: () => StringTypeStrategy,
118
135
  TagIndex: () => TagIndex,
@@ -183,6 +200,7 @@ __export(index_exports, {
183
200
  columnToOpenApiSchema: () => columnToOpenApiSchema,
184
201
  columnTypeToOpenApiFormat: () => columnTypeToOpenApiFormat,
185
202
  columnTypeToOpenApiType: () => columnTypeToOpenApiType,
203
+ composeSqlDialect: () => composeSqlDialect,
186
204
  computePaginationMetadata: () => computePaginationMetadata,
187
205
  computeSchemaHash: () => computeSchemaHash,
188
206
  concat: () => concat,
@@ -200,12 +218,18 @@ __export(index_exports, {
200
218
  createEntityFromRow: () => createEntityFromRow,
201
219
  createEntityProxy: () => createEntityProxy,
202
220
  createExecutorFromQueryRunner: () => createExecutorFromQueryRunner,
221
+ createMssqlCompilerSet: () => createMssqlCompilerSet,
203
222
  createMssqlExecutor: () => createMssqlExecutor,
223
+ createMySqlDialect: () => createMySqlDialect,
204
224
  createMysqlExecutor: () => createMysqlExecutor,
205
225
  createPooledExecutorFactory: () => createPooledExecutorFactory,
226
+ createPostgresDialect: () => createPostgresDialect,
206
227
  createPostgresExecutor: () => createPostgresExecutor,
207
228
  createQueryLoggingExecutor: () => createQueryLoggingExecutor,
208
229
  createRef: () => createRef,
230
+ createSqlDialect: () => createSqlDialect,
231
+ createSqlServerDialect: () => createSqlServerDialect,
232
+ createSqliteDialect: () => createSqliteDialect,
209
233
  createSqliteExecutor: () => createSqliteExecutor,
210
234
  createTediousExecutor: () => createTediousExecutor,
211
235
  createTediousMssqlClient: () => createTediousMssqlClient,
@@ -1984,159 +2008,6 @@ var SelectAstNormalizer = class {
1984
2008
  }
1985
2009
  };
1986
2010
 
1987
- // src/core/dialect/abstract.ts
1988
- var DialectBase = class _DialectBase {
1989
- expressionCompilerRegistry;
1990
- selectAstNormalizer;
1991
- functionStrategy;
1992
- tableFunctionStrategy;
1993
- constructor(functionStrategy, tableFunctionStrategy) {
1994
- this.functionStrategy = functionStrategy ?? new StandardFunctionStrategy();
1995
- this.tableFunctionStrategy = tableFunctionStrategy ?? new StandardTableFunctionStrategy();
1996
- this.selectAstNormalizer = new SelectAstNormalizer((kind) => this.supportsSetOperation(kind));
1997
- this.expressionCompilerRegistry = new ExpressionCompilerRegistry({
1998
- quoteIdentifier: (id) => this.quoteIdentifier(id),
1999
- compileSelectAst: (ast, ctx) => this.compileSelectAst(ast, ctx),
2000
- compileSelectForExists: (ast, ctx) => this.compileSelectForExists(ast, ctx),
2001
- compileJsonPath: (node) => this.compileJsonPath(node),
2002
- compileFunctionOperand: (node, ctx) => this.compileFunctionOperand(node, ctx),
2003
- describe: () => this.constructor.name
2004
- });
2005
- }
2006
- compileSelect(ast) {
2007
- const ctx = this.createCompilerContext();
2008
- const normalized = this.normalizeSelectAst(ast);
2009
- const rawSql = this.compileSelectAst(normalized, ctx).trim();
2010
- return {
2011
- sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
2012
- params: [...ctx.params]
2013
- };
2014
- }
2015
- compileInsert(ast) {
2016
- const ctx = this.createCompilerContext();
2017
- const rawSql = this.compileInsertAst(ast, ctx).trim();
2018
- return {
2019
- sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
2020
- params: [...ctx.params]
2021
- };
2022
- }
2023
- compileUpdate(ast) {
2024
- const ctx = this.createCompilerContext();
2025
- const rawSql = this.compileUpdateAst(ast, ctx).trim();
2026
- return {
2027
- sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
2028
- params: [...ctx.params]
2029
- };
2030
- }
2031
- compileDelete(ast) {
2032
- const ctx = this.createCompilerContext();
2033
- const rawSql = this.compileDeleteAst(ast, ctx).trim();
2034
- return {
2035
- sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
2036
- params: [...ctx.params]
2037
- };
2038
- }
2039
- supportsDmlReturningClause() {
2040
- return false;
2041
- }
2042
- compileWhere(where, ctx) {
2043
- if (!where) return "";
2044
- return ` WHERE ${this.compileExpression(where, ctx)}`;
2045
- }
2046
- compileReturning(returning, _ctx) {
2047
- void _ctx;
2048
- if (!returning || returning.length === 0) return "";
2049
- throw new Error("RETURNING is not supported by this dialect.");
2050
- }
2051
- compileSelectForExists(ast, ctx) {
2052
- const normalized = this.normalizeSelectAst(ast);
2053
- const full = this.compileSelectAst(normalized, ctx).trim().replace(/;$/, "");
2054
- if (normalized.setOps && normalized.setOps.length > 0) {
2055
- return `SELECT 1 FROM (${full}) AS _exists`;
2056
- }
2057
- const upper2 = full.toUpperCase();
2058
- const fromIndex = upper2.indexOf(" FROM ");
2059
- if (fromIndex === -1) return full;
2060
- return `SELECT 1${full.slice(fromIndex)}`;
2061
- }
2062
- createCompilerContext() {
2063
- const params = [];
2064
- let counter = 0;
2065
- return {
2066
- params,
2067
- addParameter: (value) => {
2068
- counter += 1;
2069
- params.push(value);
2070
- return this.formatPlaceholder(counter);
2071
- }
2072
- };
2073
- }
2074
- formatPlaceholder(_index) {
2075
- void _index;
2076
- return "?";
2077
- }
2078
- supportsSetOperation(_kind) {
2079
- void _kind;
2080
- return true;
2081
- }
2082
- normalizeSelectAst(ast) {
2083
- return this.selectAstNormalizer.normalize(ast);
2084
- }
2085
- registerExpressionCompiler(type, compiler) {
2086
- this.expressionCompilerRegistry.registerExpressionCompiler(type, compiler);
2087
- }
2088
- registerOperandCompiler(type, compiler) {
2089
- this.expressionCompilerRegistry.registerOperandCompiler(type, compiler);
2090
- }
2091
- compileExpression(node, ctx) {
2092
- return this.expressionCompilerRegistry.compileExpression(node, ctx);
2093
- }
2094
- compileOperand(node, ctx) {
2095
- return this.expressionCompilerRegistry.compileOperand(node, ctx);
2096
- }
2097
- compileOrderingTerm(term, ctx) {
2098
- return this.expressionCompilerRegistry.compileOrderingTerm(term, ctx);
2099
- }
2100
- compileJsonPath(_node) {
2101
- void _node;
2102
- throw new Error("JSON Path not supported by this dialect");
2103
- }
2104
- compileFunctionOperand(fnNode, ctx) {
2105
- const compiledArgs = fnNode.args.map((arg) => this.compileOperand(arg, ctx));
2106
- const renderer = this.functionStrategy.getRenderer(fnNode.name);
2107
- if (renderer) {
2108
- return renderer({
2109
- node: fnNode,
2110
- compiledArgs,
2111
- compileOperand: (operand) => this.compileOperand(operand, ctx)
2112
- });
2113
- }
2114
- return `${fnNode.name}(${compiledArgs.join(", ")})`;
2115
- }
2116
- /** Creates a minimal dialect implementation for isolated compiler tests. */
2117
- static create(functionStrategy, tableFunctionStrategy) {
2118
- class TestDialect extends _DialectBase {
2119
- dialect = "sqlite";
2120
- quoteIdentifier(id) {
2121
- return `"${id}"`;
2122
- }
2123
- compileSelectAst() {
2124
- throw new Error("Not implemented");
2125
- }
2126
- compileInsertAst() {
2127
- throw new Error("Not implemented");
2128
- }
2129
- compileUpdateAst() {
2130
- throw new Error("Not implemented");
2131
- }
2132
- compileDeleteAst() {
2133
- throw new Error("Not implemented");
2134
- }
2135
- }
2136
- return new TestDialect(functionStrategy, tableFunctionStrategy);
2137
- }
2138
- };
2139
-
2140
2011
  // src/core/dialect/base/pagination-strategy.ts
2141
2012
  var StandardLimitOffsetPagination = class {
2142
2013
  /**
@@ -2155,31 +2026,38 @@ var StandardLimitOffsetPagination = class {
2155
2026
 
2156
2027
  // src/core/dialect/base/returning-strategy.ts
2157
2028
  var NoReturningStrategy = class {
2158
- /**
2159
- * Throws an error as RETURNING is not supported.
2160
- * @param returning - Columns to return (causes error if non-empty).
2161
- * @param _ctx - Compiler context (unused).
2162
- * @throws Error indicating RETURNING is not supported.
2163
- */
2164
- compileReturning(returning, _ctx) {
2029
+ compileReturning(returning, _ctx, _quoteIdentifier) {
2165
2030
  void _ctx;
2031
+ void _quoteIdentifier;
2166
2032
  if (!returning || returning.length === 0) return "";
2167
2033
  throw new Error("RETURNING is not supported by this dialect.");
2168
2034
  }
2169
- /**
2170
- * Formats column names for RETURNING clause.
2171
- * @param returning - Columns to format.
2172
- * @param quoteIdentifier - Function to quote identifiers according to dialect rules.
2173
- * @returns Simple comma-separated column names.
2174
- */
2175
- formatReturningColumns(returning, quoteIdentifier) {
2035
+ formatReturningColumns(returning, quoteIdentifier5) {
2176
2036
  return returning.map((column) => {
2177
- const tablePart = column.table ? `${quoteIdentifier(column.table)}.` : "";
2178
- const aliasPart = column.alias ? ` AS ${quoteIdentifier(column.alias)}` : "";
2179
- return `${tablePart}${quoteIdentifier(column.name)}${aliasPart}`;
2037
+ const tablePart = column.table ? `${quoteIdentifier5(column.table)}.` : "";
2038
+ const aliasPart = column.alias ? ` AS ${quoteIdentifier5(column.alias)}` : "";
2039
+ return `${tablePart}${quoteIdentifier5(column.name)}${aliasPart}`;
2180
2040
  }).join(", ");
2181
2041
  }
2182
2042
  };
2043
+ var StandardReturningStrategy = class extends NoReturningStrategy {
2044
+ compileReturning(returning, _ctx, quoteIdentifier5) {
2045
+ void _ctx;
2046
+ if (!returning || returning.length === 0) return "";
2047
+ return ` RETURNING ${this.formatReturningColumns(returning, quoteIdentifier5)}`;
2048
+ }
2049
+ };
2050
+
2051
+ // src/core/dialect/base/upsert-strategy.ts
2052
+ var NoUpsertStrategy = class {
2053
+ compile(ast, _ctx, services) {
2054
+ void _ctx;
2055
+ if (!ast.onConflict) return "";
2056
+ throw new Error(
2057
+ `UPSERT/ON CONFLICT is not supported by dialect "${services.getDialectName()}".`
2058
+ );
2059
+ }
2060
+ };
2183
2061
 
2184
2062
  // src/core/dialect/base/function-table-formatter.ts
2185
2063
  var FunctionTableFormatter = class {
@@ -2297,13 +2175,13 @@ var CteCompiler = class {
2297
2175
  * @param stripTrailingSemicolon - Function to remove trailing semicolons from SQL.
2298
2176
  * @returns SQL WITH clause string (e.g., "WITH cte_name AS (...) ") or empty string if no CTEs.
2299
2177
  */
2300
- static compileCtes(ast, ctx, quoteIdentifier, compileSelectAst, normalizeSelectAst, stripTrailingSemicolon) {
2178
+ static compileCtes(ast, ctx, quoteIdentifier5, compileSelectAst, normalizeSelectAst, stripTrailingSemicolon) {
2301
2179
  if (!ast.ctes || ast.ctes.length === 0) return "";
2302
2180
  const hasRecursive = ast.ctes.some((cte) => cte.recursive);
2303
2181
  const prefix = hasRecursive ? "WITH RECURSIVE " : "WITH ";
2304
2182
  const cteDefs = ast.ctes.map((cte) => {
2305
- const name = quoteIdentifier(cte.name);
2306
- const cols = cte.columns && cte.columns.length ? `(${cte.columns.map((c) => quoteIdentifier(c)).join(", ")})` : "";
2183
+ const name = quoteIdentifier5(cte.name);
2184
+ const cols = cte.columns && cte.columns.length ? `(${cte.columns.map((c) => quoteIdentifier5(c)).join(", ")})` : "";
2307
2185
  const query = stripTrailingSemicolon(compileSelectAst(normalizeSelectAst(cte.query), ctx));
2308
2186
  return `${name}${cols} AS (${query})`;
2309
2187
  }).join(", ");
@@ -2526,113 +2404,174 @@ var StandardDeleteCompiler = class {
2526
2404
  }
2527
2405
  };
2528
2406
 
2529
- // src/core/dialect/base/sql-dialect.ts
2530
- var SqlDialectBase = class extends DialectBase {
2531
- paginationStrategy = new StandardLimitOffsetPagination();
2532
- returningStrategy = new NoReturningStrategy();
2533
- sourceCompiler;
2534
- selectCompiler;
2535
- insertCompiler;
2536
- updateCompiler;
2537
- deleteCompiler;
2538
- constructor(functionStrategy, tableFunctionStrategy) {
2539
- super(functionStrategy, tableFunctionStrategy);
2540
- const services = {
2541
- getDialectName: () => this.dialect,
2542
- getPaginationStrategy: () => this.paginationStrategy,
2543
- getTableFunctionStrategy: () => this.tableFunctionStrategy,
2544
- quoteIdentifier: (id) => this.quoteIdentifier(id),
2545
- compileOperand: (node, ctx) => this.compileOperand(node, ctx),
2546
- compileExpression: (node, ctx) => this.compileExpression(node, ctx),
2547
- compileOrderingTerm: (term, ctx) => this.compileOrderingTerm(term, ctx),
2548
- normalizeSelectAst: (ast) => this.normalizeSelectAst(ast),
2549
- compileSelectAst: (ast, ctx) => this.compileSelectAst(ast, ctx),
2550
- compileReturning: (returning, ctx) => this.compileReturning(returning, ctx),
2551
- compileUpsertClause: (ast, ctx) => this.compileUpsertClause(ast, ctx),
2552
- compileSetTarget: (column, table) => this.compileSetTarget(column, table),
2553
- renderOrderByNulls: (order) => this.renderOrderByNulls(order),
2554
- renderOrderByCollation: (order) => this.renderOrderByCollation(order)
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
+ }
2555
2433
  };
2556
- this.sourceCompiler = new StandardSqlSourceCompiler(services);
2557
- this.selectCompiler = new StandardSelectCompiler(services, this.sourceCompiler);
2558
- this.insertCompiler = new StandardInsertCompiler(services, this.sourceCompiler);
2559
- this.updateCompiler = new StandardUpdateCompiler(services, this.sourceCompiler);
2560
- this.deleteCompiler = new StandardDeleteCompiler(services, this.sourceCompiler);
2561
- }
2562
- compileSelectAst(ast, ctx) {
2563
- return this.selectCompiler.compile(ast, ctx);
2564
- }
2565
- compileInsertAst(ast, ctx) {
2566
- return this.insertCompiler.compile(ast, ctx);
2567
- }
2568
- compileUpdateAst(ast, ctx) {
2569
- return this.updateCompiler.compile(ast, ctx);
2570
- }
2571
- compileDeleteAst(ast, ctx) {
2572
- return this.deleteCompiler.compile(ast, ctx);
2573
- }
2574
- compileUpsertClause(ast, _ctx) {
2575
- void _ctx;
2576
- if (!ast.onConflict) return "";
2577
- throw new Error(`UPSERT/ON CONFLICT is not supported by dialect "${this.dialect}".`);
2578
- }
2579
- compileReturning(returning, ctx) {
2580
- return this.returningStrategy.compileReturning(returning, ctx);
2581
- }
2582
- ensureConflictColumns(clause, message) {
2583
- this.insertCompiler.ensureConflictColumns(clause, message);
2584
- }
2585
- compileUpdateAssignments(assignments, table, ctx) {
2586
- return this.updateCompiler.compileAssignments(assignments, table, ctx);
2587
- }
2588
- compileSetTarget(column, table) {
2589
- return this.compileQualifiedColumn(column, table);
2590
- }
2591
- compileQualifiedColumn(column, table) {
2592
- const baseTableName = table.name;
2593
- const alias = table.alias;
2594
- const columnTable = column.table ?? alias ?? baseTableName;
2595
- const tableQualifier = alias && column.table === baseTableName ? alias : columnTable;
2596
- if (!tableQualifier) return this.quoteIdentifier(column.name);
2597
- return `${this.quoteIdentifier(tableQualifier)}.${this.quoteIdentifier(column.name)}`;
2598
- }
2599
- formatReturningColumns(returning) {
2600
- return this.returningStrategy.formatReturningColumns(
2601
- returning,
2602
- (id) => this.quoteIdentifier(id)
2603
- );
2604
- }
2605
- compileFrom(source, ctx) {
2606
- return this.sourceCompiler.compileFrom(source, ctx);
2607
- }
2608
- compileFunctionTable(fn9, ctx) {
2609
- return this.sourceCompiler.compileFunctionTable(fn9, ctx);
2610
- }
2611
- compileDerivedTable(table, ctx) {
2612
- return this.sourceCompiler.compileDerivedTable(table, ctx);
2613
- }
2614
- compileTableSource(table) {
2615
- return this.sourceCompiler.compileTableSource(table);
2616
- }
2617
- compileTableName(table) {
2618
- return this.sourceCompiler.compileTableName(table);
2619
- }
2620
- compileTableReference(table) {
2621
- return this.sourceCompiler.compileTableReference(table);
2622
- }
2623
- stripTrailingSemicolon(sql) {
2624
- return this.sourceCompiler.stripTrailingSemicolon(sql);
2625
- }
2626
- wrapSetOperand(sql) {
2627
- return this.sourceCompiler.wrapSetOperand(sql);
2628
- }
2629
- renderOrderByNulls(order) {
2630
- return order.nulls ? ` NULLS ${order.nulls}` : "";
2631
- }
2632
- renderOrderByCollation(order) {
2633
- return order.collation ? ` COLLATE ${order.collation}` : "";
2634
- }
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 };
2635
2573
  };
2574
+ var createSqlDialect = (config) => composeSqlDialect(config).dialect;
2636
2575
 
2637
2576
  // src/core/dialect/postgres/functions.ts
2638
2577
  var PostgresFunctionStrategy = class extends StandardFunctionStrategy {
@@ -2795,106 +2734,41 @@ var PostgresTableFunctionStrategy = class extends StandardTableFunctionStrategy
2795
2734
  this.registerOverrides();
2796
2735
  }
2797
2736
  registerOverrides() {
2798
- this.add("ARRAY_UNNEST", ({ node, compiledArgs, quoteIdentifier }) => {
2737
+ this.add("ARRAY_UNNEST", ({ node, compiledArgs, quoteIdentifier: quoteIdentifier5 }) => {
2799
2738
  const lateral = node.lateral ?? true;
2800
2739
  const withOrd = node.withOrdinality ?? false;
2801
2740
  const base = `unnest(${compiledArgs.join(", ")})${withOrd ? " WITH ORDINALITY" : ""}`;
2802
2741
  if (node.columnAliases?.length && !node.alias) {
2803
2742
  throw new Error("tvf(ARRAY_UNNEST) with columnAliases requires an alias.");
2804
2743
  }
2805
- const alias = node.alias ? ` AS ${quoteIdentifier(node.alias)}` : "";
2806
- const cols = node.columnAliases?.length ? `(${node.columnAliases.map(quoteIdentifier).join(", ")})` : "";
2744
+ const alias = node.alias ? ` AS ${quoteIdentifier5(node.alias)}` : "";
2745
+ const cols = node.columnAliases?.length ? `(${node.columnAliases.map(quoteIdentifier5).join(", ")})` : "";
2807
2746
  return `${lateral ? "LATERAL " : ""}${base}${alias}${cols}`;
2808
2747
  });
2809
2748
  }
2810
2749
  };
2811
2750
 
2812
- // src/core/dialect/postgres/index.ts
2813
- var PostgresDialect = class extends SqlDialectBase {
2814
- dialect = "postgres";
2815
- /**
2816
- * Creates a new PostgresDialect instance
2817
- */
2818
- constructor() {
2819
- super(new PostgresFunctionStrategy(), new PostgresTableFunctionStrategy());
2820
- this.registerExpressionCompiler("BitwiseExpression", (node, ctx) => {
2821
- const left2 = this.compileOperand(node.left, ctx);
2822
- const right2 = this.compileOperand(node.right, ctx);
2823
- const op = node.operator === "^" ? "#" : node.operator;
2824
- return `${left2} ${op} ${right2}`;
2825
- });
2826
- this.registerOperandCompiler("BitwiseExpression", (node, ctx) => {
2827
- const left2 = this.compileOperand(node.left, ctx);
2828
- const right2 = this.compileOperand(node.right, ctx);
2829
- const op = node.operator === "^" ? "#" : node.operator;
2830
- return `(${left2} ${op} ${right2})`;
2831
- });
2832
- }
2833
- /**
2834
- * Quotes an identifier using PostgreSQL double-quote syntax
2835
- * @param id - Identifier to quote
2836
- * @returns Quoted identifier
2837
- */
2838
- quoteIdentifier(id) {
2839
- return `"${id}"`;
2840
- }
2841
- formatPlaceholder(index) {
2842
- return `$${index}`;
2843
- }
2844
- /**
2845
- * Compiles JSON path expression using PostgreSQL syntax
2846
- * @param node - JSON path node
2847
- * @returns PostgreSQL JSON path expression
2848
- */
2849
- compileJsonPath(node) {
2850
- const col2 = `${this.quoteIdentifier(node.column.table)}.${this.quoteIdentifier(node.column.name)}`;
2851
- return `${col2}->>'${node.path}'`;
2852
- }
2853
- compileReturning(returning, ctx) {
2854
- void ctx;
2855
- if (!returning || returning.length === 0) return "";
2856
- const columns = this.formatReturningColumns(returning);
2857
- return ` RETURNING ${columns}`;
2858
- }
2859
- compileUpsertClause(ast, ctx) {
2860
- if (!ast.onConflict) return "";
2861
- const clause = ast.onConflict;
2862
- const target = clause.target.constraint ? ` ON CONFLICT ON CONSTRAINT ${this.quoteIdentifier(clause.target.constraint)}` : (() => {
2863
- this.ensureConflictColumns(
2864
- clause,
2865
- "PostgreSQL ON CONFLICT requires conflict columns or a constraint name."
2866
- );
2867
- const cols = clause.target.columns.map((col2) => this.quoteIdentifier(col2.name)).join(", ");
2868
- return ` ON CONFLICT (${cols})`;
2869
- })();
2870
- if (clause.action.type === "DoNothing") {
2871
- return `${target} DO NOTHING`;
2872
- }
2873
- if (!clause.action.set.length) {
2874
- throw new Error("PostgreSQL ON CONFLICT DO UPDATE requires at least one assignment.");
2875
- }
2876
- const assignments = this.compileUpdateAssignments(clause.action.set, ast.into, ctx);
2877
- const where = clause.action.where ? ` WHERE ${this.compileExpression(clause.action.where, ctx)}` : "";
2878
- return `${target} DO UPDATE SET ${assignments}${where}`;
2879
- }
2880
- supportsDmlReturningClause() {
2881
- return true;
2751
+ // src/core/dialect/postgres/procedure-compiler.ts
2752
+ var PostgresProcedureCompiler = class {
2753
+ constructor(services) {
2754
+ this.services = services;
2882
2755
  }
2883
2756
  compileProcedureCall(ast) {
2884
- const ctx = this.createCompilerContext();
2885
- const qualifiedName = ast.ref.schema ? `${this.quoteIdentifier(ast.ref.schema)}.${this.quoteIdentifier(ast.ref.name)}` : this.quoteIdentifier(ast.ref.name);
2757
+ const ctx = this.services.createCompilerContext();
2758
+ const qualifiedName = ast.ref.schema ? `${this.services.quoteIdentifier(ast.ref.schema)}.${this.services.quoteIdentifier(ast.ref.name)}` : this.services.quoteIdentifier(ast.ref.name);
2886
2759
  const args = [];
2887
2760
  for (const param of ast.params) {
2888
2761
  if (param.direction === "out") continue;
2889
2762
  if (!param.value) {
2890
- throw new Error(`Procedure parameter "${param.name}" requires a value for direction "${param.direction}".`);
2763
+ throw new Error(
2764
+ `Procedure parameter "${param.name}" requires a value for direction "${param.direction}".`
2765
+ );
2891
2766
  }
2892
- args.push(this.compileOperand(param.value, ctx));
2767
+ args.push(this.services.compileOperand(param.value, ctx));
2893
2768
  }
2894
2769
  const outNames = ast.params.filter((param) => param.direction === "out" || param.direction === "inout").map((param) => param.name);
2895
- const rawSql = `CALL ${qualifiedName}(${args.join(", ")})`;
2896
2770
  return {
2897
- sql: `${rawSql};`,
2771
+ sql: `CALL ${qualifiedName}(${args.join(", ")});`,
2898
2772
  params: [...ctx.params],
2899
2773
  outParams: {
2900
2774
  source: outNames.length ? "firstResultSet" : "none",
@@ -2902,11 +2776,99 @@ var PostgresDialect = class extends SqlDialectBase {
2902
2776
  }
2903
2777
  };
2904
2778
  }
2905
- /**
2906
- * PostgreSQL requires unqualified column names in SET clause
2907
- */
2908
- compileSetTarget(column, _table) {
2909
- return this.quoteIdentifier(column.name);
2779
+ };
2780
+
2781
+ // src/core/dialect/postgres/returning.ts
2782
+ var PostgresReturningStrategy = class extends StandardReturningStrategy {
2783
+ };
2784
+
2785
+ // src/core/dialect/postgres/upsert.ts
2786
+ var PostgresUpsertStrategy = class {
2787
+ compile(ast, ctx, services) {
2788
+ if (!ast.onConflict) return "";
2789
+ const clause = ast.onConflict;
2790
+ const target = clause.target.constraint ? ` ON CONFLICT ON CONSTRAINT ${services.quoteIdentifier(clause.target.constraint)}` : (() => {
2791
+ if (!clause.target.columns.length) {
2792
+ throw new Error("PostgreSQL ON CONFLICT requires conflict columns or a constraint name.");
2793
+ }
2794
+ const columns = clause.target.columns.map((column) => services.quoteIdentifier(column.name)).join(", ");
2795
+ return ` ON CONFLICT (${columns})`;
2796
+ })();
2797
+ if (clause.action.type === "DoNothing") {
2798
+ return `${target} DO NOTHING`;
2799
+ }
2800
+ if (!clause.action.set.length) {
2801
+ throw new Error("PostgreSQL ON CONFLICT DO UPDATE requires at least one assignment.");
2802
+ }
2803
+ const assignments = services.compileUpdateAssignments(clause.action.set, ast.into, ctx);
2804
+ const where = clause.action.where ? ` WHERE ${services.compileExpression(clause.action.where, ctx)}` : "";
2805
+ return `${target} DO UPDATE SET ${assignments}${where}`;
2806
+ }
2807
+ };
2808
+
2809
+ // src/core/dialect/postgres/index.ts
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();
2852
+ quoteIdentifier(id) {
2853
+ return this.impl.quoteIdentifier(id);
2854
+ }
2855
+ supportsDmlReturningClause() {
2856
+ return this.impl.supportsDmlReturningClause();
2857
+ }
2858
+ compileSelect(ast) {
2859
+ return this.impl.compileSelect(ast);
2860
+ }
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);
2869
+ }
2870
+ compileProcedureCall(ast) {
2871
+ return this.impl.compileProcedureCall(ast);
2910
2872
  }
2911
2873
  };
2912
2874
 
@@ -3008,72 +2970,15 @@ var MysqlFunctionStrategy = class extends StandardFunctionStrategy {
3008
2970
  }
3009
2971
  };
3010
2972
 
3011
- // src/core/dialect/mysql/index.ts
2973
+ // src/core/dialect/mysql/procedure-compiler.ts
3012
2974
  var sanitizeVariableSuffix = (value) => value.replace(/[^a-zA-Z0-9_]/g, "_");
3013
- var MySqlDialect = class extends SqlDialectBase {
3014
- dialect = "mysql";
3015
- /**
3016
- * Creates a new MySqlDialect instance
3017
- */
3018
- constructor() {
3019
- super(new MysqlFunctionStrategy());
3020
- this.registerExpressionCompiler(
3021
- "IsDistinctExpression",
3022
- (node, ctx) => {
3023
- const left2 = this.compileOperand(node.left, ctx);
3024
- const right2 = this.compileOperand(node.right, ctx);
3025
- const spaceship = `${left2} <=> ${right2}`;
3026
- if (node.operator === "IS NOT DISTINCT FROM") {
3027
- return spaceship;
3028
- }
3029
- return `NOT (${spaceship})`;
3030
- }
3031
- );
3032
- }
3033
- /**
3034
- * Quotes an identifier using MySQL backtick syntax
3035
- * @param id - Identifier to quote
3036
- * @returns Quoted identifier
3037
- */
3038
- quoteIdentifier(id) {
3039
- return `\`${id}\``;
3040
- }
3041
- /**
3042
- * Compiles JSON path expression using MySQL syntax
3043
- * @param node - JSON path node
3044
- * @returns MySQL JSON path expression
3045
- */
3046
- compileJsonPath(node) {
3047
- const col2 = `${this.quoteIdentifier(node.column.table)}.${this.quoteIdentifier(node.column.name)}`;
3048
- return `${col2}->'${node.path}'`;
3049
- }
3050
- compileUpsertClause(ast, ctx) {
3051
- if (!ast.onConflict) return "";
3052
- const clause = ast.onConflict;
3053
- if (clause.action.type === "DoNothing") {
3054
- const noOpColumn = clause.target.columns[0] ?? ast.columns[0];
3055
- if (!noOpColumn) {
3056
- throw new Error("MySQL ON DUPLICATE KEY UPDATE requires at least one target column.");
3057
- }
3058
- const col2 = this.quoteIdentifier(noOpColumn.name);
3059
- return ` ON DUPLICATE KEY UPDATE ${col2} = ${col2}`;
3060
- }
3061
- if (clause.action.where) {
3062
- throw new Error("MySQL ON DUPLICATE KEY UPDATE does not support a WHERE clause.");
3063
- }
3064
- if (!clause.action.set.length) {
3065
- throw new Error("MySQL ON DUPLICATE KEY UPDATE requires at least one assignment.");
3066
- }
3067
- const assignments = clause.action.set.map((assignment) => {
3068
- const target = this.quoteIdentifier(assignment.column.name);
3069
- const value = this.compileOperand(assignment.value, ctx);
3070
- return `${target} = ${value}`;
3071
- }).join(", ");
3072
- return ` ON DUPLICATE KEY UPDATE ${assignments}`;
2975
+ var MySqlProcedureCompiler = class {
2976
+ constructor(services) {
2977
+ this.services = services;
3073
2978
  }
3074
2979
  compileProcedureCall(ast) {
3075
- const ctx = this.createCompilerContext();
3076
- const qualifiedName = ast.ref.schema ? `${this.quoteIdentifier(ast.ref.schema)}.${this.quoteIdentifier(ast.ref.name)}` : this.quoteIdentifier(ast.ref.name);
2980
+ const ctx = this.services.createCompilerContext();
2981
+ const qualifiedName = ast.ref.schema ? `${this.services.quoteIdentifier(ast.ref.schema)}.${this.services.quoteIdentifier(ast.ref.name)}` : this.services.quoteIdentifier(ast.ref.name);
3077
2982
  const prelude = [];
3078
2983
  const callArgs = [];
3079
2984
  const outVars = [];
@@ -3084,25 +2989,23 @@ var MySqlDialect = class extends SqlDialectBase {
3084
2989
  if (!param.value) {
3085
2990
  throw new Error(`Procedure parameter "${param.name}" requires a value for direction "in".`);
3086
2991
  }
3087
- callArgs.push(this.compileOperand(param.value, ctx));
2992
+ callArgs.push(this.services.compileOperand(param.value, ctx));
3088
2993
  return;
3089
2994
  }
3090
2995
  if (param.direction === "inout") {
3091
2996
  if (!param.value) {
3092
2997
  throw new Error(`Procedure parameter "${param.name}" requires a value for direction "inout".`);
3093
2998
  }
3094
- prelude.push(`SET ${variable} = ${this.compileOperand(param.value, ctx)};`);
2999
+ prelude.push(`SET ${variable} = ${this.services.compileOperand(param.value, ctx)};`);
3095
3000
  }
3096
3001
  callArgs.push(variable);
3097
3002
  outVars.push({ variable, name: param.name });
3098
3003
  });
3099
3004
  const statements = [];
3100
- if (prelude.length) {
3101
- statements.push(...prelude);
3102
- }
3005
+ if (prelude.length) statements.push(...prelude);
3103
3006
  statements.push(`CALL ${qualifiedName}(${callArgs.join(", ")});`);
3104
3007
  if (outVars.length) {
3105
- const selectOut = outVars.map(({ variable, name }) => `${variable} AS ${this.quoteIdentifier(name)}`).join(", ");
3008
+ const selectOut = outVars.map(({ variable, name }) => `${variable} AS ${this.services.quoteIdentifier(name)}`).join(", ");
3106
3009
  statements.push(`SELECT ${selectOut};`);
3107
3010
  }
3108
3011
  return {
@@ -3116,6 +3019,89 @@ var MySqlDialect = class extends SqlDialectBase {
3116
3019
  }
3117
3020
  };
3118
3021
 
3022
+ // src/core/dialect/mysql/upsert.ts
3023
+ var MySqlUpsertStrategy = class {
3024
+ compile(ast, ctx, services) {
3025
+ if (!ast.onConflict) return "";
3026
+ const clause = ast.onConflict;
3027
+ if (clause.action.type === "DoNothing") {
3028
+ const noOpColumn = clause.target.columns[0] ?? ast.columns[0];
3029
+ if (!noOpColumn) {
3030
+ throw new Error("MySQL ON DUPLICATE KEY UPDATE requires at least one target column.");
3031
+ }
3032
+ const col2 = services.quoteIdentifier(noOpColumn.name);
3033
+ return ` ON DUPLICATE KEY UPDATE ${col2} = ${col2}`;
3034
+ }
3035
+ if (clause.action.where) {
3036
+ throw new Error("MySQL ON DUPLICATE KEY UPDATE does not support a WHERE clause.");
3037
+ }
3038
+ if (!clause.action.set.length) {
3039
+ throw new Error("MySQL ON DUPLICATE KEY UPDATE requires at least one assignment.");
3040
+ }
3041
+ const assignments = clause.action.set.map((assignment) => {
3042
+ const target = services.quoteIdentifier(assignment.column.name);
3043
+ const value = services.compileOperand(assignment.value, ctx);
3044
+ return `${target} = ${value}`;
3045
+ }).join(", ");
3046
+ return ` ON DUPLICATE KEY UPDATE ${assignments}`;
3047
+ }
3048
+ };
3049
+
3050
+ // src/core/dialect/mysql/index.ts
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();
3082
+ quoteIdentifier(id) {
3083
+ return this.impl.quoteIdentifier(id);
3084
+ }
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);
3099
+ }
3100
+ compileProcedureCall(ast) {
3101
+ return this.impl.compileProcedureCall(ast);
3102
+ }
3103
+ };
3104
+
3119
3105
  // src/core/dialect/sqlite/functions.ts
3120
3106
  var SqliteFunctionStrategy = class extends StandardFunctionStrategy {
3121
3107
  constructor() {
@@ -3253,85 +3239,101 @@ var SqliteFunctionStrategy = class extends StandardFunctionStrategy {
3253
3239
  }
3254
3240
  };
3255
3241
 
3256
- // src/core/dialect/sqlite/index.ts
3257
- var SqliteDialect = class extends SqlDialectBase {
3258
- dialect = "sqlite";
3259
- /**
3260
- * Creates a new SqliteDialect instance
3261
- */
3262
- constructor() {
3263
- super(new SqliteFunctionStrategy());
3264
- this.registerExpressionCompiler("BitwiseExpression", (node, ctx) => {
3265
- const left2 = this.compileOperand(node.left, ctx);
3266
- const right2 = this.compileOperand(node.right, ctx);
3267
- if (node.operator === "^") {
3268
- return `(${left2} | ${right2}) & ~(${left2} & ${right2})`;
3269
- }
3270
- return `${left2} ${node.operator} ${right2}`;
3271
- });
3272
- this.registerOperandCompiler("BitwiseExpression", (node, ctx) => {
3273
- const left2 = this.compileOperand(node.left, ctx);
3274
- const right2 = this.compileOperand(node.right, ctx);
3275
- if (node.operator === "^") {
3276
- return `((${left2} | ${right2}) & ~(${left2} & ${right2}))`;
3277
- }
3278
- return `(${left2} ${node.operator} ${right2})`;
3279
- });
3280
- }
3281
- /**
3282
- * Quotes an identifier using SQLite double-quote syntax
3283
- * @param id - Identifier to quote
3284
- * @returns Quoted identifier
3285
- */
3286
- quoteIdentifier(id) {
3287
- return `"${id}"`;
3288
- }
3289
- /**
3290
- * Compiles JSON path expression using SQLite syntax
3291
- * @param node - JSON path node
3292
- * @returns SQLite JSON path expression
3293
- */
3294
- compileJsonPath(node) {
3295
- const col2 = `${this.quoteIdentifier(node.column.table)}.${this.quoteIdentifier(node.column.name)}`;
3296
- return `json_extract(${col2}, '${node.path}')`;
3297
- }
3298
- compileQualifiedColumn(column, _table) {
3299
- void _table;
3300
- return this.quoteIdentifier(column.name);
3301
- }
3302
- compileReturning(returning, ctx) {
3303
- void ctx;
3242
+ // src/core/dialect/sqlite/returning.ts
3243
+ var SqliteReturningStrategy = class {
3244
+ compileReturning(returning, _ctx, quoteIdentifier5) {
3245
+ void _ctx;
3304
3246
  if (!returning || returning.length === 0) return "";
3305
- const columns = this.formatReturningColumns(returning);
3306
- return ` RETURNING ${columns}`;
3247
+ return ` RETURNING ${this.formatReturningColumns(returning, quoteIdentifier5)}`;
3307
3248
  }
3308
- formatReturningColumns(returning) {
3249
+ formatReturningColumns(returning, quoteIdentifier5) {
3309
3250
  return returning.map((column) => {
3310
- const alias = column.alias ? ` AS ${this.quoteIdentifier(column.alias)}` : "";
3311
- return `${this.quoteIdentifier(column.name)}${alias}`;
3251
+ const alias = column.alias ? ` AS ${quoteIdentifier5(column.alias)}` : "";
3252
+ return `${quoteIdentifier5(column.name)}${alias}`;
3312
3253
  }).join(", ");
3313
3254
  }
3314
- compileUpsertClause(ast, ctx) {
3255
+ };
3256
+
3257
+ // src/core/dialect/sqlite/upsert.ts
3258
+ var SqliteUpsertStrategy = class {
3259
+ compile(ast, ctx, services) {
3315
3260
  if (!ast.onConflict) return "";
3316
3261
  const clause = ast.onConflict;
3317
3262
  if (clause.target.constraint) {
3318
3263
  throw new Error("SQLite ON CONFLICT does not support named constraints.");
3319
3264
  }
3320
- this.ensureConflictColumns(clause, "SQLite ON CONFLICT requires conflict columns.");
3321
- const cols = clause.target.columns.map((col2) => this.quoteIdentifier(col2.name)).join(", ");
3322
- const target = ` ON CONFLICT (${cols})`;
3265
+ if (!clause.target.columns.length) {
3266
+ throw new Error("SQLite ON CONFLICT requires conflict columns.");
3267
+ }
3268
+ const columns = clause.target.columns.map((column) => services.quoteIdentifier(column.name)).join(", ");
3269
+ const target = ` ON CONFLICT (${columns})`;
3323
3270
  if (clause.action.type === "DoNothing") {
3324
3271
  return `${target} DO NOTHING`;
3325
3272
  }
3326
3273
  if (!clause.action.set.length) {
3327
3274
  throw new Error("SQLite ON CONFLICT DO UPDATE requires at least one assignment.");
3328
3275
  }
3329
- const assignments = this.compileUpdateAssignments(clause.action.set, ast.into, ctx);
3330
- const where = clause.action.where ? ` WHERE ${this.compileExpression(clause.action.where, ctx)}` : "";
3276
+ const assignments = services.compileUpdateAssignments(clause.action.set, ast.into, ctx);
3277
+ const where = clause.action.where ? ` WHERE ${services.compileExpression(clause.action.where, ctx)}` : "";
3331
3278
  return `${target} DO UPDATE SET ${assignments}${where}`;
3332
3279
  }
3280
+ };
3281
+
3282
+ // src/core/dialect/sqlite/index.ts
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);
3303
+ if (node.operator === "^") {
3304
+ return `(${left2} | ${right2}) & ~(${left2} & ${right2})`;
3305
+ }
3306
+ return `${left2} ${node.operator} ${right2}`;
3307
+ });
3308
+ api.registerOperandCompiler("BitwiseExpression", (node, ctx) => {
3309
+ const left2 = api.compileOperand(node.left, ctx);
3310
+ const right2 = api.compileOperand(node.right, ctx);
3311
+ if (node.operator === "^") {
3312
+ return `((${left2} | ${right2}) & ~(${left2} & ${right2}))`;
3313
+ }
3314
+ return `(${left2} ${node.operator} ${right2})`;
3315
+ });
3316
+ }
3317
+ }).dialect;
3318
+ var SqliteDialect = class {
3319
+ impl = createSqliteDialect();
3320
+ quoteIdentifier(id) {
3321
+ return this.impl.quoteIdentifier(id);
3322
+ }
3333
3323
  supportsDmlReturningClause() {
3334
- return true;
3324
+ return this.impl.supportsDmlReturningClause();
3325
+ }
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);
3335
3337
  }
3336
3338
  };
3337
3339
 
@@ -3459,202 +3461,107 @@ var MssqlFunctionStrategy = class extends StandardFunctionStrategy {
3459
3461
  }
3460
3462
  };
3461
3463
 
3462
- // src/core/dialect/mssql/index.ts
3463
- var sanitizeVariableSuffix2 = (value) => value.replace(/[^a-zA-Z0-9_]/g, "_");
3464
- var toProcedureParamReference = (value) => value.startsWith("@") ? value : `@${value}`;
3465
- var SqlServerDialect = class extends SqlDialectBase {
3466
- dialect = "mssql";
3467
- /**
3468
- * Creates a new SqlServerDialect instance
3469
- */
3470
- constructor() {
3471
- super(new MssqlFunctionStrategy());
3472
- }
3473
- /**
3474
- * Quotes an identifier using SQL Server bracket syntax
3475
- * @param id - Identifier to quote
3476
- * @returns Quoted identifier
3477
- */
3478
- quoteIdentifier(id) {
3479
- return `[${id}]`;
3464
+ // src/core/dialect/mssql/output.ts
3465
+ var MssqlOutputStrategy = class {
3466
+ compileReturning(returning, _ctx, quoteIdentifier5) {
3467
+ void _ctx;
3468
+ return this.compileOutput(returning, "inserted", quoteIdentifier5);
3480
3469
  }
3481
- /**
3482
- * Compiles JSON path expression using SQL Server syntax
3483
- * @param node - JSON path node
3484
- * @returns SQL Server JSON path expression
3485
- */
3486
- compileJsonPath(node) {
3487
- const col2 = `${this.quoteIdentifier(node.column.table)}.${this.quoteIdentifier(node.column.name)}`;
3488
- return `JSON_VALUE(${col2}, '${node.path}')`;
3470
+ compileOutput(returning, prefix, quoteIdentifier5) {
3471
+ if (!returning || returning.length === 0) return "";
3472
+ const columns = returning.map((column) => {
3473
+ const alias = column.alias ? ` AS ${quoteIdentifier5(column.alias)}` : "";
3474
+ return `${prefix}.${quoteIdentifier5(column.name)}${alias}`;
3475
+ }).join(", ");
3476
+ return ` OUTPUT ${columns}`;
3489
3477
  }
3490
- /**
3491
- * Formats parameter placeholders using SQL Server named parameter syntax
3492
- * @param index - Parameter index
3493
- * @returns Named parameter placeholder
3494
- */
3495
- formatPlaceholder(index) {
3496
- return `@p${index}`;
3478
+ formatReturningColumns(returning, quoteIdentifier5) {
3479
+ return returning.map((column) => {
3480
+ const alias = column.alias ? ` AS ${quoteIdentifier5(column.alias)}` : "";
3481
+ return `${quoteIdentifier5(column.name)}${alias}`;
3482
+ }).join(", ");
3497
3483
  }
3498
- /**
3499
- * Compiles SELECT query AST to SQL Server SQL
3500
- * @param ast - Query AST
3501
- * @param ctx - Compiler context
3502
- * @returns SQL Server SQL string
3503
- */
3504
- compileSelectAst(ast, ctx) {
3505
- const hasSetOps = !!(ast.setOps && ast.setOps.length);
3506
- const ctes = this.compileCtes(ast, ctx);
3507
- const baseAst = hasSetOps ? { ...ast, setOps: void 0, orderBy: void 0, limit: void 0, offset: void 0 } : ast;
3508
- const baseSelect = this.compileSelectCoreForMssql(baseAst, ctx);
3509
- if (!hasSetOps) {
3510
- return `${ctes}${baseSelect}`;
3511
- }
3512
- const compound = ast.setOps.map((op) => `${op.operator} ${this.wrapSetOperand(this.compileSelectAst(op.query, ctx))}`).join(" ");
3513
- const orderBy = this.compileOrderBy(ast, ctx);
3514
- const pagination = this.compilePagination(ast, orderBy);
3515
- const combined = `${this.wrapSetOperand(baseSelect)} ${compound}`;
3516
- const tail = pagination || orderBy;
3517
- return `${ctes}${combined}${tail}`;
3484
+ };
3485
+
3486
+ // src/core/dialect/mssql/delete-compiler.ts
3487
+ var MssqlDeleteCompiler = class {
3488
+ constructor(services, sources) {
3489
+ this.services = services;
3490
+ this.sources = sources;
3518
3491
  }
3519
- compileDeleteAst(ast, ctx) {
3492
+ output = new MssqlOutputStrategy();
3493
+ compile(ast, ctx) {
3520
3494
  if (ast.using) {
3521
3495
  throw new Error("DELETE ... USING is not supported in the MSSQL dialect; use join() instead.");
3522
3496
  }
3523
- if (ast.from.type !== "Table") {
3524
- throw new Error("DELETE only supports base tables in the MSSQL dialect.");
3525
- }
3526
3497
  const alias = ast.from.alias ?? ast.from.name;
3527
- const target = this.compileTableReference(ast.from);
3498
+ const target = this.sources.compileTableReference(ast.from);
3528
3499
  const joins = JoinCompiler.compileJoins(
3529
3500
  ast.joins,
3530
3501
  ctx,
3531
- this.compileFrom.bind(this),
3532
- this.compileExpression.bind(this)
3502
+ (source, compilerContext) => this.sources.compileFrom(source, compilerContext),
3503
+ (expression, compilerContext) => this.services.compileExpression(expression, compilerContext)
3533
3504
  );
3534
- const whereClause = this.compileWhere(ast.where, ctx);
3535
- const returning = this.compileOutputClause(ast.returning, "deleted");
3536
- return `DELETE ${this.quoteIdentifier(alias)}${returning} FROM ${target}${joins}${whereClause}`;
3537
- }
3538
- compileUpdateAst(ast, ctx) {
3539
- const target = this.compileTableReference(ast.table);
3540
- const assignments = this.compileUpdateAssignments(ast.set, ast.table, ctx);
3541
- const output = this.compileReturning(ast.returning, ctx);
3542
- const fromClause = ast.from ? ` FROM ${this.compileFrom(ast.from, ctx)}` : "";
3543
- const joins = ast.joins ? ast.joins.map((j) => {
3544
- const table = this.compileFrom(j.table, ctx);
3545
- const cond = this.compileExpression(j.condition, ctx);
3546
- return ` ${j.kind} JOIN ${table} ON ${cond}`;
3547
- }).join("") : "";
3548
- const whereClause = this.compileWhere(ast.where, ctx);
3549
- return `UPDATE ${target} SET ${assignments}${output}${fromClause}${joins}${whereClause}`;
3550
- }
3551
- compileSelectCoreForMssql(ast, ctx) {
3552
- const columns = ast.columns.map((c) => {
3553
- const expr = c.type === "Column" ? `${this.quoteIdentifier(c.table)}.${this.quoteIdentifier(c.name)}` : this.compileOperand(c, ctx);
3554
- if (c.alias) {
3555
- if (c.alias.includes("(")) return c.alias;
3556
- return `${expr} AS ${this.quoteIdentifier(c.alias)}`;
3557
- }
3558
- return expr;
3559
- }).join(", ");
3560
- const distinct = ast.distinct ? "DISTINCT " : "";
3561
- const from = this.compileFrom(ast.from, ctx);
3562
- const joins = ast.joins.map((j) => {
3563
- const table = this.compileFrom(j.table, ctx);
3564
- const cond = this.compileExpression(j.condition, ctx);
3565
- return `${j.kind} JOIN ${table} ON ${cond}`;
3566
- }).join(" ");
3567
- const whereClause = this.compileWhere(ast.where, ctx);
3568
- const groupBy = ast.groupBy && ast.groupBy.length > 0 ? " GROUP BY " + ast.groupBy.map((term) => this.compileOrderingTerm(term, ctx)).join(", ") : "";
3569
- const having = ast.having ? ` HAVING ${this.compileExpression(ast.having, ctx)}` : "";
3570
- const orderBy = this.compileOrderBy(ast, ctx);
3571
- const pagination = this.compilePagination(ast, orderBy);
3572
- if (pagination) {
3573
- return `SELECT ${distinct}${columns} FROM ${from}${joins ? " " + joins : ""}${whereClause}${groupBy}${having}${pagination}`;
3574
- }
3575
- return `SELECT ${distinct}${columns} FROM ${from}${joins ? " " + joins : ""}${whereClause}${groupBy}${having}${orderBy}`;
3576
- }
3577
- compileOrderBy(ast, ctx) {
3578
- return OrderByCompiler.compileOrderBy(
3579
- ast,
3580
- (term) => this.compileOrderingTerm(term, ctx),
3581
- this.renderOrderByNulls.bind(this),
3582
- this.renderOrderByCollation.bind(this)
3505
+ const where = ast.where ? ` WHERE ${this.services.compileExpression(ast.where, ctx)}` : "";
3506
+ const returning = this.output.compileOutput(
3507
+ ast.returning,
3508
+ "deleted",
3509
+ (id) => this.services.quoteIdentifier(id)
3583
3510
  );
3511
+ return `DELETE ${this.services.quoteIdentifier(alias)}${returning} FROM ${target}${joins}${where}`;
3584
3512
  }
3585
- compilePagination(ast, orderBy) {
3586
- const hasLimit = ast.limit !== void 0;
3587
- const hasOffset = ast.offset !== void 0;
3588
- if (!hasLimit && !hasOffset) return "";
3589
- const off = ast.offset ?? 0;
3590
- let orderClause = orderBy;
3591
- if (!orderClause) {
3592
- orderClause = ast.distinct && ast.distinct.length > 0 ? " ORDER BY 1" : " ORDER BY (SELECT NULL)";
3593
- }
3594
- let pagination = `${orderClause} OFFSET ${off} ROWS`;
3595
- if (hasLimit) {
3596
- pagination += ` FETCH NEXT ${ast.limit} ROWS ONLY`;
3597
- }
3598
- return pagination;
3599
- }
3600
- supportsDmlReturningClause() {
3601
- return true;
3602
- }
3603
- compileReturning(returning, _ctx) {
3604
- void _ctx;
3605
- return this.compileOutputClause(returning, "inserted");
3606
- }
3607
- compileOutputClause(returning, prefix) {
3608
- if (!returning || returning.length === 0) return "";
3609
- const columns = returning.map((column) => {
3610
- const colName = this.quoteIdentifier(column.name);
3611
- const alias = column.alias ? ` AS ${this.quoteIdentifier(column.alias)}` : "";
3612
- return `${prefix}.${colName}${alias}`;
3613
- }).join(", ");
3614
- return ` OUTPUT ${columns}`;
3513
+ };
3514
+
3515
+ // src/core/dialect/mssql/insert-compiler.ts
3516
+ var MssqlInsertCompiler = class {
3517
+ constructor(services, sources) {
3518
+ this.services = services;
3519
+ this.sources = sources;
3615
3520
  }
3616
- compileInsertAst(ast, ctx) {
3521
+ compile(ast, ctx) {
3617
3522
  if (!ast.columns.length) {
3618
3523
  throw new Error("INSERT queries must specify columns.");
3619
3524
  }
3620
- if (ast.onConflict) {
3621
- return this.compileMergeInsert(ast, ctx);
3622
- }
3623
- const table = this.compileTableName(ast.into);
3624
- const columnList = ast.columns.map((column) => this.quoteIdentifier(column.name)).join(", ");
3625
- const output = this.compileReturning(ast.returning, ctx);
3626
- const source = this.compileInsertValues(ast, ctx);
3627
- return `INSERT INTO ${table} (${columnList})${output} ${source}`;
3525
+ if (ast.onConflict) return this.compileMerge(ast, ctx);
3526
+ const table = this.sources.compileTableName(ast.into);
3527
+ const columns = ast.columns.map((column) => this.services.quoteIdentifier(column.name)).join(", ");
3528
+ const output = this.services.compileReturning(ast.returning, ctx);
3529
+ const source = this.compileInsertSource(ast, ctx);
3530
+ return `INSERT INTO ${table} (${columns})${output} ${source}`;
3628
3531
  }
3629
- compileMergeInsert(ast, ctx) {
3532
+ compileMerge(ast, ctx) {
3630
3533
  const clause = ast.onConflict;
3631
3534
  if (clause.target.constraint) {
3632
3535
  throw new Error("MSSQL MERGE does not support conflict target by constraint name.");
3633
3536
  }
3634
- this.ensureConflictColumns(clause, "MSSQL MERGE requires conflict columns for the ON clause.");
3635
- const table = this.compileTableName(ast.into);
3636
- const targetRef = this.quoteIdentifier(ast.into.alias ?? ast.into.name);
3637
- const sourceAlias = this.quoteIdentifier("src");
3638
- const sourceColumns = ast.columns.map((column) => this.quoteIdentifier(column.name)).join(", ");
3537
+ if (!clause.target.columns.length) {
3538
+ throw new Error("MSSQL MERGE requires conflict columns for the ON clause.");
3539
+ }
3540
+ const table = this.sources.compileTableName(ast.into);
3541
+ const targetRef = this.services.quoteIdentifier(ast.into.alias ?? ast.into.name);
3542
+ const sourceAlias = this.services.quoteIdentifier("src");
3543
+ const sourceColumns = ast.columns.map((column) => this.services.quoteIdentifier(column.name)).join(", ");
3639
3544
  const usingSource = this.compileMergeUsingSource(ast, ctx);
3640
- const onClause = clause.target.columns.map((column) => `${targetRef}.${this.quoteIdentifier(column.name)} = ${sourceAlias}.${this.quoteIdentifier(column.name)}`).join(" AND ");
3545
+ const onClause = clause.target.columns.map(
3546
+ (column) => `${targetRef}.${this.services.quoteIdentifier(column.name)} = ${sourceAlias}.${this.services.quoteIdentifier(column.name)}`
3547
+ ).join(" AND ");
3641
3548
  const branches = [];
3642
3549
  if (clause.action.type === "DoUpdate") {
3643
3550
  if (!clause.action.set.length) {
3644
3551
  throw new Error("MSSQL MERGE WHEN MATCHED UPDATE requires at least one assignment.");
3645
3552
  }
3646
3553
  const assignments = clause.action.set.map((assignment) => {
3647
- const target = `${targetRef}.${this.quoteIdentifier(assignment.column.name)}`;
3648
- const value = this.compileOperand(assignment.value, ctx);
3554
+ const target = `${targetRef}.${this.services.quoteIdentifier(assignment.column.name)}`;
3555
+ const value = this.services.compileOperand(assignment.value, ctx);
3649
3556
  return `${target} = ${value}`;
3650
3557
  }).join(", ");
3651
- const guard = clause.action.where ? ` AND ${this.compileExpression(clause.action.where, ctx)}` : "";
3558
+ const guard = clause.action.where ? ` AND ${this.services.compileExpression(clause.action.where, ctx)}` : "";
3652
3559
  branches.push(`WHEN MATCHED${guard} THEN UPDATE SET ${assignments}`);
3653
3560
  }
3654
- const insertColumns = ast.columns.map((column) => this.quoteIdentifier(column.name)).join(", ");
3655
- const insertValues = ast.columns.map((column) => `${sourceAlias}.${this.quoteIdentifier(column.name)}`).join(", ");
3561
+ const insertColumns = ast.columns.map((column) => this.services.quoteIdentifier(column.name)).join(", ");
3562
+ const insertValues = ast.columns.map((column) => `${sourceAlias}.${this.services.quoteIdentifier(column.name)}`).join(", ");
3656
3563
  branches.push(`WHEN NOT MATCHED THEN INSERT (${insertColumns}) VALUES (${insertValues})`);
3657
- const output = this.compileReturning(ast.returning, ctx);
3564
+ const output = this.services.compileReturning(ast.returning, ctx);
3658
3565
  return `MERGE INTO ${table} USING ${usingSource} AS ${sourceAlias} (${sourceColumns}) ON ${onClause} ${branches.join(" ")}${output}`;
3659
3566
  }
3660
3567
  compileMergeUsingSource(ast, ctx) {
@@ -3662,38 +3569,146 @@ var SqlServerDialect = class extends SqlDialectBase {
3662
3569
  if (!ast.source.rows.length) {
3663
3570
  throw new Error("INSERT ... VALUES requires at least one row.");
3664
3571
  }
3665
- const rows = ast.source.rows.map((row) => `(${row.map((value) => this.compileOperand(value, ctx)).join(", ")})`).join(", ");
3572
+ const rows = ast.source.rows.map((row) => `(${row.map((value) => this.services.compileOperand(value, ctx)).join(", ")})`).join(", ");
3666
3573
  return `(VALUES ${rows})`;
3667
3574
  }
3668
- const normalized = this.normalizeSelectAst(ast.source.query);
3669
- const selectSql = this.compileSelectAst(normalized, ctx).trim().replace(/;$/, "");
3575
+ const normalized = this.services.normalizeSelectAst(ast.source.query);
3576
+ const selectSql = this.sources.stripTrailingSemicolon(
3577
+ this.services.compileSelectAst(normalized, ctx)
3578
+ );
3670
3579
  return `(${selectSql})`;
3671
3580
  }
3672
- compileInsertValues(ast, ctx) {
3673
- const source = ast.source;
3674
- if (source.type === "InsertValues") {
3675
- if (!source.rows.length) {
3581
+ compileInsertSource(ast, ctx) {
3582
+ if (ast.source.type === "InsertValues") {
3583
+ if (!ast.source.rows.length) {
3676
3584
  throw new Error("INSERT ... VALUES requires at least one row.");
3677
3585
  }
3678
- const values = source.rows.map((row) => `(${row.map((value) => this.compileOperand(value, ctx)).join(", ")})`).join(", ");
3586
+ const values = ast.source.rows.map((row) => `(${row.map((value) => this.services.compileOperand(value, ctx)).join(", ")})`).join(", ");
3679
3587
  return `VALUES ${values}`;
3680
3588
  }
3681
- const normalized = this.normalizeSelectAst(source.query);
3682
- return this.compileSelectAst(normalized, ctx).trim();
3589
+ const normalized = this.services.normalizeSelectAst(ast.source.query);
3590
+ return this.services.compileSelectAst(normalized, ctx).trim();
3591
+ }
3592
+ };
3593
+
3594
+ // src/core/dialect/mssql/select-compiler.ts
3595
+ var MssqlSelectCompiler = class {
3596
+ constructor(services, sources) {
3597
+ this.services = services;
3598
+ this.sources = sources;
3599
+ }
3600
+ compile(ast, ctx) {
3601
+ const hasSetOps = !!(ast.setOps && ast.setOps.length);
3602
+ const ctes = this.compileCtes(ast, ctx);
3603
+ const baseAst = hasSetOps ? { ...ast, setOps: void 0, orderBy: void 0, limit: void 0, offset: void 0 } : ast;
3604
+ const baseSelect = this.compileCore(baseAst, ctx);
3605
+ if (!hasSetOps) return `${ctes}${baseSelect}`;
3606
+ const compound = ast.setOps.map((op) => `${op.operator} ${this.sources.wrapSetOperand(this.services.compileSelectAst(op.query, ctx))}`).join(" ");
3607
+ const orderBy = this.compileOrderBy(ast, ctx);
3608
+ const pagination = this.compilePagination(ast, orderBy);
3609
+ const combined = `${this.sources.wrapSetOperand(baseSelect)} ${compound}`;
3610
+ return `${ctes}${combined}${pagination || orderBy}`;
3611
+ }
3612
+ compileCore(ast, ctx) {
3613
+ const columns = ast.columns.map((column) => {
3614
+ const expr = column.type === "Column" ? `${this.services.quoteIdentifier(column.table)}.${this.services.quoteIdentifier(column.name)}` : this.services.compileOperand(column, ctx);
3615
+ if (!column.alias) return expr;
3616
+ if (column.alias.includes("(")) return column.alias;
3617
+ return `${expr} AS ${this.services.quoteIdentifier(column.alias)}`;
3618
+ }).join(", ");
3619
+ const distinct = ast.distinct ? "DISTINCT " : "";
3620
+ const from = this.sources.compileFrom(ast.from, ctx);
3621
+ const joins = ast.joins.map((join) => {
3622
+ const table = this.sources.compileFrom(join.table, ctx);
3623
+ const condition = this.services.compileExpression(join.condition, ctx);
3624
+ return `${join.kind} JOIN ${table} ON ${condition}`;
3625
+ }).join(" ");
3626
+ const where = ast.where ? ` WHERE ${this.services.compileExpression(ast.where, ctx)}` : "";
3627
+ const groupBy = ast.groupBy && ast.groupBy.length > 0 ? ` GROUP BY ${ast.groupBy.map((term) => this.services.compileOrderingTerm(term, ctx)).join(", ")}` : "";
3628
+ const having = ast.having ? ` HAVING ${this.services.compileExpression(ast.having, ctx)}` : "";
3629
+ const orderBy = this.compileOrderBy(ast, ctx);
3630
+ const pagination = this.compilePagination(ast, orderBy);
3631
+ if (pagination) {
3632
+ return `SELECT ${distinct}${columns} FROM ${from}${joins ? ` ${joins}` : ""}${where}${groupBy}${having}${pagination}`;
3633
+ }
3634
+ return `SELECT ${distinct}${columns} FROM ${from}${joins ? ` ${joins}` : ""}${where}${groupBy}${having}${orderBy}`;
3635
+ }
3636
+ compileOrderBy(ast, ctx) {
3637
+ return OrderByCompiler.compileOrderBy(
3638
+ ast,
3639
+ (term) => this.services.compileOrderingTerm(term, ctx),
3640
+ (order) => this.services.renderOrderByNulls(order),
3641
+ (order) => this.services.renderOrderByCollation(order)
3642
+ );
3643
+ }
3644
+ compilePagination(ast, orderBy) {
3645
+ const hasLimit = ast.limit !== void 0;
3646
+ const hasOffset = ast.offset !== void 0;
3647
+ if (!hasLimit && !hasOffset) return "";
3648
+ const offset = ast.offset ?? 0;
3649
+ let orderClause = orderBy;
3650
+ if (!orderClause) {
3651
+ orderClause = ast.distinct && ast.distinct.length > 0 ? " ORDER BY 1" : " ORDER BY (SELECT NULL)";
3652
+ }
3653
+ let pagination = `${orderClause} OFFSET ${offset} ROWS`;
3654
+ if (hasLimit) pagination += ` FETCH NEXT ${ast.limit} ROWS ONLY`;
3655
+ return pagination;
3683
3656
  }
3684
3657
  compileCtes(ast, ctx) {
3685
3658
  if (!ast.ctes || ast.ctes.length === 0) return "";
3686
- const defs = ast.ctes.map((cte) => {
3687
- const name = this.quoteIdentifier(cte.name);
3688
- const cols = cte.columns ? `(${cte.columns.map((c) => this.quoteIdentifier(c)).join(", ")})` : "";
3689
- const query = this.compileSelectAst(this.normalizeSelectAst(cte.query), ctx).trim().replace(/;$/, "");
3690
- return `${name}${cols} AS (${query})`;
3659
+ const definitions = ast.ctes.map((cte) => {
3660
+ const name = this.services.quoteIdentifier(cte.name);
3661
+ const columns = cte.columns ? `(${cte.columns.map((column) => this.services.quoteIdentifier(column)).join(", ")})` : "";
3662
+ const query = this.sources.stripTrailingSemicolon(
3663
+ this.services.compileSelectAst(this.services.normalizeSelectAst(cte.query), ctx)
3664
+ );
3665
+ return `${name}${columns} AS (${query})`;
3691
3666
  }).join(", ");
3692
- return `WITH ${defs} `;
3667
+ return `WITH ${definitions} `;
3668
+ }
3669
+ };
3670
+
3671
+ // src/core/dialect/mssql/update-compiler.ts
3672
+ var MssqlUpdateCompiler = class {
3673
+ constructor(services, sources) {
3674
+ this.services = services;
3675
+ this.sources = sources;
3676
+ this.standardUpdate = new StandardUpdateCompiler(services, sources);
3677
+ }
3678
+ standardUpdate;
3679
+ compile(ast, ctx) {
3680
+ const target = this.sources.compileTableReference(ast.table);
3681
+ const assignments = this.standardUpdate.compileAssignments(ast.set, ast.table, ctx);
3682
+ const output = this.services.compileReturning(ast.returning, ctx);
3683
+ const from = ast.from ? ` FROM ${this.sources.compileFrom(ast.from, ctx)}` : "";
3684
+ const joins = ast.joins ? ast.joins.map((join) => {
3685
+ const table = this.sources.compileFrom(join.table, ctx);
3686
+ const condition = this.services.compileExpression(join.condition, ctx);
3687
+ return ` ${join.kind} JOIN ${table} ON ${condition}`;
3688
+ }).join("") : "";
3689
+ const where = ast.where ? ` WHERE ${this.services.compileExpression(ast.where, ctx)}` : "";
3690
+ return `UPDATE ${target} SET ${assignments}${output}${from}${joins}${where}`;
3691
+ }
3692
+ };
3693
+
3694
+ // src/core/dialect/mssql/compiler-factory.ts
3695
+ var createMssqlCompilerSet = ({ services, sources }) => ({
3696
+ select: new MssqlSelectCompiler(services, sources),
3697
+ insert: new MssqlInsertCompiler(services, sources),
3698
+ update: new MssqlUpdateCompiler(services, sources),
3699
+ delete: new MssqlDeleteCompiler(services, sources)
3700
+ });
3701
+
3702
+ // src/core/dialect/mssql/procedure-compiler.ts
3703
+ var sanitizeVariableSuffix2 = (value) => value.replace(/[^a-zA-Z0-9_]/g, "_");
3704
+ var toProcedureParamReference = (value) => value.startsWith("@") ? value : `@${value}`;
3705
+ var MssqlProcedureCompiler = class {
3706
+ constructor(services) {
3707
+ this.services = services;
3693
3708
  }
3694
3709
  compileProcedureCall(ast) {
3695
- const ctx = this.createCompilerContext();
3696
- const qualifiedName = ast.ref.schema ? `${this.quoteIdentifier(ast.ref.schema)}.${this.quoteIdentifier(ast.ref.name)}` : this.quoteIdentifier(ast.ref.name);
3710
+ const ctx = this.services.createCompilerContext();
3711
+ const qualifiedName = ast.ref.schema ? `${this.services.quoteIdentifier(ast.ref.schema)}.${this.services.quoteIdentifier(ast.ref.name)}` : this.services.quoteIdentifier(ast.ref.name);
3697
3712
  const declarations = [];
3698
3713
  const assignments = [];
3699
3714
  const execArgs = [];
@@ -3704,7 +3719,7 @@ var SqlServerDialect = class extends SqlDialectBase {
3704
3719
  if (!param.value) {
3705
3720
  throw new Error(`Procedure parameter "${param.name}" requires a value for direction "in".`);
3706
3721
  }
3707
- execArgs.push(`${targetParam} = ${this.compileOperand(param.value, ctx)}`);
3722
+ execArgs.push(`${targetParam} = ${this.services.compileOperand(param.value, ctx)}`);
3708
3723
  return;
3709
3724
  }
3710
3725
  if (!param.dbType) {
@@ -3719,7 +3734,7 @@ var SqlServerDialect = class extends SqlDialectBase {
3719
3734
  if (!param.value) {
3720
3735
  throw new Error(`Procedure parameter "${param.name}" requires a value for direction "inout".`);
3721
3736
  }
3722
- assignments.push(`SET ${variable} = ${this.compileOperand(param.value, ctx)};`);
3737
+ assignments.push(`SET ${variable} = ${this.services.compileOperand(param.value, ctx)};`);
3723
3738
  }
3724
3739
  execArgs.push(`${targetParam} = ${variable} OUTPUT`);
3725
3740
  outVars.push({ variable, name: param.name });
@@ -3730,7 +3745,7 @@ var SqlServerDialect = class extends SqlDialectBase {
3730
3745
  const argsSql = execArgs.length ? ` ${execArgs.join(", ")}` : "";
3731
3746
  statements.push(`EXEC ${qualifiedName}${argsSql};`);
3732
3747
  if (outVars.length) {
3733
- const selectOut = outVars.map(({ variable, name }) => `${variable} AS ${this.quoteIdentifier(name)}`).join(", ");
3748
+ const selectOut = outVars.map(({ variable, name }) => `${variable} AS ${this.services.quoteIdentifier(name)}`).join(", ");
3734
3749
  statements.push(`SELECT ${selectOut};`);
3735
3750
  }
3736
3751
  return {
@@ -3744,6 +3759,53 @@ var SqlServerDialect = class extends SqlDialectBase {
3744
3759
  }
3745
3760
  };
3746
3761
 
3762
+ // src/core/dialect/mssql/index.ts
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();
3786
+ quoteIdentifier(id) {
3787
+ return this.impl.quoteIdentifier(id);
3788
+ }
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);
3797
+ }
3798
+ compileUpdate(ast) {
3799
+ return this.impl.compileUpdate(ast);
3800
+ }
3801
+ compileDelete(ast) {
3802
+ return this.impl.compileDelete(ast);
3803
+ }
3804
+ compileProcedureCall(ast) {
3805
+ return this.impl.compileProcedureCall(ast);
3806
+ }
3807
+ };
3808
+
3747
3809
  // src/core/dialect/dialect-factory.ts
3748
3810
  var DialectFactory = class {
3749
3811
  static registry = /* @__PURE__ */ new Map();
@@ -3751,59 +3813,33 @@ var DialectFactory = class {
3751
3813
  static ensureDefaults() {
3752
3814
  if (this.defaultsInitialized) return;
3753
3815
  this.defaultsInitialized = true;
3754
- if (!this.registry.has("postgres")) {
3755
- this.registry.set("postgres", () => new PostgresDialect());
3756
- }
3757
- if (!this.registry.has("mysql")) {
3758
- this.registry.set("mysql", () => new MySqlDialect());
3759
- }
3760
- if (!this.registry.has("sqlite")) {
3761
- this.registry.set("sqlite", () => new SqliteDialect());
3762
- }
3763
- if (!this.registry.has("mssql")) {
3764
- this.registry.set("mssql", () => new SqlServerDialect());
3765
- }
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);
3766
3820
  }
3767
- /**
3768
- * Register (or override) a dialect factory for a key.
3769
- *
3770
- * Implementations are structural: extending DialectBase/SqlDialectBase is
3771
- * optional. A composed object satisfying Dialect is a valid registration.
3772
- */
3821
+ /** Register or replace a structural dialect factory. */
3773
3822
  static register(key, factory) {
3774
3823
  this.registry.set(key, factory);
3775
3824
  }
3776
- /**
3777
- * Resolve a key into a Dialect instance.
3778
- * Throws if the key is not registered.
3779
- */
3825
+ /** Resolve a key into a new Dialect instance. */
3780
3826
  static create(key) {
3781
3827
  this.ensureDefaults();
3782
3828
  const factory = this.registry.get(key);
3783
3829
  if (!factory) {
3784
3830
  throw new Error(
3785
- `Dialect "${String(
3786
- key
3787
- )}" is not registered. Use DialectFactory.register(...) to register it.`
3831
+ `Dialect "${String(key)}" is not registered. Use DialectFactory.register(...) to register it.`
3788
3832
  );
3789
3833
  }
3790
3834
  return factory();
3791
3835
  }
3792
- /**
3793
- * Clear all registrations (mainly for tests).
3794
- * Built-ins will be re-registered lazily on the next create().
3795
- */
3836
+ /** Clear registrations; built-ins are restored lazily on the next create(). */
3796
3837
  static clear() {
3797
3838
  this.registry.clear();
3798
3839
  this.defaultsInitialized = false;
3799
3840
  }
3800
3841
  };
3801
- var resolveDialectInput = (dialect) => {
3802
- if (typeof dialect === "string") {
3803
- return DialectFactory.create(dialect);
3804
- }
3805
- return dialect;
3806
- };
3842
+ var resolveDialectInput = (dialect) => typeof dialect === "string" ? DialectFactory.create(dialect) : dialect;
3807
3843
 
3808
3844
  // src/core/ast/builders.ts
3809
3845
  var isColumnNode = (col2) => "type" in col2 && col2.type === "Column";
@@ -22204,7 +22240,6 @@ async function bulkUpsert(session, table, rows, options = {}) {
22204
22240
  DefaultMorphToReference,
22205
22241
  DefaultTypeStrategy,
22206
22242
  DeleteQueryBuilder,
22207
- DialectBase,
22208
22243
  DialectFactory,
22209
22244
  DomainEventBus,
22210
22245
  Email,
@@ -22222,13 +22257,26 @@ async function bulkUpsert(session, table, rows, options = {}) {
22222
22257
  MorphMany,
22223
22258
  MorphOne,
22224
22259
  MorphTo,
22260
+ MssqlDeleteCompiler,
22261
+ MssqlInsertCompiler,
22262
+ MssqlOutputStrategy,
22263
+ MssqlProcedureCompiler,
22264
+ MssqlSelectCompiler,
22265
+ MssqlUpdateCompiler,
22225
22266
  MySqlDialect,
22267
+ MySqlProcedureCompiler,
22268
+ MySqlUpsertStrategy,
22226
22269
  NestedSetStrategy,
22270
+ NoReturningStrategy,
22271
+ NoUpsertStrategy,
22227
22272
  Orm,
22228
22273
  OrmSession,
22229
22274
  Pattern,
22230
22275
  Pool,
22231
22276
  PostgresDialect,
22277
+ PostgresProcedureCompiler,
22278
+ PostgresReturningStrategy,
22279
+ PostgresUpsertStrategy,
22232
22280
  PrimaryKey,
22233
22281
  ProcedureCallBuilder,
22234
22282
  PrototypeMaterializationStrategy,
@@ -22239,10 +22287,15 @@ async function bulkUpsert(session, table, rows, options = {}) {
22239
22287
  SelectQueryBuilder,
22240
22288
  SqlServerDialect,
22241
22289
  SqliteDialect,
22290
+ SqliteReturningStrategy,
22291
+ SqliteUpsertStrategy,
22242
22292
  StandardDeleteCompiler,
22243
22293
  StandardInsertCompiler,
22294
+ StandardLimitOffsetPagination,
22295
+ StandardReturningStrategy,
22244
22296
  StandardSelectCompiler,
22245
22297
  StandardSqlSourceCompiler,
22298
+ StandardTableFunctionStrategy,
22246
22299
  StandardUpdateCompiler,
22247
22300
  StringTypeStrategy,
22248
22301
  TagIndex,
@@ -22313,6 +22366,7 @@ async function bulkUpsert(session, table, rows, options = {}) {
22313
22366
  columnToOpenApiSchema,
22314
22367
  columnTypeToOpenApiFormat,
22315
22368
  columnTypeToOpenApiType,
22369
+ composeSqlDialect,
22316
22370
  computePaginationMetadata,
22317
22371
  computeSchemaHash,
22318
22372
  concat,
@@ -22330,12 +22384,18 @@ async function bulkUpsert(session, table, rows, options = {}) {
22330
22384
  createEntityFromRow,
22331
22385
  createEntityProxy,
22332
22386
  createExecutorFromQueryRunner,
22387
+ createMssqlCompilerSet,
22333
22388
  createMssqlExecutor,
22389
+ createMySqlDialect,
22334
22390
  createMysqlExecutor,
22335
22391
  createPooledExecutorFactory,
22392
+ createPostgresDialect,
22336
22393
  createPostgresExecutor,
22337
22394
  createQueryLoggingExecutor,
22338
22395
  createRef,
22396
+ createSqlDialect,
22397
+ createSqlServerDialect,
22398
+ createSqliteDialect,
22339
22399
  createSqliteExecutor,
22340
22400
  createTediousExecutor,
22341
22401
  createTediousMssqlClient,