metal-orm 1.0.13 → 1.0.15

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 (115) hide show
  1. package/README.md +75 -82
  2. package/dist/decorators/index.cjs +1600 -27
  3. package/dist/decorators/index.cjs.map +1 -1
  4. package/dist/decorators/index.d.cts +6 -2
  5. package/dist/decorators/index.d.ts +6 -2
  6. package/dist/decorators/index.js +1599 -27
  7. package/dist/decorators/index.js.map +1 -1
  8. package/dist/index.cjs +4608 -3429
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +511 -159
  11. package/dist/index.d.ts +511 -159
  12. package/dist/index.js +4526 -3415
  13. package/dist/index.js.map +1 -1
  14. package/dist/{select-CCp1oz9p.d.cts → select-Bkv8g8u_.d.cts} +193 -67
  15. package/dist/{select-CCp1oz9p.d.ts → select-Bkv8g8u_.d.ts} +193 -67
  16. package/package.json +1 -1
  17. package/src/codegen/typescript.ts +38 -35
  18. package/src/core/ast/adapters.ts +21 -0
  19. package/src/core/ast/aggregate-functions.ts +13 -13
  20. package/src/core/ast/builders.ts +56 -43
  21. package/src/core/ast/expression-builders.ts +34 -34
  22. package/src/core/ast/expression-nodes.ts +18 -16
  23. package/src/core/ast/expression-visitor.ts +122 -69
  24. package/src/core/ast/expression.ts +6 -4
  25. package/src/core/ast/join-metadata.ts +15 -0
  26. package/src/core/ast/join-node.ts +22 -20
  27. package/src/core/ast/join.ts +5 -5
  28. package/src/core/ast/query.ts +52 -88
  29. package/src/core/ast/types.ts +20 -0
  30. package/src/core/ast/window-functions.ts +55 -55
  31. package/src/core/ddl/dialects/base-schema-dialect.ts +20 -6
  32. package/src/core/ddl/dialects/mssql-schema-dialect.ts +32 -8
  33. package/src/core/ddl/dialects/mysql-schema-dialect.ts +21 -10
  34. package/src/core/ddl/dialects/postgres-schema-dialect.ts +52 -7
  35. package/src/core/ddl/dialects/sqlite-schema-dialect.ts +23 -9
  36. package/src/core/ddl/introspect/catalogs/index.ts +1 -0
  37. package/src/core/ddl/introspect/catalogs/postgres.ts +143 -0
  38. package/src/core/ddl/introspect/context.ts +9 -0
  39. package/src/core/ddl/introspect/functions/postgres.ts +26 -0
  40. package/src/core/ddl/introspect/mssql.ts +149 -149
  41. package/src/core/ddl/introspect/mysql.ts +99 -99
  42. package/src/core/ddl/introspect/postgres.ts +245 -154
  43. package/src/core/ddl/introspect/registry.ts +26 -0
  44. package/src/core/ddl/introspect/run-select.ts +25 -0
  45. package/src/core/ddl/introspect/sqlite.ts +7 -7
  46. package/src/core/ddl/introspect/types.ts +23 -19
  47. package/src/core/ddl/introspect/utils.ts +1 -1
  48. package/src/core/ddl/naming-strategy.ts +10 -0
  49. package/src/core/ddl/schema-dialect.ts +41 -0
  50. package/src/core/ddl/schema-diff.ts +211 -179
  51. package/src/core/ddl/schema-generator.ts +16 -90
  52. package/src/core/ddl/schema-introspect.ts +25 -32
  53. package/src/core/ddl/schema-plan-executor.ts +17 -0
  54. package/src/core/ddl/schema-types.ts +46 -39
  55. package/src/core/ddl/sql-writing.ts +170 -0
  56. package/src/core/dialect/abstract.ts +144 -126
  57. package/src/core/dialect/base/cte-compiler.ts +33 -0
  58. package/src/core/dialect/base/function-table-formatter.ts +132 -0
  59. package/src/core/dialect/base/groupby-compiler.ts +21 -0
  60. package/src/core/dialect/base/join-compiler.ts +26 -0
  61. package/src/core/dialect/base/orderby-compiler.ts +21 -0
  62. package/src/core/dialect/base/pagination-strategy.ts +32 -0
  63. package/src/core/dialect/base/returning-strategy.ts +56 -0
  64. package/src/core/dialect/base/sql-dialect.ts +181 -204
  65. package/src/core/dialect/dialect-factory.ts +91 -0
  66. package/src/core/dialect/mssql/functions.ts +101 -0
  67. package/src/core/dialect/mssql/index.ts +128 -126
  68. package/src/core/dialect/mysql/functions.ts +101 -0
  69. package/src/core/dialect/mysql/index.ts +20 -18
  70. package/src/core/dialect/postgres/functions.ts +95 -0
  71. package/src/core/dialect/postgres/index.ts +30 -28
  72. package/src/core/dialect/sqlite/functions.ts +115 -0
  73. package/src/core/dialect/sqlite/index.ts +30 -28
  74. package/src/core/driver/database-driver.ts +11 -0
  75. package/src/core/driver/mssql-driver.ts +20 -0
  76. package/src/core/driver/mysql-driver.ts +20 -0
  77. package/src/core/driver/postgres-driver.ts +20 -0
  78. package/src/core/driver/sqlite-driver.ts +20 -0
  79. package/src/core/execution/db-executor.ts +63 -0
  80. package/src/core/execution/executors/mssql-executor.ts +39 -0
  81. package/src/core/execution/executors/mysql-executor.ts +47 -0
  82. package/src/core/execution/executors/postgres-executor.ts +32 -0
  83. package/src/core/execution/executors/sqlite-executor.ts +31 -0
  84. package/src/core/functions/datetime.ts +132 -0
  85. package/src/core/functions/numeric.ts +179 -0
  86. package/src/core/functions/standard-strategy.ts +47 -0
  87. package/src/core/functions/text.ts +147 -0
  88. package/src/core/functions/types.ts +18 -0
  89. package/src/core/hydration/types.ts +57 -0
  90. package/src/decorators/bootstrap.ts +10 -0
  91. package/src/decorators/relations.ts +15 -0
  92. package/src/index.ts +30 -19
  93. package/src/orm/entity-metadata.ts +7 -0
  94. package/src/orm/entity.ts +58 -27
  95. package/src/orm/hydration.ts +25 -17
  96. package/src/orm/lazy-batch.ts +46 -2
  97. package/src/orm/orm-context.ts +60 -60
  98. package/src/orm/query-logger.ts +1 -1
  99. package/src/orm/relation-change-processor.ts +43 -2
  100. package/src/orm/relations/has-one.ts +139 -0
  101. package/src/orm/transaction-runner.ts +1 -1
  102. package/src/orm/unit-of-work.ts +60 -60
  103. package/src/query-builder/delete.ts +22 -5
  104. package/src/query-builder/hydration-manager.ts +2 -1
  105. package/src/query-builder/hydration-planner.ts +8 -7
  106. package/src/query-builder/insert.ts +22 -5
  107. package/src/query-builder/relation-conditions.ts +9 -8
  108. package/src/query-builder/relation-service.ts +3 -2
  109. package/src/query-builder/select.ts +66 -61
  110. package/src/query-builder/update.ts +22 -5
  111. package/src/schema/column.ts +246 -246
  112. package/src/schema/relation.ts +35 -1
  113. package/src/schema/table.ts +28 -28
  114. package/src/schema/types.ts +41 -31
  115. package/src/orm/db-executor.ts +0 -11
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OperandNode, C as ColumnDef, a as ColumnNode, B as BinaryExpressionNode, E as ExpressionNode, L as LogicalExpressionNode, N as NullExpressionNode, b as LiteralNode, I as InExpressionNode, c as BetweenExpressionNode, J as JsonPathNode, d as CaseExpressionNode, S as SelectQueryNode, e as ExistsExpressionNode, W as WindowFunctionNode, f as OrderDirection, F as FunctionNode, g as ScalarSubqueryNode, T as TableDef, h as InsertQueryNode, i as InsertCompiler, j as CompiledQuery, U as UpdateQueryNode, k as UpdateCompiler, D as DeleteQueryNode, l as DeleteCompiler, m as Dialect, n as CompilerContext, o as ForeignKeyReference, p as IndexColumn, q as IndexDef, r as DbExecutor, H as HydrationPlan, R as RelationMap, s as OrmContext, t as Entity, u as HasManyRelation, v as BelongsToRelation, w as BelongsToManyRelation, x as HasManyCollection, y as BelongsToReference, M as ManyToManyCollection, z as SelectQueryBuilder } from './select-CCp1oz9p.cjs';
2
- export { a0 as CascadeMode, A as CheckConstraint, a5 as ColumnToTs, Q as ColumnType, Y as DefaultValue, al as DomainEventHandler, af as EntityStatus, aj as HasDomainEvents, a6 as InferRow, am as OrmContextOptions, ak as OrmInterceptor, an as QueryLogEntry, ao as QueryLogger, ag as QueryResult, X as RawDefaultValue, V as ReferentialAction, ai as RelationChange, a1 as RelationDef, ah as RelationKey, _ as RelationKinds, $ as RelationType, K as TableHooks, G as TableOptions, ae as addDomainEvent, a3 as belongsTo, a4 as belongsToMany, Z as col, a7 as createColumn, a8 as createLiteral, P as defineTable, a2 as hasMany, ab as isCaseExpressionNode, ad as isExpressionSelectionNode, aa as isFunctionNode, a9 as isOperandNode, ac as isWindowFunctionNode } from './select-CCp1oz9p.cjs';
1
+ import { O as OperandNode, C as ColumnRef, a as ColumnNode, B as BinaryExpressionNode, E as ExpressionNode, L as LogicalExpressionNode, N as NullExpressionNode, b as LiteralNode, I as InExpressionNode, c as BetweenExpressionNode, J as JsonPathNode, d as CaseExpressionNode, S as SelectQueryNode, e as ExistsExpressionNode, W as WindowFunctionNode, f as OrderDirection, F as FunctionNode, g as ScalarSubqueryNode, h as ColumnDef, T as TableRef, i as TableDef, j as InsertQueryNode, k as InsertCompiler, l as CompiledQuery, D as Dialect, m as DialectKey, U as UpdateQueryNode, n as UpdateCompiler, o as DeleteQueryNode, p as DeleteCompiler, q as CompilerContext, r as ForeignKeyReference, s as IndexColumn, t as IndexDef, u as DbExecutor, H as HydrationPlan, R as RelationMap, v as OrmContext, w as Entity, x as HasManyRelation, y as HasOneRelation, z as BelongsToRelation, A as BelongsToManyRelation, G as HasManyCollection, K as BelongsToReference, M as ManyToManyCollection, P as SelectQueryBuilder } from './select-Bkv8g8u_.cjs';
2
+ export { a4 as CascadeMode, Q as CheckConstraint, aa as ColumnToTs, Z as ColumnType, a0 as DefaultValue, au as DomainEventHandler, ao as EntityStatus, as as HasDomainEvents, ac as HasOneReference, am as HydrationMetadata, ak as HydrationPivotPlan, al as HydrationRelationPlan, ab as InferRow, av as OrmContextOptions, at as OrmInterceptor, aw as QueryLogEntry, ax as QueryLogger, ap as QueryResult, $ as RawDefaultValue, _ as ReferentialAction, ar as RelationChange, a5 as RelationDef, aq as RelationKey, a2 as RelationKinds, a3 as RelationType, az as SimpleQueryRunner, X as TableHooks, V as TableOptions, an as addDomainEvent, a8 as belongsTo, a9 as belongsToMany, a1 as col, ad as createColumn, aA as createExecutorFromQueryRunner, ae as createLiteral, Y as defineTable, a6 as hasMany, a7 as hasOne, ah as isCaseExpressionNode, aj as isExpressionSelectionNode, ag as isFunctionNode, af as isOperandNode, ai as isWindowFunctionNode, ay as rowsToQueryResult } from './select-Bkv8g8u_.cjs';
3
3
 
