@simplysm/orm-common 13.0.99 → 14.0.1

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 (238) hide show
  1. package/dist/create-db-context.d.ts +10 -10
  2. package/dist/create-db-context.js +312 -276
  3. package/dist/create-db-context.js.map +1 -6
  4. package/dist/ddl/column-ddl.d.ts +4 -4
  5. package/dist/ddl/column-ddl.js +41 -35
  6. package/dist/ddl/column-ddl.js.map +1 -6
  7. package/dist/ddl/initialize.d.ts +17 -17
  8. package/dist/ddl/initialize.js +200 -142
  9. package/dist/ddl/initialize.js.map +1 -6
  10. package/dist/ddl/relation-ddl.d.ts +6 -6
  11. package/dist/ddl/relation-ddl.js +55 -48
  12. package/dist/ddl/relation-ddl.js.map +1 -6
  13. package/dist/ddl/schema-ddl.d.ts +4 -4
  14. package/dist/ddl/schema-ddl.js +21 -15
  15. package/dist/ddl/schema-ddl.js.map +1 -6
  16. package/dist/ddl/table-ddl.d.ts +20 -20
  17. package/dist/ddl/table-ddl.js +139 -93
  18. package/dist/ddl/table-ddl.js.map +1 -6
  19. package/dist/define-db-context.js +10 -13
  20. package/dist/define-db-context.js.map +1 -6
  21. package/dist/errors/db-transaction-error.d.ts +15 -15
  22. package/dist/errors/db-transaction-error.d.ts.map +1 -1
  23. package/dist/errors/db-transaction-error.js +53 -19
  24. package/dist/errors/db-transaction-error.js.map +1 -6
  25. package/dist/exec/executable.d.ts +23 -23
  26. package/dist/exec/executable.js +94 -40
  27. package/dist/exec/executable.js.map +1 -6
  28. package/dist/exec/queryable.d.ts +97 -97
  29. package/dist/exec/queryable.js +1310 -1204
  30. package/dist/exec/queryable.js.map +1 -6
  31. package/dist/exec/search-parser.d.ts +31 -31
  32. package/dist/exec/search-parser.d.ts.map +1 -1
  33. package/dist/exec/search-parser.js +158 -59
  34. package/dist/exec/search-parser.js.map +1 -6
  35. package/dist/expr/expr-unit.d.ts +4 -4
  36. package/dist/expr/expr-unit.js +24 -18
  37. package/dist/expr/expr-unit.js.map +1 -6
  38. package/dist/expr/expr.d.ts +6 -6
  39. package/dist/expr/expr.js +1872 -1844
  40. package/dist/expr/expr.js.map +1 -6
  41. package/dist/index.js +23 -1
  42. package/dist/index.js.map +1 -6
  43. package/dist/models/system-migration.js +7 -7
  44. package/dist/models/system-migration.js.map +1 -6
  45. package/dist/query-builder/base/expr-renderer-base.d.ts +10 -10
  46. package/dist/query-builder/base/expr-renderer-base.js +27 -21
  47. package/dist/query-builder/base/expr-renderer-base.js.map +1 -6
  48. package/dist/query-builder/base/query-builder-base.d.ts +21 -21
  49. package/dist/query-builder/base/query-builder-base.d.ts.map +1 -1
  50. package/dist/query-builder/base/query-builder-base.js +90 -80
  51. package/dist/query-builder/base/query-builder-base.js.map +1 -6
  52. package/dist/query-builder/mssql/mssql-expr-renderer.d.ts +4 -4
  53. package/dist/query-builder/mssql/mssql-expr-renderer.d.ts.map +1 -1
  54. package/dist/query-builder/mssql/mssql-expr-renderer.js +447 -420
  55. package/dist/query-builder/mssql/mssql-expr-renderer.js.map +1 -6
  56. package/dist/query-builder/mssql/mssql-query-builder.js +483 -443
  57. package/dist/query-builder/mssql/mssql-query-builder.js.map +1 -6
  58. package/dist/query-builder/mysql/mysql-expr-renderer.d.ts +4 -4
  59. package/dist/query-builder/mysql/mysql-expr-renderer.d.ts.map +1 -1
  60. package/dist/query-builder/mysql/mysql-expr-renderer.js +451 -419
  61. package/dist/query-builder/mysql/mysql-expr-renderer.js.map +1 -6
  62. package/dist/query-builder/mysql/mysql-query-builder.js +570 -479
  63. package/dist/query-builder/mysql/mysql-query-builder.js.map +1 -6
  64. package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts +4 -4
  65. package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts.map +1 -1
  66. package/dist/query-builder/postgresql/postgresql-expr-renderer.js +449 -422
  67. package/dist/query-builder/postgresql/postgresql-expr-renderer.js.map +1 -6
  68. package/dist/query-builder/postgresql/postgresql-query-builder.js +511 -460
  69. package/dist/query-builder/postgresql/postgresql-query-builder.js.map +1 -6
  70. package/dist/query-builder/query-builder.d.ts +1 -1
  71. package/dist/query-builder/query-builder.js +13 -13
  72. package/dist/query-builder/query-builder.js.map +1 -6
  73. package/dist/schema/factory/column-builder.d.ts +84 -84
  74. package/dist/schema/factory/column-builder.js +248 -185
  75. package/dist/schema/factory/column-builder.js.map +1 -6
  76. package/dist/schema/factory/index-builder.d.ts +38 -38
  77. package/dist/schema/factory/index-builder.js +144 -85
  78. package/dist/schema/factory/index-builder.js.map +1 -6
  79. package/dist/schema/factory/relation-builder.d.ts +91 -91
  80. package/dist/schema/factory/relation-builder.d.ts.map +1 -1
  81. package/dist/schema/factory/relation-builder.js +274 -136
  82. package/dist/schema/factory/relation-builder.js.map +1 -6
  83. package/dist/schema/procedure-builder.d.ts +51 -51
  84. package/dist/schema/procedure-builder.d.ts.map +1 -1
  85. package/dist/schema/procedure-builder.js +205 -131
  86. package/dist/schema/procedure-builder.js.map +1 -6
  87. package/dist/schema/table-builder.d.ts +55 -55
  88. package/dist/schema/table-builder.d.ts.map +1 -1
  89. package/dist/schema/table-builder.js +274 -205
  90. package/dist/schema/table-builder.js.map +1 -6
  91. package/dist/schema/view-builder.d.ts +44 -44
  92. package/dist/schema/view-builder.d.ts.map +1 -1
  93. package/dist/schema/view-builder.js +189 -116
  94. package/dist/schema/view-builder.js.map +1 -6
  95. package/dist/types/column.js +60 -30
  96. package/dist/types/column.js.map +1 -6
  97. package/dist/types/db-context-def.d.ts +9 -9
  98. package/dist/types/db-context-def.js +2 -1
  99. package/dist/types/db-context-def.js.map +1 -6
  100. package/dist/types/db.d.ts +47 -47
  101. package/dist/types/db.js +15 -5
  102. package/dist/types/db.js.map +1 -6
  103. package/dist/types/expr.d.ts +81 -81
  104. package/dist/types/expr.d.ts.map +1 -1
  105. package/dist/types/expr.js +3 -1
  106. package/dist/types/expr.js.map +1 -6
  107. package/dist/types/query-def.d.ts +46 -46
  108. package/dist/types/query-def.d.ts.map +1 -1
  109. package/dist/types/query-def.js +31 -24
  110. package/dist/types/query-def.js.map +1 -6
  111. package/dist/utils/result-parser.js +362 -221
  112. package/dist/utils/result-parser.js.map +1 -6
  113. package/package.json +5 -7
  114. package/src/create-db-context.ts +31 -31
  115. package/src/ddl/column-ddl.ts +4 -4
  116. package/src/ddl/initialize.ts +38 -38
  117. package/src/ddl/relation-ddl.ts +6 -6
  118. package/src/ddl/schema-ddl.ts +4 -4
  119. package/src/ddl/table-ddl.ts +24 -24
  120. package/src/errors/db-transaction-error.ts +13 -13
  121. package/src/exec/executable.ts +25 -25
  122. package/src/exec/queryable.ts +134 -134
  123. package/src/exec/search-parser.ts +50 -50
  124. package/src/expr/expr-unit.ts +4 -4
  125. package/src/expr/expr.ts +13 -13
  126. package/src/index.ts +8 -8
  127. package/src/models/system-migration.ts +1 -1
  128. package/src/query-builder/base/expr-renderer-base.ts +21 -21
  129. package/src/query-builder/base/query-builder-base.ts +33 -33
  130. package/src/query-builder/mssql/mssql-expr-renderer.ts +11 -11
  131. package/src/query-builder/mssql/mssql-query-builder.ts +11 -11
  132. package/src/query-builder/mysql/mysql-expr-renderer.ts +15 -15
  133. package/src/query-builder/mysql/mysql-query-builder.ts +3 -3
  134. package/src/query-builder/postgresql/postgresql-expr-renderer.ts +9 -9
  135. package/src/query-builder/postgresql/postgresql-query-builder.ts +7 -7
  136. package/src/query-builder/query-builder.ts +1 -1
  137. package/src/schema/factory/column-builder.ts +86 -86
  138. package/src/schema/factory/index-builder.ts +38 -38
  139. package/src/schema/factory/relation-builder.ts +93 -93
  140. package/src/schema/procedure-builder.ts +52 -52
  141. package/src/schema/table-builder.ts +56 -56
  142. package/src/schema/view-builder.ts +45 -45
  143. package/src/types/column.ts +1 -1
  144. package/src/types/db-context-def.ts +15 -15
  145. package/src/types/db.ts +50 -50
  146. package/src/types/expr.ts +103 -103
  147. package/src/types/query-def.ts +50 -50
  148. package/src/utils/result-parser.ts +39 -39
  149. package/README.md +0 -192
  150. package/docs/core.md +0 -234
  151. package/docs/expression.md +0 -234
  152. package/docs/query-builder.md +0 -93
  153. package/docs/queryable.md +0 -198
  154. package/docs/schema-builders.md +0 -463
  155. package/docs/types.md +0 -445
  156. package/docs/utilities.md +0 -27
  157. package/tests/db-context/create-db-context.spec.ts +0 -193
  158. package/tests/db-context/define-db-context.spec.ts +0 -17
  159. package/tests/ddl/basic.expected.ts +0 -341
  160. package/tests/ddl/basic.spec.ts +0 -557
  161. package/tests/ddl/column-builder.expected.ts +0 -310
  162. package/tests/ddl/column-builder.spec.ts +0 -525
  163. package/tests/ddl/index-builder.expected.ts +0 -38
  164. package/tests/ddl/index-builder.spec.ts +0 -148
  165. package/tests/ddl/procedure-builder.expected.ts +0 -52
  166. package/tests/ddl/procedure-builder.spec.ts +0 -128
  167. package/tests/ddl/relation-builder.expected.ts +0 -36
  168. package/tests/ddl/relation-builder.spec.ts +0 -171
  169. package/tests/ddl/table-builder.expected.ts +0 -113
  170. package/tests/ddl/table-builder.spec.ts +0 -399
  171. package/tests/ddl/view-builder.expected.ts +0 -38
  172. package/tests/ddl/view-builder.spec.ts +0 -116
  173. package/tests/dml/delete.expected.ts +0 -96
  174. package/tests/dml/delete.spec.ts +0 -127
  175. package/tests/dml/insert.expected.ts +0 -192
  176. package/tests/dml/insert.spec.ts +0 -210
  177. package/tests/dml/update.expected.ts +0 -176
  178. package/tests/dml/update.spec.ts +0 -222
  179. package/tests/dml/upsert.expected.ts +0 -215
  180. package/tests/dml/upsert.spec.ts +0 -190
  181. package/tests/errors/queryable-errors.spec.ts +0 -126
  182. package/tests/escape.spec.ts +0 -59
  183. package/tests/examples/pivot.expected.ts +0 -211
  184. package/tests/examples/pivot.spec.ts +0 -200
  185. package/tests/examples/sampling.expected.ts +0 -69
  186. package/tests/examples/sampling.spec.ts +0 -42
  187. package/tests/examples/unpivot.expected.ts +0 -120
  188. package/tests/examples/unpivot.spec.ts +0 -161
  189. package/tests/exec/search-parser.spec.ts +0 -267
  190. package/tests/executable/basic.expected.ts +0 -18
  191. package/tests/executable/basic.spec.ts +0 -54
  192. package/tests/expr/comparison.expected.ts +0 -282
  193. package/tests/expr/comparison.spec.ts +0 -334
  194. package/tests/expr/conditional.expected.ts +0 -134
  195. package/tests/expr/conditional.spec.ts +0 -249
  196. package/tests/expr/date.expected.ts +0 -332
  197. package/tests/expr/date.spec.ts +0 -459
  198. package/tests/expr/math.expected.ts +0 -62
  199. package/tests/expr/math.spec.ts +0 -59
  200. package/tests/expr/string.expected.ts +0 -218
  201. package/tests/expr/string.spec.ts +0 -300
  202. package/tests/expr/utility.expected.ts +0 -147
  203. package/tests/expr/utility.spec.ts +0 -155
  204. package/tests/select/basic.expected.ts +0 -322
  205. package/tests/select/basic.spec.ts +0 -433
  206. package/tests/select/filter.expected.ts +0 -357
  207. package/tests/select/filter.spec.ts +0 -954
  208. package/tests/select/group.expected.ts +0 -169
  209. package/tests/select/group.spec.ts +0 -159
  210. package/tests/select/join.expected.ts +0 -582
  211. package/tests/select/join.spec.ts +0 -692
  212. package/tests/select/order.expected.ts +0 -150
  213. package/tests/select/order.spec.ts +0 -140
  214. package/tests/select/recursive-cte.expected.ts +0 -244
  215. package/tests/select/recursive-cte.spec.ts +0 -514
  216. package/tests/select/result-meta.spec.ts +0 -270
  217. package/tests/select/subquery.expected.ts +0 -363
  218. package/tests/select/subquery.spec.ts +0 -441
  219. package/tests/select/view.expected.ts +0 -155
  220. package/tests/select/view.spec.ts +0 -235
  221. package/tests/select/window.expected.ts +0 -345
  222. package/tests/select/window.spec.ts +0 -433
  223. package/tests/setup/MockExecutor.ts +0 -18
  224. package/tests/setup/TestDbContext.ts +0 -59
  225. package/tests/setup/models/Company.ts +0 -13
  226. package/tests/setup/models/Employee.ts +0 -10
  227. package/tests/setup/models/MonthlySales.ts +0 -11
  228. package/tests/setup/models/Post.ts +0 -16
  229. package/tests/setup/models/Sales.ts +0 -10
  230. package/tests/setup/models/User.ts +0 -19
  231. package/tests/setup/procedure/GetAllUsers.ts +0 -9
  232. package/tests/setup/procedure/GetUserById.ts +0 -12
  233. package/tests/setup/test-utils.ts +0 -72
  234. package/tests/setup/views/ActiveUsers.ts +0 -8
  235. package/tests/setup/views/UserSummary.ts +0 -11
  236. package/tests/types/nullable-queryable-record.spec.ts +0 -97
  237. package/tests/utils/result-parser-perf.spec.ts +0 -143
  238. package/tests/utils/result-parser.spec.ts +0 -667
