metal-orm 1.1.25 → 1.1.27
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 +1151 -510
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +281 -248
- package/dist/index.d.ts +281 -248
- package/dist/index.js +1133 -508
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/ddl/dialects/index.ts +5 -6
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +129 -126
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +119 -111
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +173 -164
- package/src/core/ddl/dialects/render-reference.test.ts +37 -57
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +110 -121
- package/src/core/ddl/schema-dialect-composer.ts +129 -0
- package/src/core/ddl/schema-dialect.ts +40 -27
- package/src/core/ddl/schema-diff.ts +119 -90
- 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/core/driver/mssql-driver.ts +6 -8
- package/src/core/driver/mysql-driver.ts +6 -8
- package/src/core/driver/postgres-driver.ts +6 -8
- package/src/core/driver/sqlite-driver.ts +6 -8
- package/src/index.ts +13 -1
- package/src/core/ddl/dialects/base-schema-dialect.ts +0 -96
- package/src/core/dialect/base/sql-dialect.ts +0 -217
package/dist/index.js
CHANGED
|
@@ -1533,159 +1533,6 @@ var SelectAstNormalizer = class {
|
|
|
1533
1533
|
}
|
|
1534
1534
|
};
|
|
1535
1535
|
|
|
1536
|
-
// src/core/dialect/abstract.ts
|
|
1537
|
-
var DialectBase = class _DialectBase {
|
|
1538
|
-
expressionCompilerRegistry;
|
|
1539
|
-
selectAstNormalizer;
|
|
1540
|
-
functionStrategy;
|
|
1541
|
-
tableFunctionStrategy;
|
|
1542
|
-
constructor(functionStrategy, tableFunctionStrategy) {
|
|
1543
|
-
this.functionStrategy = functionStrategy ?? new StandardFunctionStrategy();
|
|
1544
|
-
this.tableFunctionStrategy = tableFunctionStrategy ?? new StandardTableFunctionStrategy();
|
|
1545
|
-
this.selectAstNormalizer = new SelectAstNormalizer((kind) => this.supportsSetOperation(kind));
|
|
1546
|
-
this.expressionCompilerRegistry = new ExpressionCompilerRegistry({
|
|
1547
|
-
quoteIdentifier: (id) => this.quoteIdentifier(id),
|
|
1548
|
-
compileSelectAst: (ast, ctx) => this.compileSelectAst(ast, ctx),
|
|
1549
|
-
compileSelectForExists: (ast, ctx) => this.compileSelectForExists(ast, ctx),
|
|
1550
|
-
compileJsonPath: (node) => this.compileJsonPath(node),
|
|
1551
|
-
compileFunctionOperand: (node, ctx) => this.compileFunctionOperand(node, ctx),
|
|
1552
|
-
describe: () => this.constructor.name
|
|
1553
|
-
});
|
|
1554
|
-
}
|
|
1555
|
-
compileSelect(ast) {
|
|
1556
|
-
const ctx = this.createCompilerContext();
|
|
1557
|
-
const normalized = this.normalizeSelectAst(ast);
|
|
1558
|
-
const rawSql = this.compileSelectAst(normalized, ctx).trim();
|
|
1559
|
-
return {
|
|
1560
|
-
sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
|
|
1561
|
-
params: [...ctx.params]
|
|
1562
|
-
};
|
|
1563
|
-
}
|
|
1564
|
-
compileInsert(ast) {
|
|
1565
|
-
const ctx = this.createCompilerContext();
|
|
1566
|
-
const rawSql = this.compileInsertAst(ast, ctx).trim();
|
|
1567
|
-
return {
|
|
1568
|
-
sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
|
|
1569
|
-
params: [...ctx.params]
|
|
1570
|
-
};
|
|
1571
|
-
}
|
|
1572
|
-
compileUpdate(ast) {
|
|
1573
|
-
const ctx = this.createCompilerContext();
|
|
1574
|
-
const rawSql = this.compileUpdateAst(ast, ctx).trim();
|
|
1575
|
-
return {
|
|
1576
|
-
sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
|
|
1577
|
-
params: [...ctx.params]
|
|
1578
|
-
};
|
|
1579
|
-
}
|
|
1580
|
-
compileDelete(ast) {
|
|
1581
|
-
const ctx = this.createCompilerContext();
|
|
1582
|
-
const rawSql = this.compileDeleteAst(ast, ctx).trim();
|
|
1583
|
-
return {
|
|
1584
|
-
sql: rawSql.endsWith(";") ? rawSql : `${rawSql};`,
|
|
1585
|
-
params: [...ctx.params]
|
|
1586
|
-
};
|
|
1587
|
-
}
|
|
1588
|
-
supportsDmlReturningClause() {
|
|
1589
|
-
return false;
|
|
1590
|
-
}
|
|
1591
|
-
compileWhere(where, ctx) {
|
|
1592
|
-
if (!where) return "";
|
|
1593
|
-
return ` WHERE ${this.compileExpression(where, ctx)}`;
|
|
1594
|
-
}
|
|
1595
|
-
compileReturning(returning, _ctx) {
|
|
1596
|
-
void _ctx;
|
|
1597
|
-
if (!returning || returning.length === 0) return "";
|
|
1598
|
-
throw new Error("RETURNING is not supported by this dialect.");
|
|
1599
|
-
}
|
|
1600
|
-
compileSelectForExists(ast, ctx) {
|
|
1601
|
-
const normalized = this.normalizeSelectAst(ast);
|
|
1602
|
-
const full = this.compileSelectAst(normalized, ctx).trim().replace(/;$/, "");
|
|
1603
|
-
if (normalized.setOps && normalized.setOps.length > 0) {
|
|
1604
|
-
return `SELECT 1 FROM (${full}) AS _exists`;
|
|
1605
|
-
}
|
|
1606
|
-
const upper2 = full.toUpperCase();
|
|
1607
|
-
const fromIndex = upper2.indexOf(" FROM ");
|
|
1608
|
-
if (fromIndex === -1) return full;
|
|
1609
|
-
return `SELECT 1${full.slice(fromIndex)}`;
|
|
1610
|
-
}
|
|
1611
|
-
createCompilerContext() {
|
|
1612
|
-
const params = [];
|
|
1613
|
-
let counter = 0;
|
|
1614
|
-
return {
|
|
1615
|
-
params,
|
|
1616
|
-
addParameter: (value) => {
|
|
1617
|
-
counter += 1;
|
|
1618
|
-
params.push(value);
|
|
1619
|
-
return this.formatPlaceholder(counter);
|
|
1620
|
-
}
|
|
1621
|
-
};
|
|
1622
|
-
}
|
|
1623
|
-
formatPlaceholder(_index) {
|
|
1624
|
-
void _index;
|
|
1625
|
-
return "?";
|
|
1626
|
-
}
|
|
1627
|
-
supportsSetOperation(_kind) {
|
|
1628
|
-
void _kind;
|
|
1629
|
-
return true;
|
|
1630
|
-
}
|
|
1631
|
-
normalizeSelectAst(ast) {
|
|
1632
|
-
return this.selectAstNormalizer.normalize(ast);
|
|
1633
|
-
}
|
|
1634
|
-
registerExpressionCompiler(type, compiler) {
|
|
1635
|
-
this.expressionCompilerRegistry.registerExpressionCompiler(type, compiler);
|
|
1636
|
-
}
|
|
1637
|
-
registerOperandCompiler(type, compiler) {
|
|
1638
|
-
this.expressionCompilerRegistry.registerOperandCompiler(type, compiler);
|
|
1639
|
-
}
|
|
1640
|
-
compileExpression(node, ctx) {
|
|
1641
|
-
return this.expressionCompilerRegistry.compileExpression(node, ctx);
|
|
1642
|
-
}
|
|
1643
|
-
compileOperand(node, ctx) {
|
|
1644
|
-
return this.expressionCompilerRegistry.compileOperand(node, ctx);
|
|
1645
|
-
}
|
|
1646
|
-
compileOrderingTerm(term, ctx) {
|
|
1647
|
-
return this.expressionCompilerRegistry.compileOrderingTerm(term, ctx);
|
|
1648
|
-
}
|
|
1649
|
-
compileJsonPath(_node) {
|
|
1650
|
-
void _node;
|
|
1651
|
-
throw new Error("JSON Path not supported by this dialect");
|
|
1652
|
-
}
|
|
1653
|
-
compileFunctionOperand(fnNode, ctx) {
|
|
1654
|
-
const compiledArgs = fnNode.args.map((arg) => this.compileOperand(arg, ctx));
|
|
1655
|
-
const renderer = this.functionStrategy.getRenderer(fnNode.name);
|
|
1656
|
-
if (renderer) {
|
|
1657
|
-
return renderer({
|
|
1658
|
-
node: fnNode,
|
|
1659
|
-
compiledArgs,
|
|
1660
|
-
compileOperand: (operand) => this.compileOperand(operand, ctx)
|
|
1661
|
-
});
|
|
1662
|
-
}
|
|
1663
|
-
return `${fnNode.name}(${compiledArgs.join(", ")})`;
|
|
1664
|
-
}
|
|
1665
|
-
/** Creates a minimal dialect implementation for isolated compiler tests. */
|
|
1666
|
-
static create(functionStrategy, tableFunctionStrategy) {
|
|
1667
|
-
class TestDialect extends _DialectBase {
|
|
1668
|
-
dialect = "sqlite";
|
|
1669
|
-
quoteIdentifier(id) {
|
|
1670
|
-
return `"${id}"`;
|
|
1671
|
-
}
|
|
1672
|
-
compileSelectAst() {
|
|
1673
|
-
throw new Error("Not implemented");
|
|
1674
|
-
}
|
|
1675
|
-
compileInsertAst() {
|
|
1676
|
-
throw new Error("Not implemented");
|
|
1677
|
-
}
|
|
1678
|
-
compileUpdateAst() {
|
|
1679
|
-
throw new Error("Not implemented");
|
|
1680
|
-
}
|
|
1681
|
-
compileDeleteAst() {
|
|
1682
|
-
throw new Error("Not implemented");
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
return new TestDialect(functionStrategy, tableFunctionStrategy);
|
|
1686
|
-
}
|
|
1687
|
-
};
|
|
1688
|
-
|
|
1689
1536
|
// src/core/dialect/base/pagination-strategy.ts
|
|
1690
1537
|
var StandardLimitOffsetPagination = class {
|
|
1691
1538
|
/**
|
|
@@ -1710,19 +1557,19 @@ var NoReturningStrategy = class {
|
|
|
1710
1557
|
if (!returning || returning.length === 0) return "";
|
|
1711
1558
|
throw new Error("RETURNING is not supported by this dialect.");
|
|
1712
1559
|
}
|
|
1713
|
-
formatReturningColumns(returning,
|
|
1560
|
+
formatReturningColumns(returning, quoteIdentifier9) {
|
|
1714
1561
|
return returning.map((column) => {
|
|
1715
|
-
const tablePart = column.table ? `${
|
|
1716
|
-
const aliasPart = column.alias ? ` AS ${
|
|
1717
|
-
return `${tablePart}${
|
|
1562
|
+
const tablePart = column.table ? `${quoteIdentifier9(column.table)}.` : "";
|
|
1563
|
+
const aliasPart = column.alias ? ` AS ${quoteIdentifier9(column.alias)}` : "";
|
|
1564
|
+
return `${tablePart}${quoteIdentifier9(column.name)}${aliasPart}`;
|
|
1718
1565
|
}).join(", ");
|
|
1719
1566
|
}
|
|
1720
1567
|
};
|
|
1721
1568
|
var StandardReturningStrategy = class extends NoReturningStrategy {
|
|
1722
|
-
compileReturning(returning, _ctx,
|
|
1569
|
+
compileReturning(returning, _ctx, quoteIdentifier9) {
|
|
1723
1570
|
void _ctx;
|
|
1724
1571
|
if (!returning || returning.length === 0) return "";
|
|
1725
|
-
return ` RETURNING ${this.formatReturningColumns(returning,
|
|
1572
|
+
return ` RETURNING ${this.formatReturningColumns(returning, quoteIdentifier9)}`;
|
|
1726
1573
|
}
|
|
1727
1574
|
};
|
|
1728
1575
|
|
|
@@ -1853,13 +1700,13 @@ var CteCompiler = class {
|
|
|
1853
1700
|
* @param stripTrailingSemicolon - Function to remove trailing semicolons from SQL.
|
|
1854
1701
|
* @returns SQL WITH clause string (e.g., "WITH cte_name AS (...) ") or empty string if no CTEs.
|
|
1855
1702
|
*/
|
|
1856
|
-
static compileCtes(ast, ctx,
|
|
1703
|
+
static compileCtes(ast, ctx, quoteIdentifier9, compileSelectAst, normalizeSelectAst, stripTrailingSemicolon) {
|
|
1857
1704
|
if (!ast.ctes || ast.ctes.length === 0) return "";
|
|
1858
1705
|
const hasRecursive = ast.ctes.some((cte) => cte.recursive);
|
|
1859
1706
|
const prefix = hasRecursive ? "WITH RECURSIVE " : "WITH ";
|
|
1860
1707
|
const cteDefs = ast.ctes.map((cte) => {
|
|
1861
|
-
const name =
|
|
1862
|
-
const cols = cte.columns && cte.columns.length ? `(${cte.columns.map((c) =>
|
|
1708
|
+
const name = quoteIdentifier9(cte.name);
|
|
1709
|
+
const cols = cte.columns && cte.columns.length ? `(${cte.columns.map((c) => quoteIdentifier9(c)).join(", ")})` : "";
|
|
1863
1710
|
const query = stripTrailingSemicolon(compileSelectAst(normalizeSelectAst(cte.query), ctx));
|
|
1864
1711
|
return `${name}${cols} AS (${query})`;
|
|
1865
1712
|
}).join(", ");
|
|
@@ -2082,138 +1929,174 @@ var StandardDeleteCompiler = class {
|
|
|
2082
1929
|
}
|
|
2083
1930
|
};
|
|
2084
1931
|
|
|
2085
|
-
// src/core/dialect/base/sql-dialect.ts
|
|
2086
|
-
var
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
compileUpsertClause: (ast, ctx) => this.compileUpsertClause(ast, ctx),
|
|
2112
|
-
compileSetTarget: (column, table) => this.compileSetTarget(column, table),
|
|
2113
|
-
renderOrderByNulls: (order) => this.renderOrderByNulls(order),
|
|
2114
|
-
renderOrderByCollation: (order) => this.renderOrderByCollation(order)
|
|
2115
|
-
};
|
|
2116
|
-
this.sourceCompiler = new StandardSqlSourceCompiler(services);
|
|
2117
|
-
const standardSelect = new StandardSelectCompiler(services, this.sourceCompiler);
|
|
2118
|
-
const standardInsert = new StandardInsertCompiler(services, this.sourceCompiler);
|
|
2119
|
-
this.standardUpdateCompiler = new StandardUpdateCompiler(services, this.sourceCompiler);
|
|
2120
|
-
const standardDelete = new StandardDeleteCompiler(services, this.sourceCompiler);
|
|
2121
|
-
const overrides = options.compilerFactory?.({
|
|
2122
|
-
services,
|
|
2123
|
-
sources: this.sourceCompiler
|
|
2124
|
-
}) ?? {};
|
|
2125
|
-
this.compilerSet = {
|
|
2126
|
-
select: overrides.select ?? standardSelect,
|
|
2127
|
-
insert: overrides.insert ?? standardInsert,
|
|
2128
|
-
update: overrides.update ?? this.standardUpdateCompiler,
|
|
2129
|
-
delete: overrides.delete ?? standardDelete
|
|
1932
|
+
// src/core/dialect/base/sql-dialect-composer.ts
|
|
1933
|
+
var terminate = (sql) => {
|
|
1934
|
+
const trimmed = sql.trim();
|
|
1935
|
+
return trimmed.endsWith(";") ? trimmed : `${trimmed};`;
|
|
1936
|
+
};
|
|
1937
|
+
var composeSqlDialect = (config) => {
|
|
1938
|
+
const functionStrategy = config.functionStrategy ?? new StandardFunctionStrategy();
|
|
1939
|
+
const tableFunctionStrategy = config.tableFunctionStrategy ?? new StandardTableFunctionStrategy();
|
|
1940
|
+
const paginationStrategy = config.paginationStrategy ?? new StandardLimitOffsetPagination();
|
|
1941
|
+
const returningStrategy = config.returningStrategy ?? new NoReturningStrategy();
|
|
1942
|
+
const upsertStrategy = config.upsertStrategy ?? new NoUpsertStrategy();
|
|
1943
|
+
const selectAstNormalizer = new SelectAstNormalizer(
|
|
1944
|
+
(kind) => config.supportsSetOperation?.(kind) ?? true
|
|
1945
|
+
);
|
|
1946
|
+
let compilerSet;
|
|
1947
|
+
let expressionRegistry2;
|
|
1948
|
+
const createCompilerContext = () => {
|
|
1949
|
+
const params = [];
|
|
1950
|
+
let counter = 0;
|
|
1951
|
+
return {
|
|
1952
|
+
params,
|
|
1953
|
+
addParameter(value) {
|
|
1954
|
+
counter += 1;
|
|
1955
|
+
params.push(value);
|
|
1956
|
+
return config.formatPlaceholder?.(counter) ?? "?";
|
|
1957
|
+
}
|
|
2130
1958
|
};
|
|
2131
|
-
}
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
}
|
|
2169
|
-
compileSetTarget(column, table) {
|
|
2170
|
-
return
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
}
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
}
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
1959
|
+
};
|
|
1960
|
+
const compileSelectAst = (ast, ctx) => compilerSet.select.compile(ast, ctx);
|
|
1961
|
+
const normalizeSelectAst = (ast) => selectAstNormalizer.normalize(ast);
|
|
1962
|
+
const compileSelectForExists = (ast, ctx) => {
|
|
1963
|
+
const normalized = normalizeSelectAst(ast);
|
|
1964
|
+
const full = compileSelectAst(normalized, ctx).trim().replace(/;$/, "");
|
|
1965
|
+
if (normalized.setOps && normalized.setOps.length > 0) {
|
|
1966
|
+
return `SELECT 1 FROM (${full}) AS _exists`;
|
|
1967
|
+
}
|
|
1968
|
+
const fromIndex = full.toUpperCase().indexOf(" FROM ");
|
|
1969
|
+
return fromIndex === -1 ? full : `SELECT 1${full.slice(fromIndex)}`;
|
|
1970
|
+
};
|
|
1971
|
+
const compileJsonPath = (node) => {
|
|
1972
|
+
if (!config.compileJsonPath) {
|
|
1973
|
+
throw new Error(`JSON Path not supported by dialect "${config.name}".`);
|
|
1974
|
+
}
|
|
1975
|
+
return config.compileJsonPath(node);
|
|
1976
|
+
};
|
|
1977
|
+
const compileFunctionOperand = (node, ctx) => {
|
|
1978
|
+
const compiledArgs = node.args.map((arg) => expressionRegistry2.compileOperand(arg, ctx));
|
|
1979
|
+
const renderer = functionStrategy.getRenderer(node.name);
|
|
1980
|
+
if (renderer) {
|
|
1981
|
+
return renderer({
|
|
1982
|
+
node,
|
|
1983
|
+
compiledArgs,
|
|
1984
|
+
compileOperand: (operand) => expressionRegistry2.compileOperand(operand, ctx)
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
return `${node.name}(${compiledArgs.join(", ")})`;
|
|
1988
|
+
};
|
|
1989
|
+
expressionRegistry2 = new ExpressionCompilerRegistry({
|
|
1990
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
1991
|
+
compileSelectAst,
|
|
1992
|
+
compileSelectForExists,
|
|
1993
|
+
compileJsonPath,
|
|
1994
|
+
compileFunctionOperand,
|
|
1995
|
+
describe: () => config.describe ?? config.name
|
|
1996
|
+
});
|
|
1997
|
+
const compileSetTarget = (column, table) => {
|
|
1998
|
+
if (config.compileSetTarget) return config.compileSetTarget(column, table);
|
|
1999
|
+
const columnTable = column.table ?? table.alias ?? table.name;
|
|
2000
|
+
const tableQualifier = table.alias && column.table === table.name ? table.alias : columnTable;
|
|
2001
|
+
return tableQualifier ? `${config.quoteIdentifier(tableQualifier)}.${config.quoteIdentifier(column.name)}` : config.quoteIdentifier(column.name);
|
|
2002
|
+
};
|
|
2003
|
+
let standardUpdate;
|
|
2004
|
+
const services = {
|
|
2005
|
+
getDialectName: () => config.name,
|
|
2006
|
+
getPaginationStrategy: () => paginationStrategy,
|
|
2007
|
+
getTableFunctionStrategy: () => tableFunctionStrategy,
|
|
2008
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
2009
|
+
compileOperand: (node, ctx) => expressionRegistry2.compileOperand(node, ctx),
|
|
2010
|
+
compileExpression: (node, ctx) => expressionRegistry2.compileExpression(node, ctx),
|
|
2011
|
+
compileOrderingTerm: (term, ctx) => expressionRegistry2.compileOrderingTerm(term, ctx),
|
|
2012
|
+
normalizeSelectAst,
|
|
2013
|
+
compileSelectAst,
|
|
2014
|
+
compileReturning: (returning, ctx) => returningStrategy.compileReturning(returning, ctx, config.quoteIdentifier),
|
|
2015
|
+
compileUpsertClause: (ast, ctx) => upsertStrategy.compile(ast, ctx, {
|
|
2016
|
+
getDialectName: () => config.name,
|
|
2017
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
2018
|
+
compileOperand: (node, compilerContext) => expressionRegistry2.compileOperand(node, compilerContext),
|
|
2019
|
+
compileExpression: (node, compilerContext) => expressionRegistry2.compileExpression(node, compilerContext),
|
|
2020
|
+
compileUpdateAssignments: (assignments, table, compilerContext) => standardUpdate.compileAssignments(assignments, table, compilerContext)
|
|
2021
|
+
}),
|
|
2022
|
+
compileSetTarget,
|
|
2023
|
+
renderOrderByNulls: (order) => config.renderOrderByNulls?.(order) ?? (order.nulls ? ` NULLS ${order.nulls}` : ""),
|
|
2024
|
+
renderOrderByCollation: (order) => config.renderOrderByCollation?.(order) ?? (order.collation ? ` COLLATE ${order.collation}` : "")
|
|
2025
|
+
};
|
|
2026
|
+
const sources = new StandardSqlSourceCompiler(services);
|
|
2027
|
+
const standardSelect = new StandardSelectCompiler(services, sources);
|
|
2028
|
+
const standardInsert = new StandardInsertCompiler(services, sources);
|
|
2029
|
+
standardUpdate = new StandardUpdateCompiler(services, sources);
|
|
2030
|
+
const standardDelete = new StandardDeleteCompiler(services, sources);
|
|
2031
|
+
const overrides = config.compilerFactory?.({ services, sources }) ?? {};
|
|
2032
|
+
compilerSet = {
|
|
2033
|
+
select: overrides.select ?? standardSelect,
|
|
2034
|
+
insert: overrides.insert ?? standardInsert,
|
|
2035
|
+
update: overrides.update ?? standardUpdate,
|
|
2036
|
+
delete: overrides.delete ?? standardDelete
|
|
2037
|
+
};
|
|
2038
|
+
const expressionApi = {
|
|
2039
|
+
registerExpressionCompiler(type, compiler) {
|
|
2040
|
+
expressionRegistry2.registerExpressionCompiler(type, compiler);
|
|
2041
|
+
},
|
|
2042
|
+
registerOperandCompiler(type, compiler) {
|
|
2043
|
+
expressionRegistry2.registerOperandCompiler(type, compiler);
|
|
2044
|
+
},
|
|
2045
|
+
compileExpression(node, ctx) {
|
|
2046
|
+
return expressionRegistry2.compileExpression(node, ctx);
|
|
2047
|
+
},
|
|
2048
|
+
compileOperand(node, ctx) {
|
|
2049
|
+
return expressionRegistry2.compileOperand(node, ctx);
|
|
2050
|
+
},
|
|
2051
|
+
compileOrderingTerm(term, ctx) {
|
|
2052
|
+
return expressionRegistry2.compileOrderingTerm(term, ctx);
|
|
2053
|
+
}
|
|
2054
|
+
};
|
|
2055
|
+
config.configureExpressions?.(expressionApi);
|
|
2056
|
+
const dialect = {
|
|
2057
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
2058
|
+
supportsDmlReturningClause: () => config.supportsDmlReturning ?? false,
|
|
2059
|
+
compileSelect(ast) {
|
|
2060
|
+
const ctx = createCompilerContext();
|
|
2061
|
+
return {
|
|
2062
|
+
sql: terminate(compileSelectAst(normalizeSelectAst(ast), ctx)),
|
|
2063
|
+
params: [...ctx.params]
|
|
2064
|
+
};
|
|
2065
|
+
},
|
|
2066
|
+
compileInsert(ast) {
|
|
2067
|
+
const ctx = createCompilerContext();
|
|
2068
|
+
return {
|
|
2069
|
+
sql: terminate(compilerSet.insert.compile(ast, ctx)),
|
|
2070
|
+
params: [...ctx.params]
|
|
2071
|
+
};
|
|
2072
|
+
},
|
|
2073
|
+
compileUpdate(ast) {
|
|
2074
|
+
const ctx = createCompilerContext();
|
|
2075
|
+
return {
|
|
2076
|
+
sql: terminate(compilerSet.update.compile(ast, ctx)),
|
|
2077
|
+
params: [...ctx.params]
|
|
2078
|
+
};
|
|
2079
|
+
},
|
|
2080
|
+
compileDelete(ast) {
|
|
2081
|
+
const ctx = createCompilerContext();
|
|
2082
|
+
return {
|
|
2083
|
+
sql: terminate(compilerSet.delete.compile(ast, ctx)),
|
|
2084
|
+
params: [...ctx.params]
|
|
2085
|
+
};
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
const runtime = {
|
|
2089
|
+
quoteIdentifier: config.quoteIdentifier,
|
|
2090
|
+
createCompilerContext,
|
|
2091
|
+
compileOperand: (node, ctx) => expressionRegistry2.compileOperand(node, ctx),
|
|
2092
|
+
compileExpression: (node, ctx) => expressionRegistry2.compileExpression(node, ctx),
|
|
2093
|
+
compileOrderingTerm: (term, ctx) => expressionRegistry2.compileOrderingTerm(term, ctx),
|
|
2094
|
+
normalizeSelectAst,
|
|
2095
|
+
compileSelectAst
|
|
2096
|
+
};
|
|
2097
|
+
return { dialect, runtime };
|
|
2216
2098
|
};
|
|
2099
|
+
var createSqlDialect = (config) => composeSqlDialect(config).dialect;
|
|
2217
2100
|
|
|
2218
2101
|
// src/core/dialect/postgres/functions.ts
|
|
2219
2102
|
var PostgresFunctionStrategy = class extends StandardFunctionStrategy {
|
|
@@ -2376,15 +2259,15 @@ var PostgresTableFunctionStrategy = class extends StandardTableFunctionStrategy
|
|
|
2376
2259
|
this.registerOverrides();
|
|
2377
2260
|
}
|
|
2378
2261
|
registerOverrides() {
|
|
2379
|
-
this.add("ARRAY_UNNEST", ({ node, compiledArgs, quoteIdentifier }) => {
|
|
2262
|
+
this.add("ARRAY_UNNEST", ({ node, compiledArgs, quoteIdentifier: quoteIdentifier9 }) => {
|
|
2380
2263
|
const lateral = node.lateral ?? true;
|
|
2381
2264
|
const withOrd = node.withOrdinality ?? false;
|
|
2382
2265
|
const base = `unnest(${compiledArgs.join(", ")})${withOrd ? " WITH ORDINALITY" : ""}`;
|
|
2383
2266
|
if (node.columnAliases?.length && !node.alias) {
|
|
2384
2267
|
throw new Error("tvf(ARRAY_UNNEST) with columnAliases requires an alias.");
|
|
2385
2268
|
}
|
|
2386
|
-
const alias = node.alias ? ` AS ${
|
|
2387
|
-
const cols = node.columnAliases?.length ? `(${node.columnAliases.map(
|
|
2269
|
+
const alias = node.alias ? ` AS ${quoteIdentifier9(node.alias)}` : "";
|
|
2270
|
+
const cols = node.columnAliases?.length ? `(${node.columnAliases.map(quoteIdentifier9).join(", ")})` : "";
|
|
2388
2271
|
return `${lateral ? "LATERAL " : ""}${base}${alias}${cols}`;
|
|
2389
2272
|
});
|
|
2390
2273
|
}
|
|
@@ -2449,52 +2332,68 @@ var PostgresUpsertStrategy = class {
|
|
|
2449
2332
|
};
|
|
2450
2333
|
|
|
2451
2334
|
// src/core/dialect/postgres/index.ts
|
|
2452
|
-
var
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2335
|
+
var quoteIdentifier = (id) => `"${id}"`;
|
|
2336
|
+
var createPostgresDialect = () => {
|
|
2337
|
+
const composition = composeSqlDialect({
|
|
2338
|
+
name: "postgres",
|
|
2339
|
+
quoteIdentifier,
|
|
2340
|
+
formatPlaceholder: (index) => `$${index}`,
|
|
2341
|
+
functionStrategy: new PostgresFunctionStrategy(),
|
|
2342
|
+
tableFunctionStrategy: new PostgresTableFunctionStrategy(),
|
|
2343
|
+
returningStrategy: new PostgresReturningStrategy(),
|
|
2344
|
+
upsertStrategy: new PostgresUpsertStrategy(),
|
|
2345
|
+
supportsDmlReturning: true,
|
|
2346
|
+
compileSetTarget: (column, _table) => {
|
|
2347
|
+
void _table;
|
|
2348
|
+
return quoteIdentifier(column.name);
|
|
2349
|
+
},
|
|
2350
|
+
compileJsonPath(node) {
|
|
2351
|
+
const column = `${quoteIdentifier(node.column.table)}.${quoteIdentifier(node.column.name)}`;
|
|
2352
|
+
return `${column}->>'${node.path}'`;
|
|
2353
|
+
},
|
|
2354
|
+
configureExpressions(api) {
|
|
2355
|
+
api.registerExpressionCompiler("BitwiseExpression", (node, ctx) => {
|
|
2356
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
2357
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
2358
|
+
const operator = node.operator === "^" ? "#" : node.operator;
|
|
2359
|
+
return `${left2} ${operator} ${right2}`;
|
|
2360
|
+
});
|
|
2361
|
+
api.registerOperandCompiler("BitwiseExpression", (node, ctx) => {
|
|
2362
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
2363
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
2364
|
+
const operator = node.operator === "^" ? "#" : node.operator;
|
|
2365
|
+
return `(${left2} ${operator} ${right2})`;
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
});
|
|
2369
|
+
const procedures = new PostgresProcedureCompiler(composition.runtime);
|
|
2370
|
+
return {
|
|
2371
|
+
...composition.dialect,
|
|
2372
|
+
compileProcedureCall: (ast) => procedures.compileProcedureCall(ast)
|
|
2373
|
+
};
|
|
2374
|
+
};
|
|
2375
|
+
var PostgresDialect = class {
|
|
2376
|
+
impl = createPostgresDialect();
|
|
2481
2377
|
quoteIdentifier(id) {
|
|
2482
|
-
return
|
|
2378
|
+
return this.impl.quoteIdentifier(id);
|
|
2483
2379
|
}
|
|
2484
|
-
|
|
2485
|
-
return
|
|
2380
|
+
supportsDmlReturningClause() {
|
|
2381
|
+
return this.impl.supportsDmlReturningClause();
|
|
2486
2382
|
}
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
return `${column}->>'${node.path}'`;
|
|
2383
|
+
compileSelect(ast) {
|
|
2384
|
+
return this.impl.compileSelect(ast);
|
|
2490
2385
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2386
|
+
compileInsert(ast) {
|
|
2387
|
+
return this.impl.compileInsert(ast);
|
|
2388
|
+
}
|
|
2389
|
+
compileUpdate(ast) {
|
|
2390
|
+
return this.impl.compileUpdate(ast);
|
|
2391
|
+
}
|
|
2392
|
+
compileDelete(ast) {
|
|
2393
|
+
return this.impl.compileDelete(ast);
|
|
2495
2394
|
}
|
|
2496
2395
|
compileProcedureCall(ast) {
|
|
2497
|
-
return this.
|
|
2396
|
+
return this.impl.compileProcedureCall(ast);
|
|
2498
2397
|
}
|
|
2499
2398
|
};
|
|
2500
2399
|
|
|
@@ -2674,38 +2573,57 @@ var MySqlUpsertStrategy = class {
|
|
|
2674
2573
|
};
|
|
2675
2574
|
|
|
2676
2575
|
// src/core/dialect/mysql/index.ts
|
|
2677
|
-
var
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
}
|
|
2576
|
+
var quoteIdentifier2 = (id) => `\`${id}\``;
|
|
2577
|
+
var createMySqlDialect = () => {
|
|
2578
|
+
const composition = composeSqlDialect({
|
|
2579
|
+
name: "mysql",
|
|
2580
|
+
quoteIdentifier: quoteIdentifier2,
|
|
2581
|
+
functionStrategy: new MysqlFunctionStrategy(),
|
|
2582
|
+
upsertStrategy: new MySqlUpsertStrategy(),
|
|
2583
|
+
compileJsonPath(node) {
|
|
2584
|
+
const column = `${quoteIdentifier2(node.column.table)}.${quoteIdentifier2(node.column.name)}`;
|
|
2585
|
+
return `${column}->'${node.path}'`;
|
|
2586
|
+
},
|
|
2587
|
+
configureExpressions(api) {
|
|
2588
|
+
api.registerExpressionCompiler(
|
|
2589
|
+
"IsDistinctExpression",
|
|
2590
|
+
(node, ctx) => {
|
|
2591
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
2592
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
2593
|
+
const spaceship = `${left2} <=> ${right2}`;
|
|
2594
|
+
return node.operator === "IS NOT DISTINCT FROM" ? spaceship : `NOT (${spaceship})`;
|
|
2595
|
+
}
|
|
2596
|
+
);
|
|
2597
|
+
}
|
|
2598
|
+
});
|
|
2599
|
+
const procedures = new MySqlProcedureCompiler(composition.runtime);
|
|
2600
|
+
return {
|
|
2601
|
+
...composition.dialect,
|
|
2602
|
+
compileProcedureCall: (ast) => procedures.compileProcedureCall(ast)
|
|
2603
|
+
};
|
|
2604
|
+
};
|
|
2605
|
+
var MySqlDialect = class {
|
|
2606
|
+
impl = createMySqlDialect();
|
|
2700
2607
|
quoteIdentifier(id) {
|
|
2701
|
-
return
|
|
2608
|
+
return this.impl.quoteIdentifier(id);
|
|
2702
2609
|
}
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2610
|
+
supportsDmlReturningClause() {
|
|
2611
|
+
return this.impl.supportsDmlReturningClause();
|
|
2612
|
+
}
|
|
2613
|
+
compileSelect(ast) {
|
|
2614
|
+
return this.impl.compileSelect(ast);
|
|
2615
|
+
}
|
|
2616
|
+
compileInsert(ast) {
|
|
2617
|
+
return this.impl.compileInsert(ast);
|
|
2618
|
+
}
|
|
2619
|
+
compileUpdate(ast) {
|
|
2620
|
+
return this.impl.compileUpdate(ast);
|
|
2621
|
+
}
|
|
2622
|
+
compileDelete(ast) {
|
|
2623
|
+
return this.impl.compileDelete(ast);
|
|
2706
2624
|
}
|
|
2707
2625
|
compileProcedureCall(ast) {
|
|
2708
|
-
return this.
|
|
2626
|
+
return this.impl.compileProcedureCall(ast);
|
|
2709
2627
|
}
|
|
2710
2628
|
};
|
|
2711
2629
|
|
|
@@ -2848,15 +2766,15 @@ var SqliteFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
2848
2766
|
|
|
2849
2767
|
// src/core/dialect/sqlite/returning.ts
|
|
2850
2768
|
var SqliteReturningStrategy = class {
|
|
2851
|
-
compileReturning(returning, _ctx,
|
|
2769
|
+
compileReturning(returning, _ctx, quoteIdentifier9) {
|
|
2852
2770
|
void _ctx;
|
|
2853
2771
|
if (!returning || returning.length === 0) return "";
|
|
2854
|
-
return ` RETURNING ${this.formatReturningColumns(returning,
|
|
2772
|
+
return ` RETURNING ${this.formatReturningColumns(returning, quoteIdentifier9)}`;
|
|
2855
2773
|
}
|
|
2856
|
-
formatReturningColumns(returning,
|
|
2774
|
+
formatReturningColumns(returning, quoteIdentifier9) {
|
|
2857
2775
|
return returning.map((column) => {
|
|
2858
|
-
const alias = column.alias ? ` AS ${
|
|
2859
|
-
return `${
|
|
2776
|
+
const alias = column.alias ? ` AS ${quoteIdentifier9(column.alias)}` : "";
|
|
2777
|
+
return `${quoteIdentifier9(column.name)}${alias}`;
|
|
2860
2778
|
}).join(", ");
|
|
2861
2779
|
}
|
|
2862
2780
|
};
|
|
@@ -2887,42 +2805,60 @@ var SqliteUpsertStrategy = class {
|
|
|
2887
2805
|
};
|
|
2888
2806
|
|
|
2889
2807
|
// src/core/dialect/sqlite/index.ts
|
|
2890
|
-
var
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2808
|
+
var quoteIdentifier3 = (id) => `"${id}"`;
|
|
2809
|
+
var createSqliteDialect = () => composeSqlDialect({
|
|
2810
|
+
name: "sqlite",
|
|
2811
|
+
quoteIdentifier: quoteIdentifier3,
|
|
2812
|
+
functionStrategy: new SqliteFunctionStrategy(),
|
|
2813
|
+
returningStrategy: new SqliteReturningStrategy(),
|
|
2814
|
+
upsertStrategy: new SqliteUpsertStrategy(),
|
|
2815
|
+
supportsDmlReturning: true,
|
|
2816
|
+
compileSetTarget: (column, _table) => {
|
|
2817
|
+
void _table;
|
|
2818
|
+
return quoteIdentifier3(column.name);
|
|
2819
|
+
},
|
|
2820
|
+
compileJsonPath(node) {
|
|
2821
|
+
const column = `${quoteIdentifier3(node.column.table)}.${quoteIdentifier3(node.column.name)}`;
|
|
2822
|
+
return `json_extract(${column}, '${node.path}')`;
|
|
2823
|
+
},
|
|
2824
|
+
configureExpressions(api) {
|
|
2825
|
+
api.registerExpressionCompiler("BitwiseExpression", (node, ctx) => {
|
|
2826
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
2827
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
2902
2828
|
if (node.operator === "^") {
|
|
2903
2829
|
return `(${left2} | ${right2}) & ~(${left2} & ${right2})`;
|
|
2904
2830
|
}
|
|
2905
2831
|
return `${left2} ${node.operator} ${right2}`;
|
|
2906
2832
|
});
|
|
2907
|
-
|
|
2908
|
-
const left2 =
|
|
2909
|
-
const right2 =
|
|
2833
|
+
api.registerOperandCompiler("BitwiseExpression", (node, ctx) => {
|
|
2834
|
+
const left2 = api.compileOperand(node.left, ctx);
|
|
2835
|
+
const right2 = api.compileOperand(node.right, ctx);
|
|
2910
2836
|
if (node.operator === "^") {
|
|
2911
2837
|
return `((${left2} | ${right2}) & ~(${left2} & ${right2}))`;
|
|
2912
2838
|
}
|
|
2913
2839
|
return `(${left2} ${node.operator} ${right2})`;
|
|
2914
2840
|
});
|
|
2915
2841
|
}
|
|
2842
|
+
}).dialect;
|
|
2843
|
+
var SqliteDialect = class {
|
|
2844
|
+
impl = createSqliteDialect();
|
|
2916
2845
|
quoteIdentifier(id) {
|
|
2917
|
-
return
|
|
2846
|
+
return this.impl.quoteIdentifier(id);
|
|
2918
2847
|
}
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
return `json_extract(${column}, '${node.path}')`;
|
|
2848
|
+
supportsDmlReturningClause() {
|
|
2849
|
+
return this.impl.supportsDmlReturningClause();
|
|
2922
2850
|
}
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2851
|
+
compileSelect(ast) {
|
|
2852
|
+
return this.impl.compileSelect(ast);
|
|
2853
|
+
}
|
|
2854
|
+
compileInsert(ast) {
|
|
2855
|
+
return this.impl.compileInsert(ast);
|
|
2856
|
+
}
|
|
2857
|
+
compileUpdate(ast) {
|
|
2858
|
+
return this.impl.compileUpdate(ast);
|
|
2859
|
+
}
|
|
2860
|
+
compileDelete(ast) {
|
|
2861
|
+
return this.impl.compileDelete(ast);
|
|
2926
2862
|
}
|
|
2927
2863
|
};
|
|
2928
2864
|
|
|
@@ -3052,22 +2988,22 @@ var MssqlFunctionStrategy = class extends StandardFunctionStrategy {
|
|
|
3052
2988
|
|
|
3053
2989
|
// src/core/dialect/mssql/output.ts
|
|
3054
2990
|
var MssqlOutputStrategy = class {
|
|
3055
|
-
compileReturning(returning, _ctx,
|
|
2991
|
+
compileReturning(returning, _ctx, quoteIdentifier9) {
|
|
3056
2992
|
void _ctx;
|
|
3057
|
-
return this.compileOutput(returning, "inserted",
|
|
2993
|
+
return this.compileOutput(returning, "inserted", quoteIdentifier9);
|
|
3058
2994
|
}
|
|
3059
|
-
compileOutput(returning, prefix,
|
|
2995
|
+
compileOutput(returning, prefix, quoteIdentifier9) {
|
|
3060
2996
|
if (!returning || returning.length === 0) return "";
|
|
3061
2997
|
const columns = returning.map((column) => {
|
|
3062
|
-
const alias = column.alias ? ` AS ${
|
|
3063
|
-
return `${prefix}.${
|
|
2998
|
+
const alias = column.alias ? ` AS ${quoteIdentifier9(column.alias)}` : "";
|
|
2999
|
+
return `${prefix}.${quoteIdentifier9(column.name)}${alias}`;
|
|
3064
3000
|
}).join(", ");
|
|
3065
3001
|
return ` OUTPUT ${columns}`;
|
|
3066
3002
|
}
|
|
3067
|
-
formatReturningColumns(returning,
|
|
3003
|
+
formatReturningColumns(returning, quoteIdentifier9) {
|
|
3068
3004
|
return returning.map((column) => {
|
|
3069
|
-
const alias = column.alias ? ` AS ${
|
|
3070
|
-
return `${
|
|
3005
|
+
const alias = column.alias ? ` AS ${quoteIdentifier9(column.alias)}` : "";
|
|
3006
|
+
return `${quoteIdentifier9(column.name)}${alias}`;
|
|
3071
3007
|
}).join(", ");
|
|
3072
3008
|
}
|
|
3073
3009
|
};
|
|
@@ -3349,34 +3285,49 @@ var MssqlProcedureCompiler = class {
|
|
|
3349
3285
|
};
|
|
3350
3286
|
|
|
3351
3287
|
// src/core/dialect/mssql/index.ts
|
|
3352
|
-
var
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3288
|
+
var quoteIdentifier4 = (id) => `[${id}]`;
|
|
3289
|
+
var createSqlServerDialect = () => {
|
|
3290
|
+
const composition = composeSqlDialect({
|
|
3291
|
+
name: "mssql",
|
|
3292
|
+
quoteIdentifier: quoteIdentifier4,
|
|
3293
|
+
formatPlaceholder: (index) => `@p${index}`,
|
|
3294
|
+
functionStrategy: new MssqlFunctionStrategy(),
|
|
3295
|
+
returningStrategy: new MssqlOutputStrategy(),
|
|
3296
|
+
compilerFactory: createMssqlCompilerSet,
|
|
3297
|
+
supportsDmlReturning: true,
|
|
3298
|
+
compileJsonPath(node) {
|
|
3299
|
+
const column = `${quoteIdentifier4(node.column.table)}.${quoteIdentifier4(node.column.name)}`;
|
|
3300
|
+
return `JSON_VALUE(${column}, '${node.path}')`;
|
|
3301
|
+
}
|
|
3302
|
+
});
|
|
3303
|
+
const procedures = new MssqlProcedureCompiler(composition.runtime);
|
|
3304
|
+
return {
|
|
3305
|
+
...composition.dialect,
|
|
3306
|
+
compileProcedureCall: (ast) => procedures.compileProcedureCall(ast)
|
|
3307
|
+
};
|
|
3308
|
+
};
|
|
3309
|
+
var SqlServerDialect = class {
|
|
3310
|
+
impl = createSqlServerDialect();
|
|
3368
3311
|
quoteIdentifier(id) {
|
|
3369
|
-
return
|
|
3312
|
+
return this.impl.quoteIdentifier(id);
|
|
3370
3313
|
}
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
return `JSON_VALUE(${column}, '${node.path}')`;
|
|
3314
|
+
supportsDmlReturningClause() {
|
|
3315
|
+
return this.impl.supportsDmlReturningClause();
|
|
3374
3316
|
}
|
|
3375
|
-
|
|
3376
|
-
return
|
|
3317
|
+
compileSelect(ast) {
|
|
3318
|
+
return this.impl.compileSelect(ast);
|
|
3319
|
+
}
|
|
3320
|
+
compileInsert(ast) {
|
|
3321
|
+
return this.impl.compileInsert(ast);
|
|
3322
|
+
}
|
|
3323
|
+
compileUpdate(ast) {
|
|
3324
|
+
return this.impl.compileUpdate(ast);
|
|
3325
|
+
}
|
|
3326
|
+
compileDelete(ast) {
|
|
3327
|
+
return this.impl.compileDelete(ast);
|
|
3377
3328
|
}
|
|
3378
3329
|
compileProcedureCall(ast) {
|
|
3379
|
-
return this.
|
|
3330
|
+
return this.impl.compileProcedureCall(ast);
|
|
3380
3331
|
}
|
|
3381
3332
|
};
|
|
3382
3333
|
|
|
@@ -3387,59 +3338,33 @@ var DialectFactory = class {
|
|
|
3387
3338
|
static ensureDefaults() {
|
|
3388
3339
|
if (this.defaultsInitialized) return;
|
|
3389
3340
|
this.defaultsInitialized = true;
|
|
3390
|
-
if (!this.registry.has("postgres"))
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
if (!this.registry.has("
|
|
3394
|
-
this.registry.set("mysql", () => new MySqlDialect());
|
|
3395
|
-
}
|
|
3396
|
-
if (!this.registry.has("sqlite")) {
|
|
3397
|
-
this.registry.set("sqlite", () => new SqliteDialect());
|
|
3398
|
-
}
|
|
3399
|
-
if (!this.registry.has("mssql")) {
|
|
3400
|
-
this.registry.set("mssql", () => new SqlServerDialect());
|
|
3401
|
-
}
|
|
3341
|
+
if (!this.registry.has("postgres")) this.registry.set("postgres", createPostgresDialect);
|
|
3342
|
+
if (!this.registry.has("mysql")) this.registry.set("mysql", createMySqlDialect);
|
|
3343
|
+
if (!this.registry.has("sqlite")) this.registry.set("sqlite", createSqliteDialect);
|
|
3344
|
+
if (!this.registry.has("mssql")) this.registry.set("mssql", createSqlServerDialect);
|
|
3402
3345
|
}
|
|
3403
|
-
/**
|
|
3404
|
-
* Register (or override) a dialect factory for a key.
|
|
3405
|
-
*
|
|
3406
|
-
* Implementations are structural: extending DialectBase/SqlDialectBase is
|
|
3407
|
-
* optional. A composed object satisfying Dialect is a valid registration.
|
|
3408
|
-
*/
|
|
3346
|
+
/** Register or replace a structural dialect factory. */
|
|
3409
3347
|
static register(key, factory) {
|
|
3410
3348
|
this.registry.set(key, factory);
|
|
3411
3349
|
}
|
|
3412
|
-
/**
|
|
3413
|
-
* Resolve a key into a Dialect instance.
|
|
3414
|
-
* Throws if the key is not registered.
|
|
3415
|
-
*/
|
|
3350
|
+
/** Resolve a key into a new Dialect instance. */
|
|
3416
3351
|
static create(key) {
|
|
3417
3352
|
this.ensureDefaults();
|
|
3418
3353
|
const factory = this.registry.get(key);
|
|
3419
3354
|
if (!factory) {
|
|
3420
3355
|
throw new Error(
|
|
3421
|
-
`Dialect "${String(
|
|
3422
|
-
key
|
|
3423
|
-
)}" is not registered. Use DialectFactory.register(...) to register it.`
|
|
3356
|
+
`Dialect "${String(key)}" is not registered. Use DialectFactory.register(...) to register it.`
|
|
3424
3357
|
);
|
|
3425
3358
|
}
|
|
3426
3359
|
return factory();
|
|
3427
3360
|
}
|
|
3428
|
-
/**
|
|
3429
|
-
* Clear all registrations (mainly for tests).
|
|
3430
|
-
* Built-ins will be re-registered lazily on the next create().
|
|
3431
|
-
*/
|
|
3361
|
+
/** Clear registrations; built-ins are restored lazily on the next create(). */
|
|
3432
3362
|
static clear() {
|
|
3433
3363
|
this.registry.clear();
|
|
3434
3364
|
this.defaultsInitialized = false;
|
|
3435
3365
|
}
|
|
3436
3366
|
};
|
|
3437
|
-
var resolveDialectInput = (dialect) =>
|
|
3438
|
-
if (typeof dialect === "string") {
|
|
3439
|
-
return DialectFactory.create(dialect);
|
|
3440
|
-
}
|
|
3441
|
-
return dialect;
|
|
3442
|
-
};
|
|
3367
|
+
var resolveDialectInput = (dialect) => typeof dialect === "string" ? DialectFactory.create(dialect) : dialect;
|
|
3443
3368
|
|
|
3444
3369
|
// src/core/ast/builders.ts
|
|
3445
3370
|
var isColumnNode = (col2) => "type" in col2 && col2.type === "Column";
|
|
@@ -11149,6 +11074,59 @@ var deleteFrom = (target) => {
|
|
|
11149
11074
|
};
|
|
11150
11075
|
|
|
11151
11076
|
// src/core/ddl/sql-writing.ts
|
|
11077
|
+
var escapeSqlString = (value) => value.replace(/'/g, "''");
|
|
11078
|
+
var isRawDefault = (value) => typeof value === "object" && value !== null && "raw" in value && typeof value.raw === "string";
|
|
11079
|
+
var createLiteralFormatter = (options = {}) => {
|
|
11080
|
+
const {
|
|
11081
|
+
nullLiteral = "NULL",
|
|
11082
|
+
booleanTrue = "TRUE",
|
|
11083
|
+
booleanFalse = "FALSE",
|
|
11084
|
+
numberFormatter = (value) => Number.isFinite(value) ? String(value) : nullLiteral,
|
|
11085
|
+
dateFormatter = (value) => `'${escapeSqlString(value.toISOString())}'`,
|
|
11086
|
+
stringWrapper = (escaped) => `'${escaped}'`,
|
|
11087
|
+
jsonWrapper = (escaped) => `'${escaped}'`
|
|
11088
|
+
} = options;
|
|
11089
|
+
const wrapString = stringWrapper;
|
|
11090
|
+
const wrapJson = jsonWrapper;
|
|
11091
|
+
const format = (value) => {
|
|
11092
|
+
if (isRawDefault(value)) return value.raw;
|
|
11093
|
+
if (value === null) return nullLiteral;
|
|
11094
|
+
if (typeof value === "number") {
|
|
11095
|
+
return numberFormatter(value);
|
|
11096
|
+
}
|
|
11097
|
+
if (typeof value === "boolean") {
|
|
11098
|
+
return value ? booleanTrue : booleanFalse;
|
|
11099
|
+
}
|
|
11100
|
+
if (value instanceof Date) {
|
|
11101
|
+
return dateFormatter(value);
|
|
11102
|
+
}
|
|
11103
|
+
if (typeof value === "string") {
|
|
11104
|
+
return wrapString(escapeSqlString(value));
|
|
11105
|
+
}
|
|
11106
|
+
return wrapJson(escapeSqlString(JSON.stringify(value)));
|
|
11107
|
+
};
|
|
11108
|
+
return {
|
|
11109
|
+
formatLiteral: format
|
|
11110
|
+
};
|
|
11111
|
+
};
|
|
11112
|
+
var formatLiteral = (formatter, value) => formatter.formatLiteral(value);
|
|
11113
|
+
var quoteQualified = (quoter, identifier) => {
|
|
11114
|
+
const parts = identifier.split(".");
|
|
11115
|
+
return parts.map((part) => quoter.quoteIdentifier(part)).join(".");
|
|
11116
|
+
};
|
|
11117
|
+
var renderIndexColumns = (quoter, columns) => columns.map((col2) => {
|
|
11118
|
+
if (typeof col2 === "string") {
|
|
11119
|
+
return quoter.quoteIdentifier(col2);
|
|
11120
|
+
}
|
|
11121
|
+
const parts = [quoter.quoteIdentifier(col2.column)];
|
|
11122
|
+
if (col2.order) {
|
|
11123
|
+
parts.push(col2.order);
|
|
11124
|
+
}
|
|
11125
|
+
if (col2.nulls) {
|
|
11126
|
+
parts.push(`NULLS ${col2.nulls}`);
|
|
11127
|
+
}
|
|
11128
|
+
return parts.join(" ");
|
|
11129
|
+
}).join(", ");
|
|
11152
11130
|
var resolvePrimaryKey = (table) => {
|
|
11153
11131
|
if (Array.isArray(table.primaryKey) && table.primaryKey.length > 0) {
|
|
11154
11132
|
return table.primaryKey;
|
|
@@ -11285,13 +11263,11 @@ var deriveIndexName = (table, index) => {
|
|
|
11285
11263
|
var tableKey = (name, schema) => schema ? `${schema}.${name}` : name;
|
|
11286
11264
|
var mapTables = (schema) => {
|
|
11287
11265
|
const map = /* @__PURE__ */ new Map();
|
|
11288
|
-
for (const table of schema.tables)
|
|
11289
|
-
map.set(tableKey(table.name, table.schema), table);
|
|
11290
|
-
}
|
|
11266
|
+
for (const table of schema.tables) map.set(tableKey(table.name, table.schema), table);
|
|
11291
11267
|
return map;
|
|
11292
11268
|
};
|
|
11293
|
-
var buildAddColumnSql = (table,
|
|
11294
|
-
const column = table.columns[
|
|
11269
|
+
var buildAddColumnSql = (table, columnName, dialect) => {
|
|
11270
|
+
const column = table.columns[columnName];
|
|
11295
11271
|
const rendered = renderColumnDefinition(table, column, dialect);
|
|
11296
11272
|
return `ALTER TABLE ${dialect.formatTableName(table)} ADD ${rendered.sql};`;
|
|
11297
11273
|
};
|
|
@@ -11312,6 +11288,7 @@ var diffColumn = (expected, actual, dialect) => {
|
|
|
11312
11288
|
autoIncrementChanged: !!expected.autoIncrement !== !!actual.autoIncrement
|
|
11313
11289
|
};
|
|
11314
11290
|
};
|
|
11291
|
+
var unsupportedMutationWarning = (dialect, operation, target) => `Dialect "${dialect.name}" does not provide the ${operation} capability for ${target}; manual migration is required.`;
|
|
11315
11292
|
var diffSchema = (expectedTables, actualSchema, dialect, options = {}) => {
|
|
11316
11293
|
const allowDestructive = options.allowDestructive ?? false;
|
|
11317
11294
|
const plan = { changes: [], warnings: [] };
|
|
@@ -11330,87 +11307,121 @@ var diffSchema = (expectedTables, actualSchema, dialect, options = {}) => {
|
|
|
11330
11307
|
});
|
|
11331
11308
|
continue;
|
|
11332
11309
|
}
|
|
11333
|
-
const
|
|
11334
|
-
for (const
|
|
11335
|
-
if (!
|
|
11310
|
+
const actualColumns = new Map(actual.columns.map((column) => [column.name, column]));
|
|
11311
|
+
for (const columnName of Object.keys(table.columns)) {
|
|
11312
|
+
if (!actualColumns.has(columnName)) {
|
|
11336
11313
|
plan.changes.push({
|
|
11337
11314
|
kind: "addColumn",
|
|
11338
11315
|
table: key,
|
|
11339
|
-
description: `Add column ${
|
|
11340
|
-
statements: [buildAddColumnSql(table,
|
|
11316
|
+
description: `Add column ${columnName} to ${key}`,
|
|
11317
|
+
statements: [buildAddColumnSql(table, columnName, dialect)],
|
|
11341
11318
|
safe: true
|
|
11342
11319
|
});
|
|
11343
|
-
|
|
11344
|
-
|
|
11345
|
-
|
|
11346
|
-
|
|
11347
|
-
|
|
11348
|
-
|
|
11349
|
-
|
|
11320
|
+
continue;
|
|
11321
|
+
}
|
|
11322
|
+
const expectedColumn = table.columns[columnName];
|
|
11323
|
+
const actualColumn = actualColumns.get(columnName);
|
|
11324
|
+
const columnDiff = diffColumn(expectedColumn, actualColumn, dialect);
|
|
11325
|
+
const shouldAlter = columnDiff.typeChanged || columnDiff.nullabilityChanged || columnDiff.defaultChanged || columnDiff.autoIncrementChanged;
|
|
11326
|
+
if (shouldAlter) {
|
|
11327
|
+
const capability = dialect.mutations.alterColumn;
|
|
11328
|
+
if (capability) {
|
|
11329
|
+
const statements = capability.compile(table, expectedColumn, actualColumn, columnDiff);
|
|
11350
11330
|
if (statements.length > 0) {
|
|
11351
11331
|
plan.changes.push({
|
|
11352
11332
|
kind: "alterColumn",
|
|
11353
11333
|
table: key,
|
|
11354
|
-
description: `Alter column ${
|
|
11334
|
+
description: `Alter column ${columnName} on ${key}`,
|
|
11355
11335
|
statements,
|
|
11356
11336
|
safe: true
|
|
11357
11337
|
});
|
|
11358
11338
|
}
|
|
11359
|
-
const warning =
|
|
11339
|
+
const warning = capability.warning?.(table, expectedColumn, actualColumn, columnDiff);
|
|
11360
11340
|
if (warning) plan.warnings.push(warning);
|
|
11341
|
+
} else {
|
|
11342
|
+
plan.warnings.push(
|
|
11343
|
+
unsupportedMutationWarning(dialect, "ALTER COLUMN", `${key}.${columnName}`)
|
|
11344
|
+
);
|
|
11361
11345
|
}
|
|
11362
11346
|
}
|
|
11363
11347
|
}
|
|
11364
|
-
for (const
|
|
11365
|
-
if (
|
|
11366
|
-
|
|
11367
|
-
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
11371
|
-
|
|
11372
|
-
|
|
11373
|
-
|
|
11348
|
+
for (const columnName of actualColumns.keys()) {
|
|
11349
|
+
if (table.columns[columnName]) continue;
|
|
11350
|
+
const capability = dialect.mutations.dropColumn;
|
|
11351
|
+
const statements = allowDestructive && capability ? capability.compile(actual, columnName) : [];
|
|
11352
|
+
plan.changes.push({
|
|
11353
|
+
kind: "dropColumn",
|
|
11354
|
+
table: key,
|
|
11355
|
+
description: `Drop column ${columnName} from ${key}`,
|
|
11356
|
+
statements,
|
|
11357
|
+
safe: false
|
|
11358
|
+
});
|
|
11359
|
+
if (!capability) {
|
|
11360
|
+
plan.warnings.push(
|
|
11361
|
+
unsupportedMutationWarning(dialect, "DROP COLUMN", `${key}.${columnName}`)
|
|
11362
|
+
);
|
|
11363
|
+
} else {
|
|
11364
|
+
const warning = capability.warning?.(actual, columnName);
|
|
11374
11365
|
if (warning) plan.warnings.push(warning);
|
|
11375
11366
|
}
|
|
11376
11367
|
}
|
|
11377
11368
|
const expectedIndexes = table.indexes ?? [];
|
|
11378
11369
|
const actualIndexes = actual.indexes ?? [];
|
|
11379
|
-
const actualIndexMap = new Map(actualIndexes.map((
|
|
11380
|
-
for (const
|
|
11381
|
-
const name =
|
|
11370
|
+
const actualIndexMap = new Map(actualIndexes.map((index) => [index.name, index]));
|
|
11371
|
+
for (const index of expectedIndexes) {
|
|
11372
|
+
const name = index.name || deriveIndexName(table, index);
|
|
11382
11373
|
if (!actualIndexMap.has(name)) {
|
|
11383
11374
|
plan.changes.push({
|
|
11384
11375
|
kind: "addIndex",
|
|
11385
11376
|
table: key,
|
|
11386
11377
|
description: `Create index ${name} on ${key}`,
|
|
11387
|
-
statements: [dialect.renderIndex(table, { ...
|
|
11378
|
+
statements: [dialect.renderIndex(table, { ...index, name })],
|
|
11388
11379
|
safe: true
|
|
11389
11380
|
});
|
|
11390
11381
|
}
|
|
11391
11382
|
}
|
|
11392
|
-
for (const
|
|
11393
|
-
if (
|
|
11394
|
-
|
|
11395
|
-
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
|
|
11399
|
-
|
|
11400
|
-
|
|
11383
|
+
for (const index of actualIndexes) {
|
|
11384
|
+
if (!index.name) continue;
|
|
11385
|
+
const expected = expectedIndexes.find(
|
|
11386
|
+
(candidate) => (candidate.name || deriveIndexName(table, candidate)) === index.name
|
|
11387
|
+
);
|
|
11388
|
+
if (expected) continue;
|
|
11389
|
+
const capability = dialect.mutations.dropIndex;
|
|
11390
|
+
const statements = allowDestructive && capability ? capability.compile(actual, index.name) : [];
|
|
11391
|
+
plan.changes.push({
|
|
11392
|
+
kind: "dropIndex",
|
|
11393
|
+
table: key,
|
|
11394
|
+
description: `Drop index ${index.name} on ${key}`,
|
|
11395
|
+
statements,
|
|
11396
|
+
safe: false
|
|
11397
|
+
});
|
|
11398
|
+
if (!capability) {
|
|
11399
|
+
plan.warnings.push(
|
|
11400
|
+
unsupportedMutationWarning(dialect, "DROP INDEX", `${key}.${index.name}`)
|
|
11401
|
+
);
|
|
11402
|
+
} else {
|
|
11403
|
+
const warning = capability.warning?.(actual, index.name);
|
|
11404
|
+
if (warning) plan.warnings.push(warning);
|
|
11401
11405
|
}
|
|
11402
11406
|
}
|
|
11403
11407
|
}
|
|
11404
11408
|
for (const actual of actualSchema.tables) {
|
|
11405
11409
|
const key = tableKey(actual.name, actual.schema);
|
|
11406
|
-
if (
|
|
11407
|
-
|
|
11408
|
-
|
|
11409
|
-
|
|
11410
|
-
|
|
11411
|
-
|
|
11412
|
-
|
|
11413
|
-
|
|
11410
|
+
if (expectedTables.find((table) => tableKey(table.name, table.schema) === key)) continue;
|
|
11411
|
+
const capability = dialect.mutations.dropTable;
|
|
11412
|
+
const statements = allowDestructive && capability ? capability.compile(actual) : [];
|
|
11413
|
+
plan.changes.push({
|
|
11414
|
+
kind: "dropTable",
|
|
11415
|
+
table: key,
|
|
11416
|
+
description: `Drop table ${key}`,
|
|
11417
|
+
statements,
|
|
11418
|
+
safe: false
|
|
11419
|
+
});
|
|
11420
|
+
if (!capability) {
|
|
11421
|
+
plan.warnings.push(unsupportedMutationWarning(dialect, "DROP TABLE", key));
|
|
11422
|
+
} else {
|
|
11423
|
+
const warning = capability.warning?.(actual);
|
|
11424
|
+
if (warning) plan.warnings.push(warning);
|
|
11414
11425
|
}
|
|
11415
11426
|
}
|
|
11416
11427
|
return plan;
|
|
@@ -13356,6 +13367,604 @@ var introspectSchema = async (executor, dialect, options = {}) => {
|
|
|
13356
13367
|
return handler.introspect(ctx, options);
|
|
13357
13368
|
};
|
|
13358
13369
|
|
|
13370
|
+
// src/core/ddl/schema-dialect-composer.ts
|
|
13371
|
+
var composeSchemaDialect = (config) => {
|
|
13372
|
+
const quoteIdentifier9 = (id) => config.quoteIdentifier(id);
|
|
13373
|
+
const formatTableName = (table) => table.schema ? `${quoteIdentifier9(table.schema)}.${quoteIdentifier9(table.name)}` : quoteIdentifier9(table.name);
|
|
13374
|
+
let services;
|
|
13375
|
+
const renderDefault = (value, column) => config.renderDefault?.(value, column, services) ?? formatLiteral(config.literalFormatter, value);
|
|
13376
|
+
services = {
|
|
13377
|
+
name: config.name,
|
|
13378
|
+
quoteIdentifier: quoteIdentifier9,
|
|
13379
|
+
formatTableName,
|
|
13380
|
+
renderDefault
|
|
13381
|
+
};
|
|
13382
|
+
const mutations = config.mutations?.(services) ?? {};
|
|
13383
|
+
return {
|
|
13384
|
+
name: config.name,
|
|
13385
|
+
mutations,
|
|
13386
|
+
quoteIdentifier: quoteIdentifier9,
|
|
13387
|
+
formatTableName,
|
|
13388
|
+
renderColumnType: (column) => config.renderColumnType(column, services),
|
|
13389
|
+
renderDefault,
|
|
13390
|
+
renderAutoIncrement: (column, table) => config.renderAutoIncrement(column, table, services),
|
|
13391
|
+
renderReference(ref, table) {
|
|
13392
|
+
const parts = [
|
|
13393
|
+
"REFERENCES",
|
|
13394
|
+
quoteQualified({ quoteIdentifier: quoteIdentifier9 }, ref.table),
|
|
13395
|
+
`(${quoteIdentifier9(ref.column)})`
|
|
13396
|
+
];
|
|
13397
|
+
if (ref.onDelete) parts.push("ON DELETE", ref.onDelete);
|
|
13398
|
+
if (ref.onUpdate) parts.push("ON UPDATE", ref.onUpdate);
|
|
13399
|
+
const suffix = config.renderReferenceSuffix?.(ref, table, services);
|
|
13400
|
+
if (suffix) parts.push(suffix);
|
|
13401
|
+
return parts.join(" ");
|
|
13402
|
+
},
|
|
13403
|
+
renderIndex: (table, index) => config.renderIndex(table, index, services),
|
|
13404
|
+
renderTableOptions: (table) => config.renderTableOptions?.(table, services),
|
|
13405
|
+
supportsPartialIndexes: () => config.supportsPartialIndexes ?? false,
|
|
13406
|
+
preferInlinePkAutoincrement: (column, table, pk) => config.preferInlinePkAutoincrement?.(column, table, pk, services) ?? false
|
|
13407
|
+
};
|
|
13408
|
+
};
|
|
13409
|
+
var createStandardDropTableCapability = (services) => ({
|
|
13410
|
+
compile: (table) => [`DROP TABLE IF EXISTS ${services.formatTableName(table)};`]
|
|
13411
|
+
});
|
|
13412
|
+
var createStandardDropColumnCapability = (services) => ({
|
|
13413
|
+
compile: (table, column) => [
|
|
13414
|
+
`ALTER TABLE ${services.formatTableName(table)} DROP COLUMN ${services.quoteIdentifier(column)};`
|
|
13415
|
+
]
|
|
13416
|
+
});
|
|
13417
|
+
|
|
13418
|
+
// src/core/ddl/dialects/postgres-schema-dialect.ts
|
|
13419
|
+
var quoteIdentifier5 = (id) => `"${id}"`;
|
|
13420
|
+
var literalFormatter = createLiteralFormatter();
|
|
13421
|
+
var renderPostgresColumnType = (column, services) => {
|
|
13422
|
+
const override = column.dialectTypes?.[services.name] ?? column.dialectTypes?.default;
|
|
13423
|
+
if (override) return renderTypeWithArgs(override, column.args);
|
|
13424
|
+
const type = normalizeColumnType(column.type);
|
|
13425
|
+
switch (type) {
|
|
13426
|
+
case "int":
|
|
13427
|
+
case "integer":
|
|
13428
|
+
return "integer";
|
|
13429
|
+
case "bigint":
|
|
13430
|
+
return "bigint";
|
|
13431
|
+
case "uuid":
|
|
13432
|
+
return "uuid";
|
|
13433
|
+
case "boolean":
|
|
13434
|
+
return "boolean";
|
|
13435
|
+
case "json":
|
|
13436
|
+
return "jsonb";
|
|
13437
|
+
case "decimal":
|
|
13438
|
+
return column.args?.length ? `numeric(${column.args[0]}, ${column.args[1] ?? 0})` : "numeric";
|
|
13439
|
+
case "float":
|
|
13440
|
+
case "double":
|
|
13441
|
+
return "double precision";
|
|
13442
|
+
case "timestamptz":
|
|
13443
|
+
return "timestamptz";
|
|
13444
|
+
case "timestamp":
|
|
13445
|
+
return "timestamp";
|
|
13446
|
+
case "date":
|
|
13447
|
+
return "date";
|
|
13448
|
+
case "datetime":
|
|
13449
|
+
return "timestamp";
|
|
13450
|
+
case "varchar":
|
|
13451
|
+
return column.args?.length ? `varchar(${column.args[0]})` : "varchar";
|
|
13452
|
+
case "text":
|
|
13453
|
+
return "text";
|
|
13454
|
+
case "enum":
|
|
13455
|
+
return "text";
|
|
13456
|
+
case "binary":
|
|
13457
|
+
case "varbinary":
|
|
13458
|
+
case "blob":
|
|
13459
|
+
case "bytea":
|
|
13460
|
+
return "bytea";
|
|
13461
|
+
case "vector":
|
|
13462
|
+
return column.vectorOptions?.elementType === "float16" ? `halfvec(${column.vectorOptions.dimensions})` : column.args?.length ? `vector(${column.args[0]})` : "vector";
|
|
13463
|
+
case "halfvec":
|
|
13464
|
+
return column.args?.length ? `halfvec(${column.args[0]})` : "halfvec";
|
|
13465
|
+
default:
|
|
13466
|
+
return renderTypeWithArgs(String(type).toLowerCase(), column.args);
|
|
13467
|
+
}
|
|
13468
|
+
};
|
|
13469
|
+
var renderPostgresIndex = (table, index, services) => {
|
|
13470
|
+
const name = index.name || deriveIndexName(table, index);
|
|
13471
|
+
let columns = renderIndexColumns(services, index.columns);
|
|
13472
|
+
if (index.ops) columns = `${columns} ${index.ops}`;
|
|
13473
|
+
const unique = index.unique ? "UNIQUE " : "";
|
|
13474
|
+
const using = index.using ? ` USING ${index.using}` : "";
|
|
13475
|
+
let withClause = "";
|
|
13476
|
+
if (index.with) {
|
|
13477
|
+
if (typeof index.with === "string") {
|
|
13478
|
+
withClause = ` WITH (${index.with})`;
|
|
13479
|
+
} else {
|
|
13480
|
+
const params = Object.entries(index.with).map(([key, value]) => `${key} = ${value}`).join(", ");
|
|
13481
|
+
withClause = ` WITH (${params})`;
|
|
13482
|
+
}
|
|
13483
|
+
}
|
|
13484
|
+
const where = index.where ? ` WHERE ${index.where}` : "";
|
|
13485
|
+
return `CREATE ${unique}INDEX IF NOT EXISTS ${services.quoteIdentifier(name)} ON ${services.formatTableName(table)}${using} (${columns})${withClause}${where};`;
|
|
13486
|
+
};
|
|
13487
|
+
var createPostgresSchemaDialect = () => composeSchemaDialect({
|
|
13488
|
+
name: "postgres",
|
|
13489
|
+
quoteIdentifier: quoteIdentifier5,
|
|
13490
|
+
literalFormatter,
|
|
13491
|
+
renderColumnType: renderPostgresColumnType,
|
|
13492
|
+
renderAutoIncrement: (column) => {
|
|
13493
|
+
if (!column.autoIncrement) return void 0;
|
|
13494
|
+
const strategy = column.generated === "always" ? "GENERATED ALWAYS" : "GENERATED BY DEFAULT";
|
|
13495
|
+
return `${strategy} AS IDENTITY`;
|
|
13496
|
+
},
|
|
13497
|
+
renderIndex: renderPostgresIndex,
|
|
13498
|
+
renderReferenceSuffix: (ref) => ref.deferrable ? "DEFERRABLE INITIALLY DEFERRED" : void 0,
|
|
13499
|
+
supportsPartialIndexes: true,
|
|
13500
|
+
mutations: (services) => ({
|
|
13501
|
+
dropTable: createStandardDropTableCapability(services),
|
|
13502
|
+
dropColumn: createStandardDropColumnCapability(services),
|
|
13503
|
+
dropIndex: {
|
|
13504
|
+
compile(table, index) {
|
|
13505
|
+
const qualified = table.schema ? `${services.quoteIdentifier(table.schema)}.${services.quoteIdentifier(index)}` : services.quoteIdentifier(index);
|
|
13506
|
+
return [`DROP INDEX IF EXISTS ${qualified};`];
|
|
13507
|
+
}
|
|
13508
|
+
},
|
|
13509
|
+
alterColumn: {
|
|
13510
|
+
compile(table, column, actualColumn, diff) {
|
|
13511
|
+
void actualColumn;
|
|
13512
|
+
const statements = [];
|
|
13513
|
+
const tableName = services.formatTableName(table);
|
|
13514
|
+
const columnName = services.quoteIdentifier(column.name);
|
|
13515
|
+
if (diff.typeChanged) {
|
|
13516
|
+
statements.push(
|
|
13517
|
+
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} TYPE ${renderPostgresColumnType(column, services)};`
|
|
13518
|
+
);
|
|
13519
|
+
}
|
|
13520
|
+
if (diff.defaultChanged) {
|
|
13521
|
+
statements.push(
|
|
13522
|
+
column.default === void 0 ? `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP DEFAULT;` : `ALTER TABLE ${tableName} ALTER COLUMN ${columnName} SET DEFAULT ${services.renderDefault(column.default, column)};`
|
|
13523
|
+
);
|
|
13524
|
+
}
|
|
13525
|
+
if (diff.nullabilityChanged) {
|
|
13526
|
+
statements.push(
|
|
13527
|
+
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} ${column.notNull ? "SET" : "DROP"} NOT NULL;`
|
|
13528
|
+
);
|
|
13529
|
+
}
|
|
13530
|
+
if (diff.autoIncrementChanged) {
|
|
13531
|
+
if (column.autoIncrement) {
|
|
13532
|
+
const strategy = column.generated === "always" ? "ALWAYS" : "BY DEFAULT";
|
|
13533
|
+
statements.push(
|
|
13534
|
+
`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} ADD GENERATED ${strategy} AS IDENTITY;`
|
|
13535
|
+
);
|
|
13536
|
+
} else {
|
|
13537
|
+
statements.push(`ALTER TABLE ${tableName} ALTER COLUMN ${columnName} DROP IDENTITY IF EXISTS;`);
|
|
13538
|
+
}
|
|
13539
|
+
}
|
|
13540
|
+
return statements;
|
|
13541
|
+
},
|
|
13542
|
+
warning(table, column, actualColumn, diff) {
|
|
13543
|
+
void table;
|
|
13544
|
+
void column;
|
|
13545
|
+
void actualColumn;
|
|
13546
|
+
return diff.autoIncrementChanged ? "Altering identity properties may fail if an existing sequence is attached; verify generated column state." : void 0;
|
|
13547
|
+
}
|
|
13548
|
+
}
|
|
13549
|
+
})
|
|
13550
|
+
});
|
|
13551
|
+
var PostgresSchemaDialect = class {
|
|
13552
|
+
delegate = createPostgresSchemaDialect();
|
|
13553
|
+
name = this.delegate.name;
|
|
13554
|
+
mutations = this.delegate.mutations;
|
|
13555
|
+
quoteIdentifier(id) {
|
|
13556
|
+
return this.delegate.quoteIdentifier(id);
|
|
13557
|
+
}
|
|
13558
|
+
formatTableName(table) {
|
|
13559
|
+
return this.delegate.formatTableName(table);
|
|
13560
|
+
}
|
|
13561
|
+
renderColumnType(column) {
|
|
13562
|
+
return this.delegate.renderColumnType(column);
|
|
13563
|
+
}
|
|
13564
|
+
renderDefault(value, column) {
|
|
13565
|
+
return this.delegate.renderDefault(value, column);
|
|
13566
|
+
}
|
|
13567
|
+
renderAutoIncrement(column, table) {
|
|
13568
|
+
return this.delegate.renderAutoIncrement(column, table);
|
|
13569
|
+
}
|
|
13570
|
+
renderReference(ref, table) {
|
|
13571
|
+
return this.delegate.renderReference(ref, table);
|
|
13572
|
+
}
|
|
13573
|
+
renderIndex(table, index) {
|
|
13574
|
+
return this.delegate.renderIndex(table, index);
|
|
13575
|
+
}
|
|
13576
|
+
renderTableOptions(table) {
|
|
13577
|
+
return this.delegate.renderTableOptions(table);
|
|
13578
|
+
}
|
|
13579
|
+
supportsPartialIndexes() {
|
|
13580
|
+
return this.delegate.supportsPartialIndexes();
|
|
13581
|
+
}
|
|
13582
|
+
preferInlinePkAutoincrement(column, table, pk) {
|
|
13583
|
+
return this.delegate.preferInlinePkAutoincrement(column, table, pk);
|
|
13584
|
+
}
|
|
13585
|
+
};
|
|
13586
|
+
|
|
13587
|
+
// src/core/ddl/dialects/mysql-schema-dialect.ts
|
|
13588
|
+
var quoteIdentifier6 = (id) => `\`${id}\``;
|
|
13589
|
+
var literalFormatter2 = createLiteralFormatter({ booleanTrue: "1", booleanFalse: "0" });
|
|
13590
|
+
var renderMySqlColumnType = (column, services) => {
|
|
13591
|
+
const override = column.dialectTypes?.[services.name] ?? column.dialectTypes?.default;
|
|
13592
|
+
if (override) return renderTypeWithArgs(override, column.args);
|
|
13593
|
+
const type = normalizeColumnType(column.type);
|
|
13594
|
+
switch (type) {
|
|
13595
|
+
case "int":
|
|
13596
|
+
case "integer":
|
|
13597
|
+
return "INT";
|
|
13598
|
+
case "bigint":
|
|
13599
|
+
return "BIGINT";
|
|
13600
|
+
case "uuid":
|
|
13601
|
+
return "CHAR(36)";
|
|
13602
|
+
case "boolean":
|
|
13603
|
+
return "TINYINT(1)";
|
|
13604
|
+
case "json":
|
|
13605
|
+
return "JSON";
|
|
13606
|
+
case "decimal":
|
|
13607
|
+
return column.args?.length ? `DECIMAL(${column.args[0]},${column.args[1] ?? 0})` : "DECIMAL";
|
|
13608
|
+
case "float":
|
|
13609
|
+
return column.args?.length ? `FLOAT(${column.args[0]})` : "FLOAT";
|
|
13610
|
+
case "double":
|
|
13611
|
+
return "DOUBLE";
|
|
13612
|
+
case "timestamptz":
|
|
13613
|
+
case "timestamp":
|
|
13614
|
+
return "TIMESTAMP";
|
|
13615
|
+
case "datetime":
|
|
13616
|
+
return "DATETIME";
|
|
13617
|
+
case "date":
|
|
13618
|
+
return "DATE";
|
|
13619
|
+
case "varchar":
|
|
13620
|
+
return column.args?.length ? `VARCHAR(${column.args[0]})` : "VARCHAR(255)";
|
|
13621
|
+
case "text":
|
|
13622
|
+
return "TEXT";
|
|
13623
|
+
case "binary":
|
|
13624
|
+
return column.args?.length ? `BINARY(${column.args[0]})` : "BINARY(255)";
|
|
13625
|
+
case "varbinary":
|
|
13626
|
+
return column.args?.length ? `VARBINARY(${column.args[0]})` : "VARBINARY(255)";
|
|
13627
|
+
case "blob":
|
|
13628
|
+
case "bytea":
|
|
13629
|
+
return "BLOB";
|
|
13630
|
+
case "enum":
|
|
13631
|
+
return column.args?.length ? `ENUM(${column.args.map((value) => `'${escapeSqlString(String(value))}'`).join(",")})` : "ENUM";
|
|
13632
|
+
case "vector":
|
|
13633
|
+
case "halfvec": {
|
|
13634
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
13635
|
+
return `VECTOR(${dimensions})`;
|
|
13636
|
+
}
|
|
13637
|
+
default:
|
|
13638
|
+
return renderTypeWithArgs(String(type).toUpperCase(), column.args);
|
|
13639
|
+
}
|
|
13640
|
+
};
|
|
13641
|
+
var createMySqlSchemaDialect = () => {
|
|
13642
|
+
let dialect;
|
|
13643
|
+
dialect = composeSchemaDialect({
|
|
13644
|
+
name: "mysql",
|
|
13645
|
+
quoteIdentifier: quoteIdentifier6,
|
|
13646
|
+
literalFormatter: literalFormatter2,
|
|
13647
|
+
renderColumnType: renderMySqlColumnType,
|
|
13648
|
+
renderAutoIncrement: (column) => column.autoIncrement ? "AUTO_INCREMENT" : void 0,
|
|
13649
|
+
renderIndex(table, index, services) {
|
|
13650
|
+
if (index.where) throw new Error("MySQL does not support partial/filtered indexes");
|
|
13651
|
+
const name = index.name || deriveIndexName(table, index);
|
|
13652
|
+
const columns = renderIndexColumns(services, index.columns);
|
|
13653
|
+
const unique = index.unique ? "UNIQUE " : "";
|
|
13654
|
+
return `CREATE ${unique}INDEX ${services.quoteIdentifier(name)} ON ${services.formatTableName(table)} (${columns});`;
|
|
13655
|
+
},
|
|
13656
|
+
renderTableOptions(table) {
|
|
13657
|
+
const parts = [];
|
|
13658
|
+
if (table.engine) parts.push(`ENGINE=${table.engine}`);
|
|
13659
|
+
if (table.charset) parts.push(`DEFAULT CHARSET=${table.charset}`);
|
|
13660
|
+
if (table.collation) parts.push(`COLLATE=${table.collation}`);
|
|
13661
|
+
return parts.length ? parts.join(" ") : void 0;
|
|
13662
|
+
},
|
|
13663
|
+
mutations: (services) => ({
|
|
13664
|
+
dropTable: createStandardDropTableCapability(services),
|
|
13665
|
+
dropColumn: createStandardDropColumnCapability(services),
|
|
13666
|
+
dropIndex: {
|
|
13667
|
+
compile: (table, index) => [
|
|
13668
|
+
`DROP INDEX ${services.quoteIdentifier(index)} ON ${services.formatTableName(table)};`
|
|
13669
|
+
]
|
|
13670
|
+
},
|
|
13671
|
+
alterColumn: {
|
|
13672
|
+
compile(table, column, actualColumn, diff) {
|
|
13673
|
+
void actualColumn;
|
|
13674
|
+
void diff;
|
|
13675
|
+
const rendered = renderColumnDefinition(table, column, dialect);
|
|
13676
|
+
return [`ALTER TABLE ${services.formatTableName(table)} MODIFY COLUMN ${rendered.sql};`];
|
|
13677
|
+
}
|
|
13678
|
+
}
|
|
13679
|
+
})
|
|
13680
|
+
});
|
|
13681
|
+
return dialect;
|
|
13682
|
+
};
|
|
13683
|
+
var MySqlSchemaDialect = class {
|
|
13684
|
+
delegate = createMySqlSchemaDialect();
|
|
13685
|
+
name = this.delegate.name;
|
|
13686
|
+
mutations = this.delegate.mutations;
|
|
13687
|
+
quoteIdentifier(id) {
|
|
13688
|
+
return this.delegate.quoteIdentifier(id);
|
|
13689
|
+
}
|
|
13690
|
+
formatTableName(table) {
|
|
13691
|
+
return this.delegate.formatTableName(table);
|
|
13692
|
+
}
|
|
13693
|
+
renderColumnType(column) {
|
|
13694
|
+
return this.delegate.renderColumnType(column);
|
|
13695
|
+
}
|
|
13696
|
+
renderDefault(value, column) {
|
|
13697
|
+
return this.delegate.renderDefault(value, column);
|
|
13698
|
+
}
|
|
13699
|
+
renderAutoIncrement(column, table) {
|
|
13700
|
+
return this.delegate.renderAutoIncrement(column, table);
|
|
13701
|
+
}
|
|
13702
|
+
renderReference(ref, table) {
|
|
13703
|
+
return this.delegate.renderReference(ref, table);
|
|
13704
|
+
}
|
|
13705
|
+
renderIndex(table, index) {
|
|
13706
|
+
return this.delegate.renderIndex(table, index);
|
|
13707
|
+
}
|
|
13708
|
+
renderTableOptions(table) {
|
|
13709
|
+
return this.delegate.renderTableOptions(table);
|
|
13710
|
+
}
|
|
13711
|
+
supportsPartialIndexes() {
|
|
13712
|
+
return this.delegate.supportsPartialIndexes();
|
|
13713
|
+
}
|
|
13714
|
+
preferInlinePkAutoincrement(column, table, pk) {
|
|
13715
|
+
return this.delegate.preferInlinePkAutoincrement(column, table, pk);
|
|
13716
|
+
}
|
|
13717
|
+
};
|
|
13718
|
+
|
|
13719
|
+
// src/core/ddl/dialects/sqlite-schema-dialect.ts
|
|
13720
|
+
var quoteIdentifier7 = (id) => `"${id}"`;
|
|
13721
|
+
var literalFormatter3 = createLiteralFormatter({ booleanTrue: "1", booleanFalse: "0" });
|
|
13722
|
+
var renderSqliteColumnType = (column, services) => {
|
|
13723
|
+
const override = column.dialectTypes?.[services.name] ?? column.dialectTypes?.default;
|
|
13724
|
+
if (override) return renderTypeWithArgs(override, column.args);
|
|
13725
|
+
const type = normalizeColumnType(column.type);
|
|
13726
|
+
switch (type) {
|
|
13727
|
+
case "int":
|
|
13728
|
+
case "integer":
|
|
13729
|
+
case "bigint":
|
|
13730
|
+
case "boolean":
|
|
13731
|
+
return "INTEGER";
|
|
13732
|
+
case "decimal":
|
|
13733
|
+
case "float":
|
|
13734
|
+
case "double":
|
|
13735
|
+
return "REAL";
|
|
13736
|
+
case "date":
|
|
13737
|
+
case "datetime":
|
|
13738
|
+
case "timestamp":
|
|
13739
|
+
case "timestamptz":
|
|
13740
|
+
case "varchar":
|
|
13741
|
+
case "text":
|
|
13742
|
+
case "json":
|
|
13743
|
+
case "uuid":
|
|
13744
|
+
case "enum":
|
|
13745
|
+
return "TEXT";
|
|
13746
|
+
case "binary":
|
|
13747
|
+
case "varbinary":
|
|
13748
|
+
case "blob":
|
|
13749
|
+
case "bytea":
|
|
13750
|
+
return "BLOB";
|
|
13751
|
+
case "halfvec": {
|
|
13752
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
13753
|
+
return `float16[${dimensions}]`;
|
|
13754
|
+
}
|
|
13755
|
+
case "vector": {
|
|
13756
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
13757
|
+
const elementType = column.vectorOptions?.elementType === "float16" ? "float16" : "float32";
|
|
13758
|
+
return `${elementType}[${dimensions}]`;
|
|
13759
|
+
}
|
|
13760
|
+
default:
|
|
13761
|
+
return "TEXT";
|
|
13762
|
+
}
|
|
13763
|
+
};
|
|
13764
|
+
var createSqliteSchemaDialect = () => composeSchemaDialect({
|
|
13765
|
+
name: "sqlite",
|
|
13766
|
+
quoteIdentifier: quoteIdentifier7,
|
|
13767
|
+
literalFormatter: literalFormatter3,
|
|
13768
|
+
renderColumnType: renderSqliteColumnType,
|
|
13769
|
+
renderAutoIncrement(column, table) {
|
|
13770
|
+
const primaryKey = resolvePrimaryKey(table);
|
|
13771
|
+
return column.autoIncrement && primaryKey.length === 1 && primaryKey[0] === column.name ? "PRIMARY KEY AUTOINCREMENT" : void 0;
|
|
13772
|
+
},
|
|
13773
|
+
preferInlinePkAutoincrement: (column, table, primaryKey) => {
|
|
13774
|
+
void table;
|
|
13775
|
+
return !!(column.autoIncrement && primaryKey.length === 1 && primaryKey[0] === column.name);
|
|
13776
|
+
},
|
|
13777
|
+
renderIndex(table, index, services) {
|
|
13778
|
+
const name = index.name || deriveIndexName(table, index);
|
|
13779
|
+
const columns = renderIndexColumns(services, index.columns);
|
|
13780
|
+
const unique = index.unique ? "UNIQUE " : "";
|
|
13781
|
+
const where = index.where ? ` WHERE ${index.where}` : "";
|
|
13782
|
+
return `CREATE ${unique}INDEX IF NOT EXISTS ${services.quoteIdentifier(name)} ON ${services.formatTableName(table)} (${columns})${where};`;
|
|
13783
|
+
},
|
|
13784
|
+
supportsPartialIndexes: true,
|
|
13785
|
+
mutations: (services) => ({
|
|
13786
|
+
dropTable: createStandardDropTableCapability(services),
|
|
13787
|
+
dropIndex: {
|
|
13788
|
+
compile: (_table, index) => [`DROP INDEX IF EXISTS ${services.quoteIdentifier(index)};`]
|
|
13789
|
+
}
|
|
13790
|
+
})
|
|
13791
|
+
});
|
|
13792
|
+
var SQLiteSchemaDialect = class {
|
|
13793
|
+
delegate = createSqliteSchemaDialect();
|
|
13794
|
+
name = this.delegate.name;
|
|
13795
|
+
mutations = this.delegate.mutations;
|
|
13796
|
+
quoteIdentifier(id) {
|
|
13797
|
+
return this.delegate.quoteIdentifier(id);
|
|
13798
|
+
}
|
|
13799
|
+
formatTableName(table) {
|
|
13800
|
+
return this.delegate.formatTableName(table);
|
|
13801
|
+
}
|
|
13802
|
+
renderColumnType(column) {
|
|
13803
|
+
return this.delegate.renderColumnType(column);
|
|
13804
|
+
}
|
|
13805
|
+
renderDefault(value, column) {
|
|
13806
|
+
return this.delegate.renderDefault(value, column);
|
|
13807
|
+
}
|
|
13808
|
+
renderAutoIncrement(column, table) {
|
|
13809
|
+
return this.delegate.renderAutoIncrement(column, table);
|
|
13810
|
+
}
|
|
13811
|
+
renderReference(ref, table) {
|
|
13812
|
+
return this.delegate.renderReference(ref, table);
|
|
13813
|
+
}
|
|
13814
|
+
renderIndex(table, index) {
|
|
13815
|
+
return this.delegate.renderIndex(table, index);
|
|
13816
|
+
}
|
|
13817
|
+
renderTableOptions(table) {
|
|
13818
|
+
return this.delegate.renderTableOptions(table);
|
|
13819
|
+
}
|
|
13820
|
+
supportsPartialIndexes() {
|
|
13821
|
+
return this.delegate.supportsPartialIndexes();
|
|
13822
|
+
}
|
|
13823
|
+
preferInlinePkAutoincrement(column, table, pk) {
|
|
13824
|
+
return this.delegate.preferInlinePkAutoincrement(column, table, pk);
|
|
13825
|
+
}
|
|
13826
|
+
};
|
|
13827
|
+
|
|
13828
|
+
// src/core/ddl/dialects/mssql-schema-dialect.ts
|
|
13829
|
+
var quoteIdentifier8 = (id) => `[${id.replace(/]/g, "]]")}]`;
|
|
13830
|
+
var literalFormatter4 = createLiteralFormatter({ booleanTrue: "1", booleanFalse: "0" });
|
|
13831
|
+
var renderMssqlColumnType = (column, services) => {
|
|
13832
|
+
const override = column.dialectTypes?.[services.name] ?? column.dialectTypes?.default;
|
|
13833
|
+
if (override) return renderTypeWithArgs(override, column.args);
|
|
13834
|
+
const type = normalizeColumnType(column.type);
|
|
13835
|
+
switch (type) {
|
|
13836
|
+
case "int":
|
|
13837
|
+
case "integer":
|
|
13838
|
+
return "INT";
|
|
13839
|
+
case "bigint":
|
|
13840
|
+
return "BIGINT";
|
|
13841
|
+
case "uuid":
|
|
13842
|
+
return "UNIQUEIDENTIFIER";
|
|
13843
|
+
case "boolean":
|
|
13844
|
+
return "BIT";
|
|
13845
|
+
case "json":
|
|
13846
|
+
return "NVARCHAR(MAX)";
|
|
13847
|
+
case "decimal":
|
|
13848
|
+
return column.args?.length ? `DECIMAL(${column.args[0]},${column.args[1] ?? 0})` : "DECIMAL(18,0)";
|
|
13849
|
+
case "float":
|
|
13850
|
+
case "double":
|
|
13851
|
+
return "FLOAT";
|
|
13852
|
+
case "timestamptz":
|
|
13853
|
+
case "timestamp":
|
|
13854
|
+
case "datetime":
|
|
13855
|
+
return "DATETIME2";
|
|
13856
|
+
case "date":
|
|
13857
|
+
return "DATE";
|
|
13858
|
+
case "varchar":
|
|
13859
|
+
return column.args?.length ? `NVARCHAR(${column.args[0]})` : "NVARCHAR(255)";
|
|
13860
|
+
case "text":
|
|
13861
|
+
return "NVARCHAR(MAX)";
|
|
13862
|
+
case "binary": {
|
|
13863
|
+
const length2 = column.args?.[0];
|
|
13864
|
+
return length2 !== void 0 ? `BINARY(${length2})` : "BINARY(255)";
|
|
13865
|
+
}
|
|
13866
|
+
case "varbinary": {
|
|
13867
|
+
const length2 = column.args?.[0];
|
|
13868
|
+
if (typeof length2 === "string" && length2.toLowerCase() === "max") return "VARBINARY(MAX)";
|
|
13869
|
+
return length2 !== void 0 ? `VARBINARY(${length2})` : "VARBINARY(255)";
|
|
13870
|
+
}
|
|
13871
|
+
case "blob":
|
|
13872
|
+
case "bytea":
|
|
13873
|
+
return "VARBINARY(MAX)";
|
|
13874
|
+
case "enum":
|
|
13875
|
+
return "NVARCHAR(255)";
|
|
13876
|
+
case "vector": {
|
|
13877
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
13878
|
+
const elementType = column.vectorOptions?.elementType;
|
|
13879
|
+
return elementType ? `VECTOR(${dimensions}, ${elementType})` : `VECTOR(${dimensions})`;
|
|
13880
|
+
}
|
|
13881
|
+
case "halfvec": {
|
|
13882
|
+
const dimensions = column.vectorOptions?.dimensions ?? column.args?.[0] ?? 3;
|
|
13883
|
+
return `VECTOR(${dimensions}, float16)`;
|
|
13884
|
+
}
|
|
13885
|
+
default:
|
|
13886
|
+
return renderTypeWithArgs(String(type).toUpperCase(), column.args);
|
|
13887
|
+
}
|
|
13888
|
+
};
|
|
13889
|
+
var createMssqlSchemaDialect = () => composeSchemaDialect({
|
|
13890
|
+
name: "mssql",
|
|
13891
|
+
quoteIdentifier: quoteIdentifier8,
|
|
13892
|
+
literalFormatter: literalFormatter4,
|
|
13893
|
+
renderColumnType: renderMssqlColumnType,
|
|
13894
|
+
renderAutoIncrement: (column) => column.autoIncrement ? "IDENTITY(1,1)" : void 0,
|
|
13895
|
+
renderIndex(table, index, services) {
|
|
13896
|
+
const name = index.name || deriveIndexName(table, index);
|
|
13897
|
+
const columns = renderIndexColumns(services, index.columns);
|
|
13898
|
+
const unique = index.unique ? "UNIQUE " : "";
|
|
13899
|
+
const where = index.where ? ` WHERE ${index.where}` : "";
|
|
13900
|
+
return `CREATE ${unique}INDEX ${services.quoteIdentifier(name)} ON ${services.formatTableName(table)} (${columns})${where};`;
|
|
13901
|
+
},
|
|
13902
|
+
supportsPartialIndexes: true,
|
|
13903
|
+
mutations: (services) => ({
|
|
13904
|
+
dropTable: createStandardDropTableCapability(services),
|
|
13905
|
+
dropColumn: createStandardDropColumnCapability(services),
|
|
13906
|
+
dropIndex: {
|
|
13907
|
+
compile: (table, index) => [
|
|
13908
|
+
`DROP INDEX ${services.quoteIdentifier(index)} ON ${services.formatTableName(table)};`
|
|
13909
|
+
]
|
|
13910
|
+
},
|
|
13911
|
+
alterColumn: {
|
|
13912
|
+
compile(table, column, actualColumn, diff) {
|
|
13913
|
+
void actualColumn;
|
|
13914
|
+
const statements = [];
|
|
13915
|
+
if (diff.typeChanged || diff.nullabilityChanged) {
|
|
13916
|
+
const nullability = column.notNull ? "NOT NULL" : "NULL";
|
|
13917
|
+
statements.push(
|
|
13918
|
+
`ALTER TABLE ${services.formatTableName(table)} ALTER COLUMN ${services.quoteIdentifier(column.name)} ${renderMssqlColumnType(column, services)} ${nullability};`
|
|
13919
|
+
);
|
|
13920
|
+
}
|
|
13921
|
+
return statements;
|
|
13922
|
+
},
|
|
13923
|
+
warning(table, column, actualColumn, diff) {
|
|
13924
|
+
void table;
|
|
13925
|
+
void column;
|
|
13926
|
+
void actualColumn;
|
|
13927
|
+
return diff.defaultChanged || diff.autoIncrementChanged ? "Altering defaults or identity on MSSQL is not automated (requires dropping/adding default or identity constraints manually)." : void 0;
|
|
13928
|
+
}
|
|
13929
|
+
}
|
|
13930
|
+
})
|
|
13931
|
+
});
|
|
13932
|
+
var MSSqlSchemaDialect = class {
|
|
13933
|
+
delegate = createMssqlSchemaDialect();
|
|
13934
|
+
name = this.delegate.name;
|
|
13935
|
+
mutations = this.delegate.mutations;
|
|
13936
|
+
quoteIdentifier(id) {
|
|
13937
|
+
return this.delegate.quoteIdentifier(id);
|
|
13938
|
+
}
|
|
13939
|
+
formatTableName(table) {
|
|
13940
|
+
return this.delegate.formatTableName(table);
|
|
13941
|
+
}
|
|
13942
|
+
renderColumnType(column) {
|
|
13943
|
+
return this.delegate.renderColumnType(column);
|
|
13944
|
+
}
|
|
13945
|
+
renderDefault(value, column) {
|
|
13946
|
+
return this.delegate.renderDefault(value, column);
|
|
13947
|
+
}
|
|
13948
|
+
renderAutoIncrement(column, table) {
|
|
13949
|
+
return this.delegate.renderAutoIncrement(column, table);
|
|
13950
|
+
}
|
|
13951
|
+
renderReference(ref, table) {
|
|
13952
|
+
return this.delegate.renderReference(ref, table);
|
|
13953
|
+
}
|
|
13954
|
+
renderIndex(table, index) {
|
|
13955
|
+
return this.delegate.renderIndex(table, index);
|
|
13956
|
+
}
|
|
13957
|
+
renderTableOptions(table) {
|
|
13958
|
+
return this.delegate.renderTableOptions(table);
|
|
13959
|
+
}
|
|
13960
|
+
supportsPartialIndexes() {
|
|
13961
|
+
return this.delegate.supportsPartialIndexes();
|
|
13962
|
+
}
|
|
13963
|
+
preferInlinePkAutoincrement(column, table, pk) {
|
|
13964
|
+
return this.delegate.preferInlinePkAutoincrement(column, table, pk);
|
|
13965
|
+
}
|
|
13966
|
+
};
|
|
13967
|
+
|
|
13359
13968
|
// src/core/functions/numeric.ts
|
|
13360
13969
|
var isColumnDef2 = (val) => !!val && typeof val === "object" && "type" in val && "name" in val;
|
|
13361
13970
|
var toOperand3 = (input) => {
|
|
@@ -21839,7 +22448,6 @@ export {
|
|
|
21839
22448
|
DefaultMorphToReference,
|
|
21840
22449
|
DefaultTypeStrategy,
|
|
21841
22450
|
DeleteQueryBuilder,
|
|
21842
|
-
DialectBase,
|
|
21843
22451
|
DialectFactory,
|
|
21844
22452
|
DomainEventBus,
|
|
21845
22453
|
Email,
|
|
@@ -21853,6 +22461,7 @@ export {
|
|
|
21853
22461
|
KeyvCacheAdapter,
|
|
21854
22462
|
Length,
|
|
21855
22463
|
Lower,
|
|
22464
|
+
MSSqlSchemaDialect,
|
|
21856
22465
|
MemoryCacheAdapter,
|
|
21857
22466
|
MorphMany,
|
|
21858
22467
|
MorphOne,
|
|
@@ -21865,6 +22474,7 @@ export {
|
|
|
21865
22474
|
MssqlUpdateCompiler,
|
|
21866
22475
|
MySqlDialect,
|
|
21867
22476
|
MySqlProcedureCompiler,
|
|
22477
|
+
MySqlSchemaDialect,
|
|
21868
22478
|
MySqlUpsertStrategy,
|
|
21869
22479
|
NestedSetStrategy,
|
|
21870
22480
|
NoReturningStrategy,
|
|
@@ -21876,6 +22486,7 @@ export {
|
|
|
21876
22486
|
PostgresDialect,
|
|
21877
22487
|
PostgresProcedureCompiler,
|
|
21878
22488
|
PostgresReturningStrategy,
|
|
22489
|
+
PostgresSchemaDialect,
|
|
21879
22490
|
PostgresUpsertStrategy,
|
|
21880
22491
|
PrimaryKey,
|
|
21881
22492
|
ProcedureCallBuilder,
|
|
@@ -21883,9 +22494,9 @@ export {
|
|
|
21883
22494
|
QueryCacheManager,
|
|
21884
22495
|
RedisCacheAdapter,
|
|
21885
22496
|
RelationKinds,
|
|
22497
|
+
SQLiteSchemaDialect,
|
|
21886
22498
|
STANDARD_COLUMN_TYPES,
|
|
21887
22499
|
SelectQueryBuilder,
|
|
21888
|
-
SqlDialectBase,
|
|
21889
22500
|
SqlServerDialect,
|
|
21890
22501
|
SqliteDialect,
|
|
21891
22502
|
SqliteReturningStrategy,
|
|
@@ -21967,6 +22578,8 @@ export {
|
|
|
21967
22578
|
columnToOpenApiSchema,
|
|
21968
22579
|
columnTypeToOpenApiFormat,
|
|
21969
22580
|
columnTypeToOpenApiType,
|
|
22581
|
+
composeSchemaDialect,
|
|
22582
|
+
composeSqlDialect,
|
|
21970
22583
|
computePaginationMetadata,
|
|
21971
22584
|
computeSchemaHash,
|
|
21972
22585
|
concat,
|
|
@@ -21984,14 +22597,26 @@ export {
|
|
|
21984
22597
|
createEntityFromRow,
|
|
21985
22598
|
createEntityProxy,
|
|
21986
22599
|
createExecutorFromQueryRunner,
|
|
22600
|
+
createLiteralFormatter,
|
|
21987
22601
|
createMssqlCompilerSet,
|
|
21988
22602
|
createMssqlExecutor,
|
|
22603
|
+
createMssqlSchemaDialect,
|
|
22604
|
+
createMySqlDialect,
|
|
22605
|
+
createMySqlSchemaDialect,
|
|
21989
22606
|
createMysqlExecutor,
|
|
21990
22607
|
createPooledExecutorFactory,
|
|
22608
|
+
createPostgresDialect,
|
|
21991
22609
|
createPostgresExecutor,
|
|
22610
|
+
createPostgresSchemaDialect,
|
|
21992
22611
|
createQueryLoggingExecutor,
|
|
21993
22612
|
createRef,
|
|
22613
|
+
createSqlDialect,
|
|
22614
|
+
createSqlServerDialect,
|
|
22615
|
+
createSqliteDialect,
|
|
21994
22616
|
createSqliteExecutor,
|
|
22617
|
+
createSqliteSchemaDialect,
|
|
22618
|
+
createStandardDropColumnCapability,
|
|
22619
|
+
createStandardDropTableCapability,
|
|
21995
22620
|
createTediousExecutor,
|
|
21996
22621
|
createTediousMssqlClient,
|
|
21997
22622
|
createTreeManager,
|