4
4
  /**
5
5
  * Converts a primitive or existing operand into an operand node
@@ -7,40 +7,40 @@ export { a0 as CascadeMode, A as CheckConstraint, a5 as ColumnToTs, Q as ColumnT
7
7
  * @returns OperandNode representing the value
8
8
  */
9
9
  declare const valueToOperand: (value: unknown) => OperandNode;
10
- declare const columnOperand: (col: ColumnDef | ColumnNode) => ColumnNode;
10
+ declare const columnOperand: (col: ColumnRef | ColumnNode) => ColumnNode;
11
11
  /**
12
12
  * Creates an equality expression (left = right)
13
13
  * @param left - Left operand
14
14
  * @param right - Right operand
15
15
  * @returns Binary expression node with equality operator
16
16
  */
17
- declare const eq: (left: OperandNode | ColumnDef, right: OperandNode | ColumnDef | string | number) => BinaryExpressionNode;
17
+ declare const eq: (left: OperandNode | ColumnRef, right: OperandNode | ColumnRef | string | number | boolean) => BinaryExpressionNode;
18
18
  /**
19
19
  * Creates a not equal expression (left != right)
20
20
  */
21
- declare const neq: (left: OperandNode | ColumnDef, right: OperandNode | ColumnDef | string | number) => BinaryExpressionNode;
21
+ declare const neq: (left: OperandNode | ColumnRef, right: OperandNode | ColumnRef | string | number | boolean) => BinaryExpressionNode;
22
22
  /**
23
23
  * Creates a greater-than expression (left > right)
24
24
  * @param left - Left operand
25
25
  * @param right - Right operand
26
26
  * @returns Binary expression node with greater-than operator
27
27
  */
28
- declare const gt: (left: OperandNode | ColumnDef, right: OperandNode | ColumnDef | string | number) => BinaryExpressionNode;
28
+ declare const gt: (left: OperandNode | ColumnRef, right: OperandNode | ColumnRef | string | number) => BinaryExpressionNode;
29
29
  /**
30
30
  * Creates a greater than or equal expression (left >= right)
31
31
  */
32
- declare const gte: (left: OperandNode | ColumnDef, right: OperandNode | ColumnDef | string | number) => BinaryExpressionNode;
32
+ declare const gte: (left: OperandNode | ColumnRef, right: OperandNode | ColumnRef | string | number) => BinaryExpressionNode;
33
33
  /**
34
34
  * Creates a less-than expression (left < right)
35
35
  * @param left - Left operand
36
36
  * @param right - Right operand
37
37
  * @returns Binary expression node with less-than operator
38
38
  */
39
- declare const lt: (left: OperandNode | ColumnDef, right: OperandNode | ColumnDef | string | number) => BinaryExpressionNode;
39
+ declare const lt: (left: OperandNode | ColumnRef, right: OperandNode | ColumnRef | string | number) => BinaryExpressionNode;
40
40
  /**
41
41
  * Creates a less than or equal expression (left <= right)
42
42
  */
43
- declare const lte: (left: OperandNode | ColumnDef, right: OperandNode | ColumnDef | string | number) => BinaryExpressionNode;
43
+ declare const lte: (left: OperandNode | ColumnRef, right: OperandNode | ColumnRef | string | number) => BinaryExpressionNode;
44
44
  /**
45
45
  * Creates a LIKE pattern matching expression
46
46
  * @param left - Left operand
@@ -48,7 +48,7 @@ declare const lte: (left: OperandNode | ColumnDef, right: OperandNode | ColumnDe
48
48
  * @param escape - Optional escape character
49
49
  * @returns Binary expression node with LIKE operator
50
50
  */
51
- declare const like: (left: OperandNode | ColumnDef, pattern: string, escape?: string) => BinaryExpressionNode;
51
+ declare const like: (left: OperandNode | ColumnRef, pattern: string, escape?: string) => BinaryExpressionNode;
52
52
  /**
53
53
  * Creates a NOT LIKE pattern matching expression
54
54
  * @param left - Left operand
@@ -56,7 +56,7 @@ declare const like: (left: OperandNode | ColumnDef, pattern: string, escape?: st
56
56
  * @param escape - Optional escape character
57
57
  * @returns Binary expression node with NOT LIKE operator
58
58
  */
59
- declare const notLike: (left: OperandNode | ColumnDef, pattern: string, escape?: string) => BinaryExpressionNode;
59
+ declare const notLike: (left: OperandNode | ColumnRef, pattern: string, escape?: string) => BinaryExpressionNode;
60
60
  /**
61
61
  * Creates a logical AND expression
62
62
  * @param operands - Expressions to combine with AND
@@ -74,27 +74,27 @@ declare const or: (...operands: ExpressionNode[]) => LogicalExpressionNode;
74
74
  * @param left - Operand to check for null
75
75
  * @returns Null expression node with IS NULL operator
76
76
  */