package/README.md DELETED
@@ -1,192 +0,0 @@
1
- # @simplysm/orm-common
2
-
3
- Simplysm Package - ORM Module (common)
4
-
5
- Dialect-independent ORM for MySQL, MSSQL, and PostgreSQL. Provides schema definition, type-safe query building, expression construction, and query rendering without any direct database dependency. Actual database execution is handled by `@simplysm/orm-node`.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install @simplysm/orm-common
11
- ```
12
-
13
- ## API Overview
14
-
15
- ### Core
16
- | API | Type | Description |
17
- |-----|------|-------------|
18
- | `defineDbContext` | function | Create a DbContext definition (blueprint) |
19
- | `createDbContext` | function | Create a DbContext instance from definition + executor |
20
- | `DbContextDef` | interface | DbContext definition (schema metadata, no runtime state) |
21
- | `DbContextBase` | interface | Internal interface used by Queryable/Executable |
22
- | `DbContextStatus` | type | Connection status: `"ready" \| "connect" \| "transact"` |
23
- | `DbContextInstance` | type | Full DbContext instance with accessors and methods |
24
- | `DbContextConnectionMethods` | interface | connect/connectWithoutTransaction/transaction methods |
25
- | `DbContextDdlMethods` | interface | DDL execution and QueryDef generation methods |
26
- | `DbTransactionError` | class | Standardized transaction error with error codes |
27
- | `DbErrorCode` | enum | Transaction error codes (NO_ACTIVE_TRANSACTION, DEADLOCK, etc.) |
28
-
29
- -> See [docs/core.md](./docs/core.md) for details.
30
-
31
- ### Queryable / Executable
32
- | API | Type | Description |
33
- |-----|------|-------------|
34
- | `Queryable` | class | Type-safe query builder (SELECT/INSERT/UPDATE/DELETE) |
35
- | `queryable` | function | Factory to create Queryable accessor for DbContext |
36
- | `Executable` | class | Stored procedure execution wrapper |
37
- | `executable` | function | Factory to create Executable accessor for DbContext |
38
- | `parseSearchQuery` | function | Parse search query string to SQL LIKE patterns |
39
- | `ParsedSearchQuery` | interface | Search query parsing result (or/must/not arrays) |
40
-
41
- -> See [docs/queryable.md](./docs/queryable.md) for details.
42
-
43
- ### Expression
44
- | API | Type | Description |
45
- |-----|------|-------------|
46
- | `expr` | object | Dialect-independent SQL expression builder |
47
- | `ExprUnit` | class | Type-safe expression wrapper |
48
- | `WhereExprUnit` | class | WHERE clause expression wrapper |
49
- | `ExprInput` | type | Input type accepting ExprUnit or literal |
50
- | `SwitchExprBuilder` | interface | CASE/WHEN expression builder |
51
-
52
- -> See [docs/expression.md](./docs/expression.md) for details.
53
-
54
- ### Schema Builders
55
- | API | Type | Description |
56
- |-----|------|-------------|
57
- | `Table` | function | Table builder factory |
58
- | `TableBuilder` | class | Table definition builder (columns, PK, indexes, relations) |
59
- | `View` | function | View builder factory |
60
- | `ViewBuilder` | class | View definition builder (query, relations) |
61
- | `Procedure` | function | Procedure builder factory |
62
- | `ProcedureBuilder` | class | Stored procedure definition builder |
63
- | `ColumnBuilder` | class | Column definition builder (type, nullable, default) |
64
- | `createColumnFactory` | function | Column type factory (int, varchar, datetime, etc.) |
65
- | `IndexBuilder` | class | Index definition builder |
66
- | `createIndexFactory` | function | Index factory |
67
- | `ForeignKeyBuilder` | class | FK relation builder (N:1, creates DB constraint) |
68
- | `ForeignKeyTargetBuilder` | class | FK reverse-reference builder (1:N) |
69
- | `RelationKeyBuilder` | class | Logical relation builder (N:1, no DB FK) |
70
- | `RelationKeyTargetBuilder` | class | Logical reverse-reference builder (1:N, no DB FK) |
71
- | `createRelationFactory` | function | Relation builder factory |
72
- | `_Migration` | const | Built-in system migration table |
73
- | `ColumnBuilderRecord` | type | Column builder record type |
74
- | `RelationBuilderRecord` | type | Relation builder record type |
75
- | `InferColumns` | type | Infer value types from column builders |
76
- | `InferColumnExprs` | type | Infer expression input types |
77
- | `InferInsertColumns` | type | INSERT type inference |
78
- | `InferUpdateColumns` | type | UPDATE type inference |
79
- | `RequiredInsertKeys` | type | Required column keys for INSERT |
80
- | `OptionalInsertKeys` | type | Optional column keys for INSERT |
81
- | `DataToColumnBuilderRecord` | type | Data record to column builder record |
82
- | `InferDeepRelations` | type | Deep relation type inference |
83
- | `ExtractRelationTarget` | type | Extract N:1 relation target type |
84
- | `ExtractRelationTargetResult` | type | Extract 1:N relation target type |
85
-
86
- -> See [docs/schema-builders.md](./docs/schema-builders.md) for details.
87
-
88
- ### Query Builder
89
- | API | Type | Description |
90
- |-----|------|-------------|
91
- | `createQueryBuilder` | function | Create dialect-specific QueryBuilder |
92
- | `QueryBuilderBase` | class | Abstract QueryDef-to-SQL renderer |
93
- | `ExprRendererBase` | class | Abstract expression-to-SQL renderer |
94
- | `MysqlQueryBuilder` | class | MySQL query builder |
95
- | `MysqlExprRenderer` | class | MySQL expression renderer |
96
- | `MssqlQueryBuilder` | class | MSSQL query builder |
97
- | `MssqlExprRenderer` | class | MSSQL expression renderer |
98
- | `PostgresqlQueryBuilder` | class | PostgreSQL query builder |
99
- | `PostgresqlExprRenderer` | class | PostgreSQL expression renderer |
100
-
101
- -> See [docs/query-builder.md](./docs/query-builder.md) for details.
102
-
103
- ### Types
104
- | API | Type | Description |
105
- |-----|------|-------------|
106
- | `Dialect` | type | Database dialect (`"mysql" \| "mssql" \| "postgresql"`) |
107
- | `dialects` | const | List of all supported dialects |
108
- | `IsolationLevel` | type | Transaction isolation level |
109
- | `DataRecord` | type | Query result data record (supports nesting) |
110
- | `DbContextExecutor` | interface | DB connection and query executor interface |
111
- | `QueryBuildResult` | interface | Built SQL string + metadata |
112
- | `ResultMeta` | interface | Result transformation metadata |
113
- | `Migration` | interface | Database migration definition |
114
- | `DataType` | type | SQL data type definition (14 variants) |
115
- | `ColumnPrimitiveMap` | type | TypeScript type name to actual type mapping |
116
- | `ColumnPrimitiveStr` | type | Column primitive type name |
117
- | `ColumnPrimitive` | type | All column-storable primitive types |
118
- | `ColumnMeta` | interface | Column metadata |
119
- | `DateUnit` | type | Date operation unit |
120
- | `QueryDefObjectName` | interface | DB object name (database.schema.name) |
121
- | `QueryDef` | type | All query definition union type |
122
- | `SelectQueryDef` | interface | SELECT query definition |
123
- | `InsertQueryDef` | interface | INSERT query definition |
124
- | `UpdateQueryDef` | interface | UPDATE query definition |
125
- | `DeleteQueryDef` | interface | DELETE query definition |
126
- | `UpsertQueryDef` | interface | UPSERT query definition |
127
- | `DDL_TYPES` | const | DDL type constants |
128
- | `Expr` | type | All expression union type |
129
- | `WhereExpr` | type | WHERE clause expression union type |
130
- | `WinFn` | type | Window function union type |
131
- | `WinSpec` | interface | Window specification (OVER clause) |
132
- | `parseQueryResult` | function | Transform raw DB results to typed objects |
133
- | `inferColumnPrimitiveStr` | function | Infer ColumnPrimitiveStr from runtime value |
134
- | `dataTypeStrToColumnPrimitiveStr` | const | SQL type to TypeScript type mapping |
135
-
136
- -> See [docs/types.md](./docs/types.md) and [docs/utilities.md](./docs/utilities.md) for details.
137
-
138
- ## Usage Examples
139
-
140
- ### Define Schema and Query
141
-
142
- ```typescript
143
- import { Table, defineDbContext, createDbContext, expr } from "@simplysm/orm-common";
144
-
145
- // Define tables
146
- const User = Table("User")
147
- .database("mydb")
148
- .columns((c) => ({
149
- id: c.bigint().autoIncrement(),
150
- name: c.varchar(100),
151
- email: c.varchar(200).nullable(),
152
- status: c.varchar(20).default("active"),
153
- }))
154
- .primaryKey("id")
155
- .indexes((i) => [i.index("email").unique()]);
156
-
157
- const Post = Table("Post")
158
- .database("mydb")
159
- .columns((c) => ({
160
- id: c.bigint().autoIncrement(),
161
- authorId: c.bigint(),
162
- title: c.varchar(200),
163
- }))
164
- .primaryKey("id")
165
- .relations((r) => ({
166
- author: r.foreignKey(["authorId"], () => User),
167
- }));
168
-
169
- // Define DbContext
170
- const MyDb = defineDbContext({
171
- tables: { user: User, post: Post },
172
- });
173
-
174
- // Create instance and query
175
- const db = createDbContext(MyDb, executor, { database: "mydb" });
176
-
177
- await db.connect(async () => {
178
- // SELECT with WHERE
179
- const activeUsers = await db.user()
180
- .where((u) => [expr.eq(u.status, "active")])
181
- .orderBy((u) => u.name)
182
- .execute();
183
-
184
- // INSERT
185
- await db.user().insert([{ name: "John", email: "john@test.com" }]);
186
-
187
- // JOIN with include
188
- const posts = await db.post()
189
- .include((p) => p.author)
190
- .execute();
191
- });
192
- ```
package/docs/core.md DELETED
@@ -1,234 +0,0 @@
1
- # Core
2
-
3
- ## `defineDbContext`
4
-
5
- Factory function that creates a DbContext definition (blueprint). Takes table, view, procedure builders and migration definitions. Automatically includes the `_migration` system table.
6
-
7
- ```typescript
8
- function defineDbContext<
9
- TTables extends Record<string, TableBuilder<any, any>> = {},
10
- TViews extends Record<string, ViewBuilder<any, any, any>> = {},
11
- TProcedures extends Record<string, ProcedureBuilder<any, any>> = {},
12
- >(config: {
13
- tables?: TTables;
14
- views?: TViews;
15
- procedures?: TProcedures;
16
- migrations?: Migration[];
17
- }): DbContextDef<TTables & { _migration: typeof _Migration }, TViews, TProcedures>;
18
- ```
19
-
20
- | Parameter | Type | Description |
21
- |-----------|------|-------------|
22
- | `config.tables` | `TTables` | Table builder definitions |
23
- | `config.views` | `TViews` | View builder definitions |
24
- | `config.procedures` | `TProcedures` | Procedure builder definitions |
25
- | `config.migrations` | `Migration[]` | Migration definitions |
26
-
27
- ## `createDbContext`
28
-
29
- DbContext instance factory. Takes a `DbContextDef` and `DbContextExecutor` and creates a complete DbContext instance with queryable accessors, DDL methods, and connection/transaction management.
30
-
31
- ```typescript
32
- function createDbContext<TDef extends DbContextDef<any, any, any>>(
33
- def: TDef,
34
- executor: DbContextExecutor,
35
- opt: { database: string; schema?: string },
36
- ): DbContextInstance<TDef>;
37
- ```
38
-
39
- | Parameter | Type | Description |
40
- |-----------|------|-------------|
41
- | `def` | `TDef` | Definition object created by `defineDbContext()` |
42
- | `executor` | `DbContextExecutor` | Query executor implementation |
43
- | `opt.database` | `string` | Database name |
44
- | `opt.schema` | `string` | Schema name (MSSQL: dbo, PostgreSQL: public) |
45
-
46
- ## `DbContextDef`
47
-
48
- DbContext definition (blueprint). Created by `defineDbContext()`. Contains schema metadata but no runtime state.
49
-
50
- ```typescript
51
- interface DbContextDef<
52
- TTables extends Record<string, TableBuilder<any, any>>,
53
- TViews extends Record<string, ViewBuilder<any, any, any>>,
54
- TProcedures extends Record<string, ProcedureBuilder<any, any>> = {},
55
- > {
56
- readonly meta: {
57
- readonly tables: TTables;
58
- readonly views: TViews;
59
- readonly procedures: TProcedures;
60
- readonly migrations: Migration[];
61
- };
62
- }
63
- ```
64
-
65
- | Field | Type | Description |
66
- |-------|------|-------------|
67
- | `meta.tables` | `TTables` | Table builder definitions |
68
- | `meta.views` | `TViews` | View builder definitions |
69
- | `meta.procedures` | `TProcedures` | Procedure builder definitions |
70
- | `meta.migrations` | `Migration[]` | Migration definitions |
71
-
72
- ## `DbContextBase`
73
-
74
- Internal interface used by Queryable, Executable, and ViewBuilder.
75
-
76
- ```typescript
77
- interface DbContextBase {
78
- status: DbContextStatus;
79
- readonly database: string | undefined;
80
- readonly schema: string | undefined;
81
- getNextAlias(): string;
82
- resetAliasCounter(): void;
83
- executeDefs<T = DataRecord>(
84
- defs: QueryDef[],
85
- resultMetas?: (ResultMeta | undefined)[],
86
- ): Promise<T[][]>;
87
- getQueryDefObjectName(
88
- tableOrView: TableBuilder<any, any> | ViewBuilder<any, any, any>,
89
- ): QueryDefObjectName;
90
- switchFk(table: QueryDefObjectName, enabled: boolean): Promise<void>;
91
- }
92
- ```
93
-
94
- | Field | Type | Description |
95
- |-------|------|-------------|
96
- | `status` | `DbContextStatus` | Current connection status |
97
- | `database` | `string \| undefined` | Database name |
98
- | `schema` | `string \| undefined` | Schema name |
99
- | `getNextAlias()` | `() => string` | Generate next table alias |
100
- | `resetAliasCounter()` | `() => void` | Reset alias counter |
101
- | `executeDefs()` | `(defs, resultMetas?) => Promise<T[][]>` | Execute query definitions |
102
- | `getQueryDefObjectName()` | `(tableOrView) => QueryDefObjectName` | Get qualified object name |
103
- | `switchFk()` | `(table, enabled) => Promise<void>` | Enable/disable FK constraints |
104
-
105
- ## `DbContextStatus`
106
-
107
- Connection status type.
108
-
109
- ```typescript
110
- type DbContextStatus = "ready" | "connect" | "transact";
111
- ```
112
-
113
- ## `DbContextInstance`
114
-
115
- Full DbContext instance type created by `createDbContext`. Extends `DbContextBase` with queryable accessors for tables/views, executable accessors for procedures, DDL methods, and connection/transaction management.
116
-
117
- ```typescript
118
- type DbContextInstance<TDef extends DbContextDef<any, any, any>> = DbContextBase &
119
- DbContextConnectionMethods &
120
- DbContextDdlMethods & {
121
- [K in keyof TDef["meta"]["tables"]]: () => Queryable<...>;
122
- } & {
123
- [K in keyof TDef["meta"]["views"]]: () => Queryable<...>;
124
- } & {
125
- [K in keyof TDef["meta"]["procedures"]]: () => Executable<...>;
126
- } & {
127
- _migration: () => Queryable<{ code: string }, any>;
128
- initialize(options?: { dbs?: string[]; force?: boolean }): Promise<void>;
129
- };
130
- ```
131
-
132
- ## `DbContextConnectionMethods`
133
-
134
- Connection and transaction management methods.
135
-
136
- ```typescript
137
- interface DbContextConnectionMethods {
138
- connect<TResult>(fn: () => Promise<TResult>, isolationLevel?: IsolationLevel): Promise<TResult>;
139
- connectWithoutTransaction<TResult>(callback: () => Promise<TResult>): Promise<TResult>;
140
- transaction<TResult>(fn: () => Promise<TResult>, isolationLevel?: IsolationLevel): Promise<TResult>;
141
- }
142
- ```
143
-
144
- | Method | Description |
145
- |--------|-------------|
146
- | `connect()` | Execute callback within a transaction (auto commit/rollback) |
147
- | `connectWithoutTransaction()` | Connect without transaction, execute callback, auto-close |
148
- | `transaction()` | Start transaction in already-connected state (auto commit/rollback) |
149
-
150
- ## `DbContextDdlMethods`
151
-
152
- DDL execution methods and QueryDef generators for tables, views, procedures, columns, indexes, foreign keys, and schema operations.
153
-
154
- ```typescript
155
- interface DbContextDdlMethods {
156
- createTable(table: TableBuilder<any, any>): Promise<void>;
157
- dropTable(table: QueryDefObjectName): Promise<void>;
158
- renameTable(table: QueryDefObjectName, newName: string): Promise<void>;
159
- createView(view: ViewBuilder<any, any, any>): Promise<void>;
160
- dropView(view: QueryDefObjectName): Promise<void>;
161
- createProc(procedure: ProcedureBuilder<any, any>): Promise<void>;
162
- dropProc(procedure: QueryDefObjectName): Promise<void>;
163
- addColumn(table: QueryDefObjectName, columnName: string, column: ColumnBuilder<any, any>): Promise<void>;
164
- dropColumn(table: QueryDefObjectName, column: string): Promise<void>;
165
- modifyColumn(table: QueryDefObjectName, columnName: string, column: ColumnBuilder<any, any>): Promise<void>;
166
- renameColumn(table: QueryDefObjectName, column: string, newName: string): Promise<void>;
167
- addPrimaryKey(table: QueryDefObjectName, columns: string[]): Promise<void>;
168
- dropPrimaryKey(table: QueryDefObjectName): Promise<void>;
169
- addForeignKey(table: QueryDefObjectName, relationName: string, relationDef: ForeignKeyBuilder<any, any>): Promise<void>;
170
- addIndex(table: QueryDefObjectName, indexBuilder: IndexBuilder<string[]>): Promise<void>;
171
- dropForeignKey(table: QueryDefObjectName, relationName: string): Promise<void>;
172
- dropIndex(table: QueryDefObjectName, columns: string[]): Promise<void>;
173
- clearSchema(params: { database: string; schema?: string }): Promise<void>;
174
- schemaExists(database: string, schema?: string): Promise<boolean>;
175
- truncate(table: QueryDefObjectName): Promise<void>;
176
- switchFk(table: QueryDefObjectName, enabled: boolean): Promise<void>;
177
- // QueryDef generators (get*QueryDef methods for each DDL operation)
178
- getCreateTableQueryDef(table: TableBuilder<any, any>): QueryDef;
179
- getCreateViewQueryDef(view: ViewBuilder<any, any, any>): QueryDef;
180
- getCreateProcQueryDef(procedure: ProcedureBuilder<any, any>): QueryDef;
181
- getCreateObjectQueryDef(builder: TableBuilder | ViewBuilder | ProcedureBuilder): QueryDef;
182
- getDropTableQueryDef(table: QueryDefObjectName): QueryDef;
183
- getRenameTableQueryDef(table: QueryDefObjectName, newName: string): QueryDef;
184
- getDropViewQueryDef(view: QueryDefObjectName): QueryDef;
185
- getDropProcQueryDef(procedure: QueryDefObjectName): QueryDef;
186
- getAddColumnQueryDef(table: QueryDefObjectName, columnName: string, column: ColumnBuilder<any, any>): QueryDef;
187
- getDropColumnQueryDef(table: QueryDefObjectName, column: string): QueryDef;
188
- getModifyColumnQueryDef(table: QueryDefObjectName, columnName: string, column: ColumnBuilder<any, any>): QueryDef;
189
- getRenameColumnQueryDef(table: QueryDefObjectName, column: string, newName: string): QueryDef;
190
- getAddPrimaryKeyQueryDef(table: QueryDefObjectName, columns: string[]): QueryDef;
191
- getDropPrimaryKeyQueryDef(table: QueryDefObjectName): QueryDef;
192
- getAddForeignKeyQueryDef(table: QueryDefObjectName, relationName: string, relationDef: ForeignKeyBuilder<any, any>): QueryDef;
193
- getAddIndexQueryDef(table: QueryDefObjectName, indexBuilder: IndexBuilder<string[]>): QueryDef;
194
- getDropForeignKeyQueryDef(table: QueryDefObjectName, relationName: string): QueryDef;
195
- getDropIndexQueryDef(table: QueryDefObjectName, columns: string[]): QueryDef;
196
- getClearSchemaQueryDef(params: { database: string; schema?: string }): QueryDef;
197
- getSchemaExistsQueryDef(database: string, schema?: string): QueryDef;
198
- getTruncateQueryDef(table: QueryDefObjectName): QueryDef;
199
- getSwitchFkQueryDef(table: QueryDefObjectName, enabled: boolean): QueryDef;
200
- }
201
- ```
202
-
203
- ## `DbTransactionError`
204
-
205
- Database transaction error with standardized error codes for DBMS-independent error handling.
206
-
207
- ```typescript
208
- class DbTransactionError extends Error {
209
- override readonly name = "DbTransactionError";
210
- constructor(
211
- public readonly code: DbErrorCode,
212
- message: string,
213
- public readonly originalError?: unknown,
214
- );
215
- }
216
- ```
217
-
218
- | Property | Type | Description |
219
- |----------|------|-------------|
220
- | `code` | `DbErrorCode` | Standardized error code |
221
- | `originalError` | `unknown` | Original DBMS error (for debugging) |
222
-
223
- ## `DbErrorCode`
224
-
225
- Transaction-related error codes.
226
-
227
- ```typescript
228
- enum DbErrorCode {
229
- NO_ACTIVE_TRANSACTION = "NO_ACTIVE_TRANSACTION",
230
- TRANSACTION_ALREADY_STARTED = "TRANSACTION_ALREADY_STARTED",
231
- DEADLOCK = "DEADLOCK",
232
- LOCK_TIMEOUT = "LOCK_TIMEOUT",
233
- }
234
- ```
@@ -1,234 +0,0 @@
1
- # Expression
2
-
3
- ## `ExprUnit`
4
-
5
- Type-safe expression wrapper. Tracks expression return type using TypeScript generics.
6
-
7
- ```typescript
8
- class ExprUnit<TPrimitive extends ColumnPrimitive> {
9
- readonly $infer!: TPrimitive;
10
- get n(): ExprUnit<NonNullable<TPrimitive>>;
11
- constructor(readonly dataType: ColumnPrimitiveStr, readonly expr: Expr);
12
- }
13
- ```
14
-
15
- | Property | Type | Description |
16
- |----------|------|-------------|
17
- | `$infer` | `TPrimitive` | Type inference marker (not used at runtime) |
18
- | `n` | `ExprUnit<NonNullable<TPrimitive>>` | Non-nullable version of this expression |
19
- | `dataType` | `ColumnPrimitiveStr` | Column data type name |
20
- | `expr` | `Expr` | Internal expression AST |
21
-
22
- ## `WhereExprUnit`
23
-
24
- Expression wrapper for WHERE clause conditions.
25
-
26
- ```typescript
27
- class WhereExprUnit {
28
- constructor(readonly expr: WhereExpr);
29
- }
30
- ```
31
-
32
- ## `ExprInput`
33
-
34
- Input type that accepts `ExprUnit` or literal values.
35
-
36
- ```typescript
37
- type ExprInput<TPrimitive extends ColumnPrimitive> = ExprUnit<TPrimitive> | TPrimitive;
38
- ```
39
-
40
- ## `SwitchExprBuilder`
41
-
42
- CASE/WHEN expression builder interface.
43
-
44
- ```typescript
45
- interface SwitchExprBuilder<TPrimitive extends ColumnPrimitive> {
46
- case(condition: WhereExprUnit, then: ExprInput<TPrimitive>): SwitchExprBuilder<TPrimitive>;
47
- default(value: ExprInput<TPrimitive>): ExprUnit<TPrimitive>;
48
- }
49
- ```
50
-
51
- ## `expr`
52
-
53
- Dialect-independent SQL expression builder. Generates JSON AST (`Expr`) instead of SQL strings, which `QueryBuilder` converts to each DBMS (MySQL, MSSQL, PostgreSQL).
54
-
55
- ```typescript
56
- const expr: {
57
- // Value creation
58
- val<TStr extends ColumnPrimitiveStr>(dataType: TStr, value): ExprUnit<...>;
59
- col<TStr extends ColumnPrimitiveStr>(dataType: ColumnPrimitiveStr, ...path: string[]): ExprUnit<...>;
60
- raw<T extends ColumnPrimitiveStr>(dataType: T): (strings: TemplateStringsArray, ...values: ExprInput<ColumnPrimitive>[]) => ExprUnit<...>;
61
-
62
- // Comparison (WHERE)
63
- eq<T extends ColumnPrimitive>(source: ExprUnit<T>, target: ExprInput<T>): WhereExprUnit;
64
- gt<T extends ColumnPrimitive>(source: ExprUnit<T>, target: ExprInput<T>): WhereExprUnit;
65
- lt<T extends ColumnPrimitive>(source: ExprUnit<T>, target: ExprInput<T>): WhereExprUnit;
66
- gte<T extends ColumnPrimitive>(source: ExprUnit<T>, target: ExprInput<T>): WhereExprUnit;
67
- lte<T extends ColumnPrimitive>(source: ExprUnit<T>, target: ExprInput<T>): WhereExprUnit;
68
- between<T extends ColumnPrimitive>(source: ExprUnit<T>, from?: ExprInput<T>, to?: ExprInput<T>): WhereExprUnit;
69
- isNull(arg: ExprUnit<ColumnPrimitive>): WhereExprUnit;
70
- like(source: ExprUnit<string | undefined>, pattern: ExprInput<string>): WhereExprUnit;
71
- regexp(source: ExprUnit<string | undefined>, pattern: ExprInput<string>): WhereExprUnit;
72
- in<T extends ColumnPrimitive>(source: ExprUnit<T>, values: ExprInput<T>[]): WhereExprUnit;
73
- inQuery<T extends ColumnPrimitive>(source: ExprUnit<T>, query: Queryable<any, any>): WhereExprUnit;
74
- exists(query: Queryable<any, any>): WhereExprUnit;
75
-
76
- // Logical
77
- not(condition: WhereExprUnit): WhereExprUnit;
78
- and(...conditions: WhereExprUnit[]): WhereExprUnit;
79
- or(...conditions: WhereExprUnit[]): WhereExprUnit;
80
-
81
- // String
82
- concat(...args: ExprInput<string | undefined>[]): ExprUnit<string>;
83
- left(source: ExprInput<string | undefined>, length: ExprInput<number>): ExprUnit<string>;
84
- right(source: ExprInput<string | undefined>, length: ExprInput<number>): ExprUnit<string>;
85
- trim(arg: ExprInput<string | undefined>): ExprUnit<string>;
86
- padStart(source: ExprInput<string | undefined>, length: ExprInput<number>, fillString: ExprInput<string>): ExprUnit<string>;
87
- replace(source: ExprInput<string | undefined>, from: ExprInput<string>, to: ExprInput<string>): ExprUnit<string>;
88
- upper(arg: ExprInput<string | undefined>): ExprUnit<string>;
89
- lower(arg: ExprInput<string | undefined>): ExprUnit<string>;
90
- length(arg: ExprInput<string | undefined>): ExprUnit<number>;
91
- byteLength(arg: ExprInput<string | undefined>): ExprUnit<number>;
92
- substring(source: ExprInput<string | undefined>, start: ExprInput<number>, length?: ExprInput<number>): ExprUnit<string>;
93
- indexOf(source: ExprInput<string | undefined>, search: ExprInput<string>): ExprUnit<number>;
94
-
95
- // Numeric
96
- abs(arg: ExprInput<number | undefined>): ExprUnit<number>;
97
- round(arg: ExprInput<number | undefined>, digits: number): ExprUnit<number>;
98
- ceil(arg: ExprInput<number | undefined>): ExprUnit<number>;
99
- floor(arg: ExprInput<number | undefined>): ExprUnit<number>;
100
-
101
- // Date
102
- year(arg: ExprInput<DateTime | DateOnly | undefined>): ExprUnit<number>;
103
- month(arg: ExprInput<DateTime | DateOnly | undefined>): ExprUnit<number>;
104
- day(arg: ExprInput<DateTime | DateOnly | undefined>): ExprUnit<number>;
105
- hour(arg: ExprInput<DateTime | undefined>): ExprUnit<number>;
106
- minute(arg: ExprInput<DateTime | undefined>): ExprUnit<number>;
107
- second(arg: ExprInput<DateTime | undefined>): ExprUnit<number>;
108
- isoWeek(arg: ExprInput<DateTime | DateOnly | undefined>): ExprUnit<number>;
109
- isoWeekStartDate(arg: ExprInput<DateTime | DateOnly | undefined>): ExprUnit<DateOnly>;
110
- isoYearMonth(arg: ExprInput<DateTime | DateOnly | undefined>): ExprUnit<string>;
111
- dateDiff(unit: DateUnit, from: ExprInput<ColumnPrimitive>, to: ExprInput<ColumnPrimitive>): ExprUnit<number>;
112
- dateAdd(unit: DateUnit, source: ExprInput<ColumnPrimitive>, value: ExprInput<number>): ExprUnit<DateTime>;
113
- formatDate(source: ExprInput<ColumnPrimitive>, format: string): ExprUnit<string>;
114
-
115
- // Conditional
116
- coalesce<T extends ColumnPrimitive>(...args: ExprInput<T | undefined>[]): ExprUnit<T>;
117
- nullIf<T extends ColumnPrimitive>(source: ExprInput<T>, value: ExprInput<T>): ExprUnit<T | undefined>;
118
- is(condition: WhereExprUnit): ExprUnit<number>;
119
- switch<T extends ColumnPrimitive>(dataType: ColumnPrimitiveStr): SwitchExprBuilder<T>;
120
- if<T extends ColumnPrimitive>(condition: WhereExprUnit, then: ExprInput<T>, elseVal?: ExprInput<T>): ExprUnit<T>;
121
-
122
- // Aggregate
123
- count(arg?: ExprUnit<ColumnPrimitive>, distinct?: boolean): ExprUnit<number>;
124
- sum(arg: ExprUnit<number | undefined>): ExprUnit<number>;
125
- avg(arg: ExprUnit<number | undefined>): ExprUnit<number>;
126
- max<T extends ColumnPrimitive>(arg: ExprUnit<T>): ExprUnit<T>;
127
- min<T extends ColumnPrimitive>(arg: ExprUnit<T>): ExprUnit<T>;
128
-
129
- // Other
130
- greatest<T extends ColumnPrimitive>(...args: ExprInput<T>[]): ExprUnit<T>;
131
- least<T extends ColumnPrimitive>(...args: ExprInput<T>[]): ExprUnit<T>;
132
- rowNum(): ExprUnit<number>;
133
- random(): ExprUnit<number>;
134
- cast<TDataType extends DataType>(source: ExprInput<ColumnPrimitive>, targetType: TDataType): ExprUnit<InferColumnPrimitiveFromDataType<TDataType>>;
135
-
136
- // Window
137
- window(fn: WinFn, spec?: WinSpecInput): ExprUnit<number>;
138
-
139
- // Subquery
140
- subquery<T extends ColumnPrimitive>(query: Queryable<any, any>, selectFn: (q: ...) => ExprUnit<T>): ExprUnit<T>;
141
- };
142
- ```
143
-
144
- ### Value Creation
145
-
146
- | Method | Description |
147
- |--------|-------------|
148
- | `val()` | Wrap literal value as ExprUnit |
149
- | `col()` | Generate column reference |
150
- | `raw()` | Raw SQL expression (escape hatch, tagged template literal) |
151
-
152
- ### Comparison (WHERE)
153
-
154
- | Method | SQL | Description |
155
- |--------|-----|-------------|
156
- | `eq()` | `=` | Equality comparison (NULL-safe) |
157
- | `gt()` | `>` | Greater than |
158
- | `lt()` | `<` | Less than |
159
- | `gte()` | `>=` | Greater than or equal |
160
- | `lte()` | `<=` | Less than or equal |
161
- | `between()` | `BETWEEN` | Range comparison |
162
- | `isNull()` | `IS NULL` | NULL check |
163
- | `like()` | `LIKE` | Pattern matching |
164
- | `regexp()` | `REGEXP` | Regular expression matching |
165
- | `in()` | `IN` | Value list inclusion |
166
- | `inQuery()` | `IN (SELECT)` | Subquery inclusion |
167
- | `exists()` | `EXISTS` | Subquery existence |
168
-
169
- ### Logical
170
-
171
- | Method | SQL | Description |
172
- |--------|-----|-------------|
173
- | `not()` | `NOT` | Logical negation |
174
- | `and()` | `AND` | Logical conjunction |
175
- | `or()` | `OR` | Logical disjunction |
176
-
177
- ### String Functions
178
-
179
- | Method | SQL | Description |
180
- |--------|-----|-------------|
181
- | `concat()` | `CONCAT` | String concatenation |
182
- | `left()` | `LEFT` | Extract left N characters |
183
- | `right()` | `RIGHT` | Extract right N characters |
184
- | `trim()` | `TRIM` | Remove leading/trailing whitespace |
185
- | `padStart()` | `LPAD` | Left padding |
186
- | `replace()` | `REPLACE` | String replacement |
187
- | `upper()` | `UPPER` | Uppercase |
188
- | `lower()` | `LOWER` | Lowercase |
189
- | `length()` | `CHAR_LENGTH` | Character length |
190
- | `byteLength()` | `LENGTH/DATALENGTH` | Byte length |
191
- | `substring()` | `SUBSTRING` | Substring extraction |
192
- | `indexOf()` | `LOCATE/CHARINDEX` | Find string position |
193
-
194
- ### Numeric Functions
195
-
196
- | Method | SQL | Description |
197
- |--------|-----|-------------|
198
- | `abs()` | `ABS` | Absolute value |
199
- | `round()` | `ROUND` | Rounding |
200
- | `ceil()` | `CEIL` | Ceiling |
201
- | `floor()` | `FLOOR` | Floor |
202
-
203
- ### Date Functions
204
-
205
- | Method | SQL | Description |
206
- |--------|-----|-------------|
207
- | `year()` | `YEAR` | Extract year |
208
- | `month()` | `MONTH` | Extract month |
209
- | `day()` | `DAY` | Extract day |
210
- | `hour()` | `HOUR` | Extract hour |
211
- | `minute()` | `MINUTE` | Extract minute |
212
- | `second()` | `SECOND` | Extract second |
213
- | `isoWeek()` | `WEEK` | ISO week number |
214
- | `isoWeekStartDate()` | - | ISO week start date |
215
- | `isoYearMonth()` | - | ISO year-month (YYYYMM) |
216
- | `dateDiff()` | `DATEDIFF` | Date difference |
217
- | `dateAdd()` | `DATEADD` | Date arithmetic |
218
- | `formatDate()` | `FORMAT/DATE_FORMAT` | Date formatting |
219
-
220
- ### Aggregate Functions
221
-
222
- | Method | SQL | Description |
223
- |--------|-----|-------------|
224
- | `count()` | `COUNT` | Record count |
225
- | `sum()` | `SUM` | Sum |
226
- | `avg()` | `AVG` | Average |
227
- | `max()` | `MAX` | Maximum |
228
- | `min()` | `MIN` | Minimum |
229
-
230
- ### Window Functions
231
-
232
- | Method | SQL | Description |
233
- |--------|-----|-------------|
234
- | `window()` | `OVER(...)` | Window function (rowNumber, rank, denseRank, ntile, lag, lead, firstValue, lastValue, sum, avg, count, min, max) |