@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.
- package/dist/create-db-context.d.ts +10 -10
- package/dist/create-db-context.js +312 -276
- package/dist/create-db-context.js.map +1 -6
- package/dist/ddl/column-ddl.d.ts +4 -4
- package/dist/ddl/column-ddl.js +41 -35
- package/dist/ddl/column-ddl.js.map +1 -6
- package/dist/ddl/initialize.d.ts +17 -17
- package/dist/ddl/initialize.js +200 -142
- package/dist/ddl/initialize.js.map +1 -6
- package/dist/ddl/relation-ddl.d.ts +6 -6
- package/dist/ddl/relation-ddl.js +55 -48
- package/dist/ddl/relation-ddl.js.map +1 -6
- package/dist/ddl/schema-ddl.d.ts +4 -4
- package/dist/ddl/schema-ddl.js +21 -15
- package/dist/ddl/schema-ddl.js.map +1 -6
- package/dist/ddl/table-ddl.d.ts +20 -20
- package/dist/ddl/table-ddl.js +139 -93
- package/dist/ddl/table-ddl.js.map +1 -6
- package/dist/define-db-context.js +10 -13
- package/dist/define-db-context.js.map +1 -6
- package/dist/errors/db-transaction-error.d.ts +15 -15
- package/dist/errors/db-transaction-error.d.ts.map +1 -1
- package/dist/errors/db-transaction-error.js +53 -19
- package/dist/errors/db-transaction-error.js.map +1 -6
- package/dist/exec/executable.d.ts +23 -23
- package/dist/exec/executable.js +94 -40
- package/dist/exec/executable.js.map +1 -6
- package/dist/exec/queryable.d.ts +97 -97
- package/dist/exec/queryable.js +1310 -1204
- package/dist/exec/queryable.js.map +1 -6
- package/dist/exec/search-parser.d.ts +31 -31
- package/dist/exec/search-parser.d.ts.map +1 -1
- package/dist/exec/search-parser.js +158 -59
- package/dist/exec/search-parser.js.map +1 -6
- package/dist/expr/expr-unit.d.ts +4 -4
- package/dist/expr/expr-unit.js +24 -18
- package/dist/expr/expr-unit.js.map +1 -6
- package/dist/expr/expr.d.ts +6 -6
- package/dist/expr/expr.js +1872 -1844
- package/dist/expr/expr.js.map +1 -6
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -6
- package/dist/models/system-migration.js +7 -7
- package/dist/models/system-migration.js.map +1 -6
- package/dist/query-builder/base/expr-renderer-base.d.ts +10 -10
- package/dist/query-builder/base/expr-renderer-base.js +27 -21
- package/dist/query-builder/base/expr-renderer-base.js.map +1 -6
- package/dist/query-builder/base/query-builder-base.d.ts +21 -21
- package/dist/query-builder/base/query-builder-base.d.ts.map +1 -1
- package/dist/query-builder/base/query-builder-base.js +90 -80
- package/dist/query-builder/base/query-builder-base.js.map +1 -6
- package/dist/query-builder/mssql/mssql-expr-renderer.d.ts +4 -4
- package/dist/query-builder/mssql/mssql-expr-renderer.d.ts.map +1 -1
- package/dist/query-builder/mssql/mssql-expr-renderer.js +447 -420
- package/dist/query-builder/mssql/mssql-expr-renderer.js.map +1 -6
- package/dist/query-builder/mssql/mssql-query-builder.js +483 -443
- package/dist/query-builder/mssql/mssql-query-builder.js.map +1 -6
- package/dist/query-builder/mysql/mysql-expr-renderer.d.ts +4 -4
- package/dist/query-builder/mysql/mysql-expr-renderer.d.ts.map +1 -1
- package/dist/query-builder/mysql/mysql-expr-renderer.js +451 -419
- package/dist/query-builder/mysql/mysql-expr-renderer.js.map +1 -6
- package/dist/query-builder/mysql/mysql-query-builder.js +570 -479
- package/dist/query-builder/mysql/mysql-query-builder.js.map +1 -6
- package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts +4 -4
- package/dist/query-builder/postgresql/postgresql-expr-renderer.d.ts.map +1 -1
- package/dist/query-builder/postgresql/postgresql-expr-renderer.js +449 -422
- package/dist/query-builder/postgresql/postgresql-expr-renderer.js.map +1 -6
- package/dist/query-builder/postgresql/postgresql-query-builder.js +511 -460
- package/dist/query-builder/postgresql/postgresql-query-builder.js.map +1 -6
- package/dist/query-builder/query-builder.d.ts +1 -1
- package/dist/query-builder/query-builder.js +13 -13
- package/dist/query-builder/query-builder.js.map +1 -6
- package/dist/schema/factory/column-builder.d.ts +84 -84
- package/dist/schema/factory/column-builder.js +248 -185
- package/dist/schema/factory/column-builder.js.map +1 -6
- package/dist/schema/factory/index-builder.d.ts +38 -38
- package/dist/schema/factory/index-builder.js +144 -85
- package/dist/schema/factory/index-builder.js.map +1 -6
- package/dist/schema/factory/relation-builder.d.ts +91 -91
- package/dist/schema/factory/relation-builder.d.ts.map +1 -1
- package/dist/schema/factory/relation-builder.js +274 -136
- package/dist/schema/factory/relation-builder.js.map +1 -6
- package/dist/schema/procedure-builder.d.ts +51 -51
- package/dist/schema/procedure-builder.d.ts.map +1 -1
- package/dist/schema/procedure-builder.js +205 -131
- package/dist/schema/procedure-builder.js.map +1 -6
- package/dist/schema/table-builder.d.ts +55 -55
- package/dist/schema/table-builder.d.ts.map +1 -1
- package/dist/schema/table-builder.js +274 -205
- package/dist/schema/table-builder.js.map +1 -6
- package/dist/schema/view-builder.d.ts +44 -44
- package/dist/schema/view-builder.d.ts.map +1 -1
- package/dist/schema/view-builder.js +189 -116
- package/dist/schema/view-builder.js.map +1 -6
- package/dist/types/column.js +60 -30
- package/dist/types/column.js.map +1 -6
- package/dist/types/db-context-def.d.ts +9 -9
- package/dist/types/db-context-def.js +2 -1
- package/dist/types/db-context-def.js.map +1 -6
- package/dist/types/db.d.ts +47 -47
- package/dist/types/db.js +15 -5
- package/dist/types/db.js.map +1 -6
- package/dist/types/expr.d.ts +81 -81
- package/dist/types/expr.d.ts.map +1 -1
- package/dist/types/expr.js +3 -1
- package/dist/types/expr.js.map +1 -6
- package/dist/types/query-def.d.ts +46 -46
- package/dist/types/query-def.d.ts.map +1 -1
- package/dist/types/query-def.js +31 -24
- package/dist/types/query-def.js.map +1 -6
- package/dist/utils/result-parser.js +362 -221
- package/dist/utils/result-parser.js.map +1 -6
- package/package.json +5 -7
- package/src/create-db-context.ts +31 -31
- package/src/ddl/column-ddl.ts +4 -4
- package/src/ddl/initialize.ts +38 -38
- package/src/ddl/relation-ddl.ts +6 -6
- package/src/ddl/schema-ddl.ts +4 -4
- package/src/ddl/table-ddl.ts +24 -24
- package/src/errors/db-transaction-error.ts +13 -13
- package/src/exec/executable.ts +25 -25
- package/src/exec/queryable.ts +134 -134
- package/src/exec/search-parser.ts +50 -50
- package/src/expr/expr-unit.ts +4 -4
- package/src/expr/expr.ts +13 -13
- package/src/index.ts +8 -8
- package/src/models/system-migration.ts +1 -1
- package/src/query-builder/base/expr-renderer-base.ts +21 -21
- package/src/query-builder/base/query-builder-base.ts +33 -33
- package/src/query-builder/mssql/mssql-expr-renderer.ts +11 -11
- package/src/query-builder/mssql/mssql-query-builder.ts +11 -11
- package/src/query-builder/mysql/mysql-expr-renderer.ts +15 -15
- package/src/query-builder/mysql/mysql-query-builder.ts +3 -3
- package/src/query-builder/postgresql/postgresql-expr-renderer.ts +9 -9
- package/src/query-builder/postgresql/postgresql-query-builder.ts +7 -7
- package/src/query-builder/query-builder.ts +1 -1
- package/src/schema/factory/column-builder.ts +86 -86
- package/src/schema/factory/index-builder.ts +38 -38
- package/src/schema/factory/relation-builder.ts +93 -93
- package/src/schema/procedure-builder.ts +52 -52
- package/src/schema/table-builder.ts +56 -56
- package/src/schema/view-builder.ts +45 -45
- package/src/types/column.ts +1 -1
- package/src/types/db-context-def.ts +15 -15
- package/src/types/db.ts +50 -50
- package/src/types/expr.ts +103 -103
- package/src/types/query-def.ts +50 -50
- package/src/utils/result-parser.ts +39 -39
- package/README.md +0 -192
- package/docs/core.md +0 -234
- package/docs/expression.md +0 -234
- package/docs/query-builder.md +0 -93
- package/docs/queryable.md +0 -198
- package/docs/schema-builders.md +0 -463
- package/docs/types.md +0 -445
- package/docs/utilities.md +0 -27
- package/tests/db-context/create-db-context.spec.ts +0 -193
- package/tests/db-context/define-db-context.spec.ts +0 -17
- package/tests/ddl/basic.expected.ts +0 -341
- package/tests/ddl/basic.spec.ts +0 -557
- package/tests/ddl/column-builder.expected.ts +0 -310
- package/tests/ddl/column-builder.spec.ts +0 -525
- package/tests/ddl/index-builder.expected.ts +0 -38
- package/tests/ddl/index-builder.spec.ts +0 -148
- package/tests/ddl/procedure-builder.expected.ts +0 -52
- package/tests/ddl/procedure-builder.spec.ts +0 -128
- package/tests/ddl/relation-builder.expected.ts +0 -36
- package/tests/ddl/relation-builder.spec.ts +0 -171
- package/tests/ddl/table-builder.expected.ts +0 -113
- package/tests/ddl/table-builder.spec.ts +0 -399
- package/tests/ddl/view-builder.expected.ts +0 -38
- package/tests/ddl/view-builder.spec.ts +0 -116
- package/tests/dml/delete.expected.ts +0 -96
- package/tests/dml/delete.spec.ts +0 -127
- package/tests/dml/insert.expected.ts +0 -192
- package/tests/dml/insert.spec.ts +0 -210
- package/tests/dml/update.expected.ts +0 -176
- package/tests/dml/update.spec.ts +0 -222
- package/tests/dml/upsert.expected.ts +0 -215
- package/tests/dml/upsert.spec.ts +0 -190
- package/tests/errors/queryable-errors.spec.ts +0 -126
- package/tests/escape.spec.ts +0 -59
- package/tests/examples/pivot.expected.ts +0 -211
- package/tests/examples/pivot.spec.ts +0 -200
- package/tests/examples/sampling.expected.ts +0 -69
- package/tests/examples/sampling.spec.ts +0 -42
- package/tests/examples/unpivot.expected.ts +0 -120
- package/tests/examples/unpivot.spec.ts +0 -161
- package/tests/exec/search-parser.spec.ts +0 -267
- package/tests/executable/basic.expected.ts +0 -18
- package/tests/executable/basic.spec.ts +0 -54
- package/tests/expr/comparison.expected.ts +0 -282
- package/tests/expr/comparison.spec.ts +0 -334
- package/tests/expr/conditional.expected.ts +0 -134
- package/tests/expr/conditional.spec.ts +0 -249
- package/tests/expr/date.expected.ts +0 -332
- package/tests/expr/date.spec.ts +0 -459
- package/tests/expr/math.expected.ts +0 -62
- package/tests/expr/math.spec.ts +0 -59
- package/tests/expr/string.expected.ts +0 -218
- package/tests/expr/string.spec.ts +0 -300
- package/tests/expr/utility.expected.ts +0 -147
- package/tests/expr/utility.spec.ts +0 -155
- package/tests/select/basic.expected.ts +0 -322
- package/tests/select/basic.spec.ts +0 -433
- package/tests/select/filter.expected.ts +0 -357
- package/tests/select/filter.spec.ts +0 -954
- package/tests/select/group.expected.ts +0 -169
- package/tests/select/group.spec.ts +0 -159
- package/tests/select/join.expected.ts +0 -582
- package/tests/select/join.spec.ts +0 -692
- package/tests/select/order.expected.ts +0 -150
- package/tests/select/order.spec.ts +0 -140
- package/tests/select/recursive-cte.expected.ts +0 -244
- package/tests/select/recursive-cte.spec.ts +0 -514
- package/tests/select/result-meta.spec.ts +0 -270
- package/tests/select/subquery.expected.ts +0 -363
- package/tests/select/subquery.spec.ts +0 -441
- package/tests/select/view.expected.ts +0 -155
- package/tests/select/view.spec.ts +0 -235
- package/tests/select/window.expected.ts +0 -345
- package/tests/select/window.spec.ts +0 -433
- package/tests/setup/MockExecutor.ts +0 -18
- package/tests/setup/TestDbContext.ts +0 -59
- package/tests/setup/models/Company.ts +0 -13
- package/tests/setup/models/Employee.ts +0 -10
- package/tests/setup/models/MonthlySales.ts +0 -11
- package/tests/setup/models/Post.ts +0 -16
- package/tests/setup/models/Sales.ts +0 -10
- package/tests/setup/models/User.ts +0 -19
- package/tests/setup/procedure/GetAllUsers.ts +0 -9
- package/tests/setup/procedure/GetUserById.ts +0 -12
- package/tests/setup/test-utils.ts +0 -72
- package/tests/setup/views/ActiveUsers.ts +0 -8
- package/tests/setup/views/UserSummary.ts +0 -11
- package/tests/types/nullable-queryable-record.spec.ts +0 -97
- package/tests/utils/result-parser-perf.spec.ts +0 -143
- 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
|
-
```
|
package/docs/expression.md
DELETED
|
@@ -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) |
|