77
- declare const isNull: (left: OperandNode | ColumnDef) => NullExpressionNode;
77
+ declare const isNull: (left: OperandNode | ColumnRef) => NullExpressionNode;
78
78
  /**
79
79
  * Creates an IS NOT NULL expression
80
80
  * @param left - Operand to check for non-null
81
81
  * @returns Null expression node with IS NOT NULL operator
82
82
  */
83
- declare const isNotNull: (left: OperandNode | ColumnDef) => NullExpressionNode;
83
+ declare const isNotNull: (left: OperandNode | ColumnRef) => NullExpressionNode;
84
84
  /**
85
85
  * Creates an IN expression (value IN list)
86
86
  * @param left - Operand to check
87
87
  * @param values - Values to check against
88
88
  * @returns IN expression node
89
89
  */
90
- declare const inList: (left: OperandNode | ColumnDef, values: (string | number | LiteralNode)[]) => InExpressionNode;
90
+ declare const inList: (left: OperandNode | ColumnRef, values: (string | number | LiteralNode)[]) => InExpressionNode;
91
91
  /**
92
92
  * Creates a NOT IN expression (value NOT IN list)
93
93
  * @param left - Operand to check
94
94
  * @param values - Values to check against
95
95
  * @returns NOT IN expression node
96
96
  */
97
- declare const notInList: (left: OperandNode | ColumnDef, values: (string | number | LiteralNode)[]) => InExpressionNode;
97
+ declare const notInList: (left: OperandNode | ColumnRef, values: (string | number | LiteralNode)[]) => InExpressionNode;
98
98
  /**
99
99
  * Creates a BETWEEN expression (value BETWEEN lower AND upper)
100
100
  * @param left - Operand to check
@@ -102,7 +102,7 @@ declare const notInList: (left: OperandNode | ColumnDef, values: (string | numbe
102
102
  * @param upper - Upper bound
103
103
  * @returns BETWEEN expression node
104
104
  */
105
- declare const between: (left: OperandNode | ColumnDef, lower: OperandNode | ColumnDef | string | number, upper: OperandNode | ColumnDef | string | number) => BetweenExpressionNode;
105
+ declare const between: (left: OperandNode | ColumnRef, lower: OperandNode | ColumnRef | string | number, upper: OperandNode | ColumnRef | string | number) => BetweenExpressionNode;
106
106
  /**
107
107
  * Creates a NOT BETWEEN expression (value NOT BETWEEN lower AND upper)
108
108
  * @param left - Operand to check
@@ -110,14 +110,14 @@ declare const between: (left: OperandNode | ColumnDef, lower: OperandNode | Colu
110
110
  * @param upper - Upper bound
111
111
  * @returns NOT BETWEEN expression node
112
112
  */
113
- declare const notBetween: (left: OperandNode | ColumnDef, lower: OperandNode | ColumnDef | string | number, upper: OperandNode | ColumnDef | string | number) => BetweenExpressionNode;
113
+ declare const notBetween: (left: OperandNode | ColumnRef, lower: OperandNode | ColumnRef | string | number, upper: OperandNode | ColumnRef | string | number) => BetweenExpressionNode;
114
114
  /**
115
115
  * Creates a JSON path expression
116
116
  * @param col - Source column
117
117
  * @param path - JSON path expression
118
118
  * @returns JSON path node
119
119
  */
120
- declare const jsonPath: (col: ColumnDef | ColumnNode, path: string) => JsonPathNode;
120
+ declare const jsonPath: (col: ColumnRef | ColumnNode, path: string) => JsonPathNode;
121
121
  /**
122
122
  * Creates a CASE expression
123
123
  * @param conditions - Array of WHEN-THEN conditions
@@ -126,8 +126,8 @@ declare const jsonPath: (col: ColumnDef | ColumnNode, path: string) => JsonPathN
126
126
  */
127
127
  declare const caseWhen: (conditions: {
128
128
  when: ExpressionNode;
129
- then: OperandNode | ColumnDef | string | number | boolean | null;
130
- }[], elseValue?: OperandNode | ColumnDef | string | number | boolean | null) => CaseExpressionNode;
129
+ then: OperandNode | ColumnRef | string | number | boolean | null;
130
+ }[], elseValue?: OperandNode | ColumnRef | string | number | boolean | null) => CaseExpressionNode;
131
131
  /**
132
132
  * Creates an EXISTS expression
133
133
  * @param subquery - Subquery to check for existence
@@ -169,7 +169,7 @@ declare const ntile: (n: number) => WindowFunctionNode;
169
169
  * @param defaultValue - Default value if no row exists
170
170
  * @returns Window function node for LAG
171
171
  */
172
- declare const lag: (col: ColumnDef | ColumnNode, offset?: number, defaultValue?: any) => WindowFunctionNode;
172
+ declare const lag: (col: ColumnRef | ColumnNode, offset?: number, defaultValue?: any) => WindowFunctionNode;
173
173
  /**
174
174
  * Creates a LEAD window function
175
175
  * @param col - Column to lead
@@ -177,19 +177,19 @@ declare const lag: (col: ColumnDef | ColumnNode, offset?: number, defaultValue?:
177
177
  * @param defaultValue - Default value if no row exists
178
178
  * @returns Window function node for LEAD
179
179
  */
180
- declare const lead: (col: ColumnDef | ColumnNode, offset?: number, defaultValue?: any) => WindowFunctionNode;
180
+ declare const lead: (col: ColumnRef | ColumnNode, offset?: number, defaultValue?: any) => WindowFunctionNode;
181
181
  /**
182
182
  * Creates a FIRST_VALUE window function
183
183
  * @param col - Column to get first value from
184
184
  * @returns Window function node for FIRST_VALUE
185
185
  */
186
- declare const firstValue: (col: ColumnDef | ColumnNode) => WindowFunctionNode;
186
+ declare const firstValue: (col: ColumnRef | ColumnNode) => WindowFunctionNode;
187
187
  /**
188
188
  * Creates a LAST_VALUE window function
189
189
  * @param col - Column to get last value from
190
190
  * @returns Window function node for LAST_VALUE
191
191
  */
192
- declare const lastValue: (col: ColumnDef | ColumnNode) => WindowFunctionNode;
192
+ declare const lastValue: (col: ColumnRef | ColumnNode) => WindowFunctionNode;
193
193
  /**
194
194
  * Creates a custom window function
195
195
  * @param name - Window function name
@@ -198,8 +198,8 @@ declare const lastValue: (col: ColumnDef | ColumnNode) => WindowFunctionNode;
198
198
  * @param orderBy - Optional ORDER BY clauses
199
199
  * @returns Window function node
200
200
  */
201
- declare const windowFunction: (name: string, args?: (ColumnDef | ColumnNode | LiteralNode | JsonPathNode)[], partitionBy?: (ColumnDef | ColumnNode)[], orderBy?: {
202
- column: ColumnDef | ColumnNode;
201
+ declare const windowFunction: (name: string, args?: (ColumnRef | ColumnNode | LiteralNode | JsonPathNode)[], partitionBy?: (ColumnRef | ColumnNode)[], orderBy?: {
202
+ column: ColumnRef | ColumnNode;
203
203
  direction: OrderDirection;
204
204
  }[]) => WindowFunctionNode;
205
205
 
@@ -208,43 +208,62 @@ declare const windowFunction: (name: string, args?: (ColumnDef | ColumnNode | Li
208
208
  * @param col - Column to count
209
209
  * @returns Function node with COUNT
210
210
  */
211
- declare const count: (col: ColumnDef | ColumnNode) => FunctionNode;
211
+ declare const count: (col: ColumnRef | ColumnNode) => FunctionNode;
212
212
  /**
213
213
  * Creates a SUM function expression
214
214
  * @param col - Column to sum
215
215
  * @returns Function node with SUM
216
216
  */
217
- declare const sum: (col: ColumnDef | ColumnNode) => FunctionNode;
217
+ declare const sum: (col: ColumnRef | ColumnNode) => FunctionNode;
218
218
  /**
219
219
  * Creates an AVG function expression
220
220
  * @param col - Column to average
221
221
  * @returns Function node with AVG
222
222
  */
223
- declare const avg: (col: ColumnDef | ColumnNode) => FunctionNode;
223
+ declare const avg: (col: ColumnRef | ColumnNode) => FunctionNode;
224
224
 
225
225
  /**
226
226
  * Visitor for expression nodes
227
227
  */
228
228
  interface ExpressionVisitor<R> {
229
- visitBinaryExpression(node: BinaryExpressionNode): R;
230
- visitLogicalExpression(node: LogicalExpressionNode): R;
231
- visitNullExpression(node: NullExpressionNode): R;
232
- visitInExpression(node: InExpressionNode): R;
233
- visitExistsExpression(node: ExistsExpressionNode): R;
234
- visitBetweenExpression(node: BetweenExpressionNode): R;
229
+ visitBinaryExpression?(node: BinaryExpressionNode): R;
230
+ visitLogicalExpression?(node: LogicalExpressionNode): R;
231
+ visitNullExpression?(node: NullExpressionNode): R;
232
+ visitInExpression?(node: InExpressionNode): R;
233
+ visitExistsExpression?(node: ExistsExpressionNode): R;
234
+ visitBetweenExpression?(node: BetweenExpressionNode): R;
235
+ otherwise?(node: ExpressionNode): R;
235
236
  }
236
237
  /**
237
238
  * Visitor for operand nodes
238
239
  */
239
240
  interface OperandVisitor<R> {
240
- visitColumn(node: ColumnNode): R;
241
- visitLiteral(node: LiteralNode): R;
242
- visitFunction(node: FunctionNode): R;
243
- visitJsonPath(node: JsonPathNode): R;
244
- visitScalarSubquery(node: ScalarSubqueryNode): R;
245
- visitCaseExpression(node: CaseExpressionNode): R;
246
- visitWindowFunction(node: WindowFunctionNode): R;
241
+ visitColumn?(node: ColumnNode): R;
242
+ visitLiteral?(node: LiteralNode): R;
243
+ visitFunction?(node: FunctionNode): R;
244
+ visitJsonPath?(node: JsonPathNode): R;
245
+ visitScalarSubquery?(node: ScalarSubqueryNode): R;
246
+ visitCaseExpression?(node: CaseExpressionNode): R;
247
+ visitWindowFunction?(node: WindowFunctionNode): R;
248
+ otherwise?(node: OperandNode): R;
247
249
  }
250
+ type ExpressionDispatch = <R>(node: any, visitor: ExpressionVisitor<R>) => R;
251
+ type OperandDispatch = <R>(node: any, visitor: OperandVisitor<R>) => R;
252
+ /**
253
+ * Registers a dispatcher for a custom expression node type.
254
+ * Allows new node kinds without modifying the core switch.
255
+ */
256
+ declare const registerExpressionDispatcher: (type: string, dispatcher: ExpressionDispatch) => void;
257
+ /**
258
+ * Registers a dispatcher for a custom operand node type.
259
+ * Allows new node kinds without modifying the core switch.
260
+ */
261
+ declare const registerOperandDispatcher: (type: string, dispatcher: OperandDispatch) => void;
262
+ /**
263
+ * Clears all registered dispatchers. Primarily for tests.
264
+ */
265
+ declare const clearExpressionDispatchers: () => void;
266
+ declare const clearOperandDispatchers: () => void;
248
267
  /**
249
268
  * Dispatches an expression node to the visitor
250
269
  * @param node - Expression node to visit
@@ -258,6 +277,15 @@ declare const visitExpression: <R>(node: ExpressionNode, visitor: ExpressionVisi
258
277
  */
259
278
  declare const visitOperand: <R>(node: OperandNode, visitor: OperandVisitor<R>) => R;
260
279
 
280
+ /**
281
+ * Adapts a schema ColumnDef to an AST-friendly ColumnRef.
282
+ */
283
+ declare const toColumnRef: (col: ColumnRef | ColumnDef) => ColumnRef;
284
+ /**
285
+ * Adapts a schema TableDef to an AST-friendly TableRef.
286
+ */
287
+ declare const toTableRef: (table: TableRef | TableDef) => TableRef;
288
+
261
289
  /**
262
290
  * Maintains immutable state for building INSERT queries
263
291
  */
@@ -270,6 +298,7 @@ declare class InsertQueryState {
270
298
  withReturning(columns: ColumnNode[]): InsertQueryState;
271
299
  }
272
300
 
301
+ type InsertDialectInput = Dialect | DialectKey;
273
302
  /**
274
303
  * Builder for INSERT queries
275
304
  */
@@ -281,7 +310,8 @@ declare class InsertQueryBuilder<T> {
281
310
  values(rowOrRows: Record<string, unknown> | Record<string, unknown>[]): InsertQueryBuilder<T>;
282
311
  returning(...columns: (ColumnDef | ColumnNode)[]): InsertQueryBuilder<T>;
283
312
  compile(compiler: InsertCompiler): CompiledQuery;
284
- toSql(compiler: InsertCompiler): string;
313
+ compile(dialect: InsertDialectInput): CompiledQuery;
314
+ toSql(arg: InsertCompiler | InsertDialectInput): string;
285
315
  getAST(): InsertQueryNode;
286
316
  }
287
317
 
@@ -298,6 +328,7 @@ declare class UpdateQueryState {
298
328
  withReturning(columns: ColumnNode[]): UpdateQueryState;
299
329
  }
300
330
 
331
+ type UpdateDialectInput = Dialect | DialectKey;
301
332
  /**
302
333
  * Builder for UPDATE queries
303
334
  */
@@ -310,7 +341,8 @@ declare class UpdateQueryBuilder<T> {
310
341
  where(expr: ExpressionNode): UpdateQueryBuilder<T>;
311
342
  returning(...columns: (ColumnDef | ColumnNode)[]): UpdateQueryBuilder<T>;
312
343
  compile(compiler: UpdateCompiler): CompiledQuery;
313
- toSql(compiler: UpdateCompiler): string;
344
+ compile(dialect: UpdateDialectInput): CompiledQuery;
345
+ toSql(arg: UpdateCompiler | UpdateDialectInput): string;
314
346
  getAST(): UpdateQueryNode;
315
347
  }
316
348
 
@@ -326,6 +358,7 @@ declare class DeleteQueryState {
326
358
  withReturning(columns: ColumnNode[]): DeleteQueryState;
327
359
  }
328
360
 
361
+ type DeleteDialectInput = Dialect | DialectKey;
329
362
  /**
330
363
  * Builder for DELETE queries
331
364
  */
@@ -337,64 +370,107 @@ declare class DeleteQueryBuilder<T> {
337
370
  where(expr: ExpressionNode): DeleteQueryBuilder<T>;
338
371
  returning(...columns: (ColumnDef | ColumnNode)[]): DeleteQueryBuilder<T>;
339
372
  compile(compiler: DeleteCompiler): CompiledQuery;
340
- toSql(compiler: DeleteCompiler): string;
373
+ compile(dialect: DeleteDialectInput): CompiledQuery;
374
+ toSql(arg: DeleteCompiler | DeleteDialectInput): string;
341
375
  getAST(): DeleteQueryNode;
342
376
  }
343
377
 
378
+ interface FunctionTableNode {
379
+ type: 'FunctionTable';
380
+ schema?: string;
381
+ name: string;
382
+ args?: unknown[];
383
+ lateral?: boolean;
384
+ withOrdinality?: boolean;
385
+ alias?: string;
386
+ columnAliases?: string[];
387
+ }
388
+ interface FunctionTableNode {
389
+ type: 'FunctionTable';
390
+ schema?: string;
391
+ name: string;
392
+ args?: unknown[];
393
+ lateral?: boolean;
394
+ withOrdinality?: boolean;
395
+ alias?: string;
396
+ columnAliases?: string[];
397
+ }
398
+
344
399
  /**
345
- * Shared SQL compiler for dialects with standard LIMIT/OFFSET pagination.
346
- * Concrete dialects override only the minimal hooks (identifier quoting,
347
- * JSON path, placeholders, RETURNING support) instead of re-implementing
348
- * the entire compile pipeline.
400
+ * Strategy interface for compiling pagination clauses.
401
+ * Allows dialects to customize how pagination (LIMIT/OFFSET, ROWS FETCH, etc.) is generated.
349
402
  */
350
- declare abstract class SqlDialectBase extends Dialect {
403
+ interface PaginationStrategy {
351
404
  /**
352
- * Quotes an identifier (dialect-specific).
405
+ * Compiles pagination logic into SQL clause.
406
+ * @param limit - The limit value, if present.
407
+ * @param offset - The offset value, if present.
408
+ * @returns SQL pagination clause (e.g., " LIMIT 10 OFFSET 0") or empty string if no pagination.
353
409
  */
354
- abstract quoteIdentifier(id: string): string;
410
+ compilePagination(limit?: number, offset?: number): string;
411
+ }
412
+
413
+ /**
414
+ * Strategy interface for handling RETURNING clauses in DML statements (INSERT, UPDATE, DELETE).
415
+ * Different SQL dialects have varying levels of support for RETURNING clauses.
416
+ */
417
+ interface ReturningStrategy {
355
418
  /**
356
- * Compiles SELECT query AST to SQL using common rules.
419
+ * Compiles a RETURNING clause for DML statements.
420
+ * @param returning - Array of columns to return, or undefined if none.
421
+ * @param ctx - The compiler context for expression compilation.
422
+ * @returns SQL RETURNING clause or empty string if not supported.
423
+ * @throws Error if RETURNING is not supported by this dialect.
357
424
  */
358
- protected compileSelectAst(ast: SelectQueryNode, ctx: CompilerContext): string;
359
- protected compileInsertAst(ast: InsertQueryNode, ctx: CompilerContext): string;
425
+ compileReturning(returning: ColumnNode[] | undefined, ctx: CompilerContext): string;
360
426
  /**
361
- * Compiles a single SELECT (no set operations, no CTE prefix).
427
+ * Formats column list for RETURNING clause.
428
+ * @param returning - Array of columns to format.
429
+ * @param quoteIdentifier - Function to quote identifiers according to dialect rules.
430
+ * @returns Formatted column list (e.g., "table.col1, table.col2").
362
431
  */
432
+ formatReturningColumns(returning: ColumnNode[], quoteIdentifier: (id: string) => string): string;
433
+ }
434
+
435
+ declare abstract class SqlDialectBase extends Dialect {
436
+ abstract quoteIdentifier(id: string): string;
437
+ protected paginationStrategy: PaginationStrategy;
438
+ protected returningStrategy: ReturningStrategy;
439
+ protected compileSelectAst(ast: SelectQueryNode, ctx: CompilerContext): string;
440
+ private compileSelectWithSetOps;
441
+ protected compileInsertAst(ast: InsertQueryNode, ctx: CompilerContext): string;
442
+ protected compileReturning(returning: ColumnNode[] | undefined, ctx: CompilerContext): string;
443
+ private compileInsertColumnList;
444
+ private compileInsertValues;
363
445
  private compileSelectCore;
364
446
  protected compileUpdateAst(ast: UpdateQueryNode, ctx: CompilerContext): string;
447
+ private compileUpdateAssignments;
365
448
  protected compileDeleteAst(ast: DeleteQueryNode, ctx: CompilerContext): string;
366
- /**
367
- * Default RETURNING compilation: no support.
368
- */
369
- protected compileReturning(returning: ColumnNode[] | undefined, _ctx: CompilerContext): string;
370
449
  protected formatReturningColumns(returning: ColumnNode[]): string;
371
- /**
372
- * DISTINCT clause. Override for DISTINCT ON support.
373
- */
374
450
  protected compileDistinct(ast: SelectQueryNode): string;
375
451
  protected compileSelectColumns(ast: SelectQueryNode, ctx: CompilerContext): string;
376
- protected compileFrom(ast: SelectQueryNode['from']): string;
452
+ protected compileFrom(ast: SelectQueryNode['from'], ctx?: CompilerContext): string;
453
+ protected compileFunctionTable(fn: FunctionTableNode, ctx?: CompilerContext): string;
454
+ protected compileTableSource(table: TableSourceNode): string;
377
455
  protected compileTableName(table: {
378
456
  name: string;
379
457
  schema?: string;
380
458
  }): string;
381
- protected compileJoins(ast: SelectQueryNode, ctx: CompilerContext): string;
382
- protected compileGroupBy(ast: SelectQueryNode): string;
383
459
  protected compileHaving(ast: SelectQueryNode, ctx: CompilerContext): string;
384
- protected compileOrderBy(ast: SelectQueryNode): string;
385
- /**
386
- * Default LIMIT/OFFSET pagination clause.
387
- */
388
- protected compilePagination(ast: SelectQueryNode, _orderByClause: string): string;
389
- protected compileCtes(ast: SelectQueryNode, ctx: CompilerContext): string;
390
460
  protected stripTrailingSemicolon(sql: string): string;
391
461
  protected wrapSetOperand(sql: string): string;
392
462
  }
463
+ interface TableSourceNode {
464
+ name: string;
465
+ schema?: string;
466
+ alias?: string;
467
+ }
393
468
 
394
469
  /**
395
470
  * MySQL dialect implementation
396
471
  */
397
472
  declare class MySqlDialect extends SqlDialectBase {
473
+ protected readonly dialect = "mysql";
398
474
  /**
399
475
  * Creates a new MySqlDialect instance
400
476
  */
@@ -417,6 +493,7 @@ declare class MySqlDialect extends SqlDialectBase {
417
493
  * Microsoft SQL Server dialect implementation
418
494
  */
419
495
  declare class SqlServerDialect extends Dialect {
496
+ protected readonly dialect = "mssql";
420
497
  /**
421
498
  * Creates a new SqlServerDialect instance
422
499
  */
@@ -460,6 +537,7 @@ declare class SqlServerDialect extends Dialect {
460
537
  * SQLite dialect implementation
461
538
  */
462
539
  declare class SqliteDialect extends SqlDialectBase {
540
+ protected readonly dialect = "sqlite";
463
541
  /**
464
542
  * Creates a new SqliteDialect instance
465
543
  */
@@ -484,6 +562,7 @@ declare class SqliteDialect extends SqlDialectBase {
484
562
  * PostgreSQL dialect implementation
485
563
  */
486
564
  declare class PostgresDialect extends SqlDialectBase {
565
+ protected readonly dialect = "postgres";
487
566
  /**
488
567
  * Creates a new PostgresDialect instance
489
568
  */
@@ -504,6 +583,12 @@ declare class PostgresDialect extends SqlDialectBase {
504
583
  supportsReturning(): boolean;
505
584
  }
506
585
 
586
+ interface ColumnDiff {
587
+ typeChanged?: boolean;
588
+ nullabilityChanged?: boolean;
589
+ defaultChanged?: boolean;
590
+ autoIncrementChanged?: boolean;
591
+ }
507
592
  interface DatabaseColumn {
508
593
  name: string;
509
594
  type: string;
@@ -537,82 +622,9 @@ interface DatabaseSchema {
537
622
  tables: DatabaseTable[];
538
623
  }
539
624
 
540
- type TableLike = {
541
- name: string;
542
- schema?: string;
543
- };
544
- /**
545
- * Common behavior for schema dialects (DDL).
546
- * Concrete dialects only override the small surface area instead of reimplementing everything.
547
- */
548
- declare abstract class BaseSchemaDialect implements SchemaDialect {
549
- abstract name: DialectName;
550
- abstract quoteIdentifier(id: string): string;
551
- abstract renderColumnType(column: ColumnDef): string;
552
- abstract renderAutoIncrement(column: ColumnDef, table: TableDef): string | undefined;
553
- abstract renderIndex(table: TableDef, index: IndexDef): string;
554
- supportsPartialIndexes(): boolean;
555
- formatTableName(table: TableLike): string;
556
- renderDefault(value: unknown, _column: ColumnDef): string;
557
- renderReference(ref: ForeignKeyReference, _table: TableDef): string;
558
- renderTableOptions(_table: TableDef): string | undefined;
559
- dropTableSql(table: DatabaseTable): string[];
560
- abstract dropColumnSql(table: DatabaseTable, column: string): string[];
561
- abstract dropIndexSql(table: DatabaseTable, index: string): string[];
562
- warnDropColumn(_table: DatabaseTable, _column: string): string | undefined;
563
- }
564
-
565
- declare class PostgresSchemaDialect extends BaseSchemaDialect {
566
- name: DialectName;
567
- quoteIdentifier(id: string): string;
568
- renderColumnType(column: ColumnDef): string;
569
- renderAutoIncrement(column: ColumnDef): string | undefined;
570
- renderIndex(table: TableDef, index: IndexDef): string;
571
- supportsPartialIndexes(): boolean;
572
- dropColumnSql(table: DatabaseTable, column: string): string[];
573
- dropIndexSql(table: DatabaseTable, index: string): string[];
574
- }
575
-
576
- declare class MySqlSchemaDialect extends BaseSchemaDialect {
577
- name: DialectName;
578
- quoteIdentifier(id: string): string;
579
- renderColumnType(column: ColumnDef): string;
580
- renderDefault(value: unknown): string;
581
- renderAutoIncrement(column: ColumnDef): string | undefined;
582
- renderIndex(table: TableDef, index: IndexDef): string;
583
- renderTableOptions(table: TableDef): string | undefined;
584
- dropColumnSql(table: DatabaseTable, column: string): string[];
585
- dropIndexSql(table: DatabaseTable, index: string): string[];
586
- }
587
-
588
- declare class SQLiteSchemaDialect extends BaseSchemaDialect {
589
- name: DialectName;
590
- quoteIdentifier(id: string): string;
591
- renderColumnType(column: ColumnDef): string;
592
- renderAutoIncrement(column: ColumnDef, table: TableDef): string | undefined;
593
- preferInlinePkAutoincrement(column: ColumnDef, table: TableDef, pk: string[]): boolean;
594
- renderDefault(value: unknown): string;
595
- renderIndex(table: TableDef, index: IndexDef): string;
596
- dropColumnSql(_table: DatabaseTable, _column: string): string[];
597
- dropIndexSql(_table: DatabaseTable, index: string): string[];
598
- warnDropColumn(table: DatabaseTable, column: string): string | undefined;
599
- }
600
-
601
- declare class MSSqlSchemaDialect extends BaseSchemaDialect {
602
- name: DialectName;
603
- quoteIdentifier(id: string): string;
604
- renderColumnType(column: ColumnDef): string;
605
- renderDefault(value: unknown): string;
606
- renderAutoIncrement(column: ColumnDef): string | undefined;
607
- renderIndex(table: TableDef, index: IndexDef): string;
608
- supportsPartialIndexes(): boolean;
609
- dropColumnSql(table: DatabaseTable, column: string): string[];
610
- dropIndexSql(table: DatabaseTable, index: string): string[];
611
- }
612
-
613
- type DialectName = 'postgres' | 'mysql' | 'sqlite' | 'mssql';
625
+ type DialectName = 'postgres' | 'mysql' | 'sqlite' | 'mssql' | (string & {});
614
626
  interface SchemaDialect {
615
- name: DialectName;
627
+ readonly name: DialectName;
616
628
  quoteIdentifier(id: string): string;
617
629
  formatTableName(table: TableDef | DatabaseTable): string;
618
630
  renderColumnType(column: ColumnDef): string;
@@ -622,22 +634,18 @@ interface SchemaDialect {
622
634
  renderIndex(table: TableDef, index: IndexDef): string;
623
635
  renderTableOptions(table: TableDef): string | undefined;
624
636
  supportsPartialIndexes(): boolean;
625
- preferInlinePkAutoincrement?(column: ColumnDef, table: TableDef, pk: string[]): boolean;
626
- dropColumnSql(table: DatabaseTable, column: string): string[];
627
- dropIndexSql(table: DatabaseTable, index: string): string[];
628
- dropTableSql(table: DatabaseTable): string[];
637
+ dropColumnSql?(table: DatabaseTable, column: string): string[];
638
+ dropIndexSql?(table: DatabaseTable, index: string): string[];
639
+ dropTableSql?(table: DatabaseTable): string[];
629
640
  warnDropColumn?(table: DatabaseTable, column: string): string | undefined;
641
+ alterColumnSql?(table: TableDef, column: ColumnDef, actualColumn: DatabaseColumn, diff: ColumnDiff): string[];
642
+ warnAlterColumn?(table: TableDef, column: ColumnDef, actualColumn: DatabaseColumn, diff: ColumnDiff): string | undefined;
630
643
  }
644
+
631
645
  interface SchemaGenerateResult {
632
646
  tableSql: string;
633
647
  indexSql: string[];
634
648
  }
635
- declare const escapeLiteral: (value: string) => string;
636
- declare const formatLiteral: (value: unknown, dialect: DialectName) => string;
637
- declare const resolvePrimaryKey: (table: TableDef) => string[];
638
- declare const quoteQualified: (dialect: SchemaDialect, identifier: string) => string;
639
- declare const renderIndexColumns: (dialect: SchemaDialect, columns: (string | IndexColumn)[]) => string;
640
- declare const deriveIndexName: (table: TableDef, index: IndexDef) => string;
641
649
  interface RenderColumnOptions {
642
650
  includePrimary?: boolean;
643
651
  }
@@ -670,6 +678,11 @@ interface SynchronizeOptions extends SchemaDiffOptions {
670
678
  }
671
679
  declare const synchronizeSchema: (expectedTables: TableDef[], actualSchema: DatabaseSchema, dialect: SchemaDialect, executor: DbExecutor, options?: SynchronizeOptions) => Promise<SchemaPlan>;
672
680
 
681
+ interface IntrospectContext {
682
+ dialect: Dialect;
683
+ executor: DbExecutor;
684
+ }
685
+
673
686
  /**
674
687
  * Dialect-agnostic options for schema introspection.
675
688
  */
@@ -683,7 +696,7 @@ interface IntrospectOptions {
683
696
  * Strategy interface implemented per dialect to introspect an existing database schema.
684
697
  */
685
698
  interface SchemaIntrospector {
686
- introspect(executor: DbExecutor, options: IntrospectOptions): Promise<DatabaseSchema>;
699
+ introspect(ctx: IntrospectContext, options: IntrospectOptions): Promise<DatabaseSchema>;
687
700
  }
688
701
 
689
702
  /**
@@ -691,6 +704,310 @@ interface SchemaIntrospector {
691
704
  */
692
705
  declare const introspectSchema: (executor: DbExecutor, dialect: DialectName, options?: IntrospectOptions) => Promise<DatabaseSchema>;
693
706
 
707
+ declare const registerSchemaIntrospector: (dialect: DialectName, introspector: SchemaIntrospector) => void;
708
+ declare const getSchemaIntrospector: (dialect: DialectName) => SchemaIntrospector | undefined;
709
+
710
+ type OperandInput$2 = OperandNode | ColumnDef | string | number | boolean | null;
711
+ /**
712
+ * Helper: LOWER(str)
713
+ */
714
+ declare const lower: (value: OperandInput$2) => FunctionNode;
715
+ /**
716
+ * Helper: UPPER(str)
717
+ */
718
+ declare const upper: (value: OperandInput$2) => FunctionNode;
719
+ /**
720
+ * Helper: ASCII(str)
721
+ */
722
+ declare const ascii: (value: OperandInput$2) => FunctionNode;
723
+ /**
724
+ * Helper: CHAR(code[, code...])
725
+ */
726
+ declare const char: (...codes: OperandInput$2[]) => FunctionNode;
727
+ /**
728
+ * Helper: CHAR_LENGTH(str)
729
+ */
730
+ declare const charLength: (value: OperandInput$2) => FunctionNode;
731
+ /**
732
+ * Helper: LENGTH(str)
733
+ */
734
+ declare const length: (value: OperandInput$2) => FunctionNode;
735
+ /**
736
+ * Helper: TRIM([chars FROM] str)
737
+ */
738
+ declare const trim: (value: OperandInput$2, chars?: OperandInput$2) => FunctionNode;
739
+ /**
740
+ * Helper: LTRIM(str)
741
+ */
742
+ declare const ltrim: (value: OperandInput$2) => FunctionNode;
743
+ /**
744
+ * Helper: RTRIM(str)
745
+ */
746
+ declare const rtrim: (value: OperandInput$2) => FunctionNode;
747
+ /**
748
+ * Helper: CONCAT(arg1, arg2, ...)
749
+ */
750
+ declare const concat: (...args: OperandInput$2[]) => FunctionNode;
751
+ /**
752
+ * Helper: CONCAT_WS(separator, arg1, arg2, ...)
753
+ */
754
+ declare const concatWs: (separator: OperandInput$2, ...args: OperandInput$2[]) => FunctionNode;
755
+ /**
756
+ * Helper: SUBSTR(str, start[, length])
757
+ */
758
+ declare const substr: (value: OperandInput$2, start: OperandInput$2, length?: OperandInput$2) => FunctionNode;
759
+ /**
760
+ * Helper: LEFT(str, length)
761
+ */
762
+ declare const left: (value: OperandInput$2, len: OperandInput$2) => FunctionNode;
763
+ /**
764
+ * Helper: RIGHT(str, length)
765
+ */
766
+ declare const right: (value: OperandInput$2, len: OperandInput$2) => FunctionNode;
767
+ /**
768
+ * Helper: POSITION(substring IN string)
769
+ */
770
+ declare const position: (substring: OperandInput$2, value: OperandInput$2) => FunctionNode;
771
+ /**
772
+ * Helper: INSTR(string, substring)
773
+ */
774
+ declare const instr: (value: OperandInput$2, substring: OperandInput$2) => FunctionNode;
775
+ /**
776
+ * Helper: LOCATE(substring, string[, start])
777
+ */
778
+ declare const locate: (substring: OperandInput$2, value: OperandInput$2, start?: OperandInput$2) => FunctionNode;
779
+ /**
780
+ * Helper: REPLACE(string, search, replace)
781
+ */
782
+ declare const replace: (value: OperandInput$2, search: OperandInput$2, replacement: OperandInput$2) => FunctionNode;
783
+ /**
784
+ * Helper: REPEAT(string, count)
785
+ */
786
+ declare const repeat: (value: OperandInput$2, count: OperandInput$2) => FunctionNode;
787
+ /**
788
+ * Helper: LPAD(string, length, padstr)
789
+ */
790
+ declare const lpad: (value: OperandInput$2, len: OperandInput$2, pad: OperandInput$2) => FunctionNode;
791
+ /**
792
+ * Helper: RPAD(string, length, padstr)
793
+ */
794
+ declare const rpad: (value: OperandInput$2, len: OperandInput$2, pad: OperandInput$2) => FunctionNode;
795
+ /**
796
+ * Helper: SPACE(count)
797
+ */
798
+ declare const space: (count: OperandInput$2) => FunctionNode;
799
+
800
+ type OperandInput$1 = OperandNode | ColumnDef | string | number | boolean | null;
801
+ /**
802
+ * Helper: ABS(x) - Returns the absolute value of a number
803
+ */
804
+ declare const abs: (value: OperandInput$1) => FunctionNode;
805
+ /**
806
+ * Helper: ACOS(x) - Returns the arccosine (inverse cosine)
807
+ */
808
+ declare const acos: (value: OperandInput$1) => FunctionNode;
809
+ /**
810
+ * Helper: ASIN(x) - Returns the arcsine (inverse sine)
811
+ */
812
+ declare const asin: (value: OperandInput$1) => FunctionNode;
813
+ /**
814
+ * Helper: ATAN(x) - Returns the arctangent (inverse tangent)
815
+ */
816
+ declare const atan: (value: OperandInput$1) => FunctionNode;
817
+ /**
818
+ * Helper: ATAN2(y, x) - Returns the arctangent of the two arguments
819
+ */
820
+ declare const atan2: (y: OperandInput$1, x: OperandInput$1) => FunctionNode;
821
+ /**
822
+ * Helper: CEIL(x) / CEILING(x) - Returns the smallest integer >= x
823
+ */
824
+ declare const ceil: (value: OperandInput$1) => FunctionNode;
825
+ /**
826
+ * Helper: CEILING(x) - Alias for CEIL
827
+ */
828
+ declare const ceiling: (value: OperandInput$1) => FunctionNode;
829
+ /**
830
+ * Helper: COS(x) - Returns the cosine of a number (in radians)
831
+ */
832
+ declare const cos: (value: OperandInput$1) => FunctionNode;
833
+ /**
834
+ * Helper: COT(x) - Returns the cotangent of a number
835
+ */
836
+ declare const cot: (value: OperandInput$1) => FunctionNode;
837
+ /**
838
+ * Helper: DEGREES(x) - Converts radians to degrees
839
+ */
840
+ declare const degrees: (value: OperandInput$1) => FunctionNode;
841
+ /**
842
+ * Helper: EXP(x) - Returns e raised to the power of the argument
843
+ */
844
+ declare const exp: (value: OperandInput$1) => FunctionNode;
845
+ /**
846
+ * Helper: FLOOR(x) - Returns the largest integer <= x
847
+ */
848
+ declare const floor: (value: OperandInput$1) => FunctionNode;
849
+ /**
850
+ * Helper: LN(x) - Returns the natural logarithm (base e)
851
+ */
852
+ declare const ln: (value: OperandInput$1) => FunctionNode;
853
+ /**
854
+ * Helper: LOG(x) - Returns the base-10 logarithm
855
+ */
856
+ declare const log: (value: OperandInput$1) => FunctionNode;
857
+ /**
858
+ * Helper: LOG10(x) - Returns the base-10 logarithm
859
+ */
860
+ declare const log10: (value: OperandInput$1) => FunctionNode;
861
+ /**
862
+ * Helper: LOG(base, x) - Returns the logarithm of x for a specific base
863
+ */
864
+ declare const logBase: (base: OperandInput$1, value: OperandInput$1) => FunctionNode;
865
+ /**
866
+ * Helper: MOD(x, y) - Returns the remainder of x/y
867
+ */
868
+ declare const mod: (x: OperandInput$1, y: OperandInput$1) => FunctionNode;
869
+ /**
870
+ * Helper: PI() - Returns the value of PI (approx. 3.14159...)
871
+ */
872
+ declare const pi: () => FunctionNode;
873
+ /**
874
+ * Helper: POWER(x, y) - Returns x raised to the power of y
875
+ */
876
+ declare const power: (x: OperandInput$1, y: OperandInput$1) => FunctionNode;
877
+ /**
878
+ * Helper: POW(x, y) - Alias for POWER
879
+ */
880
+ declare const pow: (x: OperandInput$1, y: OperandInput$1) => FunctionNode;
881
+ /**
882
+ * Helper: RADIANS(x) - Converts degrees to radians
883
+ */
884
+ declare const radians: (value: OperandInput$1) => FunctionNode;
885
+ /**
886
+ * Helper: RAND() / RANDOM() - Returns a random number
887
+ */
888
+ declare const random: () => FunctionNode;
889
+ /**
890
+ * Helper: RAND() - Alias for RANDOM (returns float 0-1)
891
+ */
892
+ declare const rand: () => FunctionNode;
893
+ /**
894
+ * Helper: ROUND(x[, decimals]) - Rounds a number to specified decimal places
895
+ */
896
+ declare const round: (value: OperandInput$1, decimals?: OperandInput$1) => FunctionNode;
897
+ /**
898
+ * Helper: SIGN(x) - Returns the sign of a number (-1, 0, 1)
899
+ */
900
+ declare const sign: (value: OperandInput$1) => FunctionNode;
901
+ /**
902
+ * Helper: SIN(x) - Returns the sine of a number (in radians)
903
+ */
904
+ declare const sin: (value: OperandInput$1) => FunctionNode;
905
+ /**
906
+ * Helper: SQRT(x) - Returns the square root of a number
907
+ */
908
+ declare const sqrt: (value: OperandInput$1) => FunctionNode;
909
+ /**
910
+ * Helper: TAN(x) - Returns the tangent of a number (in radians)
911
+ */
912
+ declare const tan: (value: OperandInput$1) => FunctionNode;
913
+ /**
914
+ * Helper: TRUNC(x[, decimals]) / TRUNCATE(x, decimals) - Truncates a number without rounding
915
+ */
916
+ declare const trunc: (value: OperandInput$1, decimals?: OperandInput$1) => FunctionNode;
917
+ /**
918
+ * Helper: TRUNCATE(x, decimals) - Alias for TRUNC
919
+ */
920
+ declare const truncate: (value: OperandInput$1, decimals: OperandInput$1) => FunctionNode;
921
+
922
+ type OperandInput = OperandNode | ColumnDef | string | number | boolean | null;
923
+ /**
924
+ * Helper: NOW() - Returns the current local date and time
925
+ */
926
+ declare const now: () => FunctionNode;
927
+ /**
928
+ * Helper: CURRENT_DATE - Returns only the current date (no time)
929
+ */
930
+ declare const currentDate: () => FunctionNode;
931
+ /**
932
+ * Helper: CURRENT_TIME - Returns only the current time
933
+ */
934
+ declare const currentTime: () => FunctionNode;
935
+ /**
936
+ * Helper: UTC_NOW() - Returns current UTC/GMT date and time
937
+ */
938
+ declare const utcNow: () => FunctionNode;
939
+ /**
940
+ * Helper: EXTRACT(part FROM date) - Extracts a part (year, month, day, hour, etc.) from a date
941
+ * @param part - The date part to extract (e.g., 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND')
942
+ * @param date - The date/datetime value
943
+ */
944
+ declare const extract: (part: OperandInput, date: OperandInput) => FunctionNode;
945
+ /**
946
+ * Helper: YEAR(date) - Extracts the year from a date
947
+ */
948
+ declare const year: (date: OperandInput) => FunctionNode;
949
+ /**
950
+ * Helper: MONTH(date) - Extracts the month from a date
951
+ */
952
+ declare const month: (date: OperandInput) => FunctionNode;
953
+ /**
954
+ * Helper: DAY(date) - Extracts the day from a date
955
+ */
956
+ declare const day: (date: OperandInput) => FunctionNode;
957
+ /**
958
+ * Helper: DATE_ADD(date, interval, unit) - Adds a specific time interval to a date
959
+ * @param date - The date/datetime value
960
+ * @param interval - The number of units to add
961
+ * @param unit - The unit type (e.g., 'DAY', 'MONTH', 'YEAR', 'HOUR', 'MINUTE', 'SECOND')
962
+ */
963
+ declare const dateAdd: (date: OperandInput, interval: OperandInput, unit: OperandInput) => FunctionNode;
964
+ /**
965
+ * Helper: DATE_SUB(date, interval, unit) - Subtracts a specific time interval from a date
966
+ * @param date - The date/datetime value
967
+ * @param interval - The number of units to subtract
968
+ * @param unit - The unit type (e.g., 'DAY', 'MONTH', 'YEAR', 'HOUR', 'MINUTE', 'SECOND')
969
+ */
970
+ declare const dateSub: (date: OperandInput, interval: OperandInput, unit: OperandInput) => FunctionNode;
971
+ /**
972
+ * Helper: DATE_DIFF(date1, date2) - Returns the difference between two dates in days
973
+ * @param date1 - The end date
974
+ * @param date2 - The start date
975
+ */
976
+ declare const dateDiff: (date1: OperandInput, date2: OperandInput) => FunctionNode;
977
+ /**
978
+ * Helper: DATE_FORMAT(date, format) - Converts a date to a formatted string
979
+ * @param date - The date/datetime value
980
+ * @param format - The format string (dialect-specific)
981
+ */
982
+ declare const dateFormat: (date: OperandInput, format: OperandInput) => FunctionNode;
983
+ /**
984
+ * Helper: UNIX_TIMESTAMP() - Returns the current Unix epoch (seconds since 1970)
985
+ */
986
+ declare const unixTimestamp: () => FunctionNode;
987
+ /**
988
+ * Helper: FROM_UNIXTIME(timestamp) - Converts Unix epoch seconds to a date
989
+ * @param timestamp - Unix timestamp in seconds
990
+ */
991
+ declare const fromUnixTime: (timestamp: OperandInput) => FunctionNode;
992
+ /**
993
+ * Helper: END_OF_MONTH(date) - Returns the last day of the month for a given date
994
+ */
995
+ declare const endOfMonth: (date: OperandInput) => FunctionNode;
996
+ /**
997
+ * Helper: DAY_OF_WEEK(date) - Returns the index of the weekday
998
+ */
999
+ declare const dayOfWeek: (date: OperandInput) => FunctionNode;
1000
+ /**
1001
+ * Helper: WEEK_OF_YEAR(date) - Returns the week number of the year
1002
+ */
1003
+ declare const weekOfYear: (date: OperandInput) => FunctionNode;
1004
+ /**
1005
+ * Helper: DATE_TRUNC(part, date) - Resets date precision (e.g., first day of the month/year)
1006
+ * @param part - The truncation precision (e.g., 'YEAR', 'MONTH', 'DAY')
1007
+ * @param date - The date/datetime value
1008
+ */
1009
+ declare const dateTrunc: (part: OperandInput, date: OperandInput) => FunctionNode;
1010
+
694
1011
  /**
695
1012
  * Browser-compatible implementation of AsyncLocalStorage
696
1013
  * Provides a simple in-memory store for browser environments
@@ -858,6 +1175,7 @@ declare const createEntityFromRow: <TTable extends TableDef>(ctx: OrmContext, ta
858
1175
 
859
1176
  type Rows$3 = Record<string, any>[];
860
1177
  declare const loadHasManyRelation: (ctx: OrmContext, rootTable: TableDef, _relationName: string, relation: HasManyRelation) => Promise<Map<string, Rows$3>>;
1178
+ declare const loadHasOneRelation: (ctx: OrmContext, rootTable: TableDef, _relationName: string, relation: HasOneRelation) => Promise<Map<string, Record<string, any>>>;
861
1179
  declare const loadBelongsToRelation: (ctx: OrmContext, rootTable: TableDef, _relationName: string, relation: BelongsToRelation) => Promise<Map<string, Record<string, any>>>;
862
1180
  declare const loadBelongsToManyRelation: (ctx: OrmContext, rootTable: TableDef, _relationName: string, relation: BelongsToManyRelation) => Promise<Map<string, Rows$3>>;
863
1181
 
@@ -948,4 +1266,38 @@ declare class DefaultManyToManyCollection<TTarget> implements ManyToManyCollecti
948
1266
 
949
1267
  declare function executeHydrated<TTable extends TableDef>(ctx: OrmContext, qb: SelectQueryBuilder<any, TTable>): Promise<Entity<TTable>[]>;
950
1268
 
951
- export { AsyncLocalStorage, BaseSchemaDialect, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, ColumnNode, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, HasManyCollection, HasManyRelation, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, LogicalExpressionNode, MSSqlSchemaDialect, ManyToManyCollection, MySqlDialect, MySqlSchemaDialect, NullExpressionNode, OperandNode, type OperandVisitor, OrmContext, PostgresDialect, PostgresSchemaDialect, RelationMap, type RenderColumnOptions, SQLiteSchemaDialect, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDialect, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, SqliteDialect, type SynchronizeOptions, TableDef, TypeScriptGenerator, UpdateQueryBuilder, WindowFunctionNode, and, avg, between, caseWhen, columnOperand, count, createEntityFromRow, createEntityProxy, denseRank, deriveIndexName, diffSchema, eq, escapeLiteral, executeHydrated, exists, firstValue, formatLiteral, generateCreateTableSql, generateSchemaSql, gt, gte, hydrateRows, inList, introspectSchema, isNotNull, isNull, jsonPath, lag, lastValue, lead, like, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, lt, lte, neq, notBetween, notExists, notInList, notLike, ntile, or, quoteQualified, rank, renderColumnDefinition, renderIndexColumns, resolvePrimaryKey, rowNumber, sum, synchronizeSchema, valueToOperand, visitExpression, visitOperand, windowFunction };
1269
+ interface PostgresClientLike {
1270
+ query(text: string, params?: unknown[]): Promise<{
1271
+ rows: Array<Record<string, unknown>>;
1272
+ }>;
1273
+ }
1274
+ declare function createPostgresExecutor(client: PostgresClientLike): DbExecutor;
1275
+
1276
+ interface MysqlClientLike {
1277
+ query(sql: string, params?: unknown[]): Promise<[any, any?]>;
1278
+ beginTransaction?(): Promise<void>;
1279
+ commit?(): Promise<void>;
1280
+ rollback?(): Promise<void>;
1281
+ }
1282
+ declare function createMysqlExecutor(client: MysqlClientLike): DbExecutor;
1283
+
1284
+ interface SqliteClientLike {
1285
+ all(sql: string, params?: unknown[]): Promise<Array<Record<string, unknown>>>;
1286
+ run?(sql: string, params?: unknown[]): Promise<unknown>;
1287
+ beginTransaction?(): Promise<void>;
1288
+ commitTransaction?(): Promise<void>;
1289
+ rollbackTransaction?(): Promise<void>;
1290
+ }
1291
+ declare function createSqliteExecutor(client: SqliteClientLike): DbExecutor;
1292
+
1293
+ interface MssqlClientLike {
1294
+ query(sql: string, params?: unknown[]): Promise<{
1295
+ recordset: Array<Record<string, unknown>>;
1296
+ }>;
1297
+ beginTransaction?(): Promise<void>;
1298
+ commit?(): Promise<void>;
1299
+ rollback?(): Promise<void>;
1300
+ }
1301
+ declare function createMssqlExecutor(client: MssqlClientLike): DbExecutor;
1302
+
1303
+ export { AsyncLocalStorage, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, type ColumnDiff, ColumnNode, ColumnRef, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, HasManyCollection, HasManyRelation, HasOneRelation, HydrationPlan, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, LogicalExpressionNode, ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, NullExpressionNode, OperandNode, type OperandVisitor, OrmContext, type PostgresClientLike, PostgresDialect, RelationMap, type RenderColumnOptions, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, TableDef, TableRef, TypeScriptGenerator, UpdateQueryBuilder, WindowFunctionNode, abs, acos, and, ascii, asin, atan, atan2, avg, between, caseWhen, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, columnOperand, concat, concatWs, cos, cot, count, createEntityFromRow, createEntityProxy, createMssqlExecutor, createMysqlExecutor, createPostgresExecutor, createSqliteExecutor, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, degrees, denseRank, diffSchema, endOfMonth, eq, executeHydrated, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, gt, gte, hydrateRows, inList, instr, introspectSchema, isNotNull, isNull, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, mod, month, neq, notBetween, notExists, notInList, notLike, now, ntile, or, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rpad, rtrim, sign, sin, space, sqrt, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };