@simplysm/orm-common 13.0.100 → 14.0.4
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/README.md +90 -147
- 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 +108 -108
- 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 +5 -5
- 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.d.ts +2 -2
- package/dist/query-builder/mssql/mssql-query-builder.d.ts.map +1 -1
- 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 +5 -5
- 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.d.ts +10 -10
- package/dist/query-builder/mysql/mysql-query-builder.d.ts.map +1 -1
- 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 +5 -5
- 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.d.ts +8 -8
- package/dist/query-builder/postgresql/postgresql-query-builder.d.ts.map +1 -1
- 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 +99 -99
- 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.d.ts +21 -21
- 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.d.ts +11 -11
- package/dist/utils/result-parser.js +362 -221
- package/dist/utils/result-parser.js.map +1 -6
- package/docs/core.md +117 -145
- package/docs/expression.md +186 -203
- package/docs/query-builder.md +75 -42
- package/docs/queryable.md +189 -151
- package/docs/schema-builders.md +172 -283
- package/docs/types.md +229 -173
- package/package.json +7 -5
- 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 +152 -152
- package/src/exec/search-parser.ts +50 -50
- package/src/expr/expr-unit.ts +4 -4
- package/src/expr/expr.ts +118 -118
- 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 +28 -28
- package/src/query-builder/mssql/mssql-query-builder.ts +37 -37
- package/src/query-builder/mysql/mysql-expr-renderer.ts +29 -29
- package/src/query-builder/mysql/mysql-query-builder.ts +70 -70
- package/src/query-builder/postgresql/postgresql-expr-renderer.ts +22 -22
- package/src/query-builder/postgresql/postgresql-query-builder.ts +54 -54
- 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 +102 -102
- package/src/schema/procedure-builder.ts +52 -52
- package/src/schema/table-builder.ts +56 -56
- package/src/schema/view-builder.ts +47 -47
- package/src/types/column.ts +24 -24
- 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 +88 -88
- 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/docs/types.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Types
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core type definitions for the ORM.
|
|
4
|
+
|
|
5
|
+
## Dialect
|
|
4
6
|
|
|
5
7
|
Supported database dialects.
|
|
6
8
|
|
|
@@ -8,17 +10,15 @@ Supported database dialects.
|
|
|
8
10
|
type Dialect = "mysql" | "mssql" | "postgresql";
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
List of all supported database dialects.
|
|
13
|
+
**Constant:**
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
16
|
const dialects: Dialect[] = ["mysql", "mssql", "postgresql"];
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## IsolationLevel
|
|
20
20
|
|
|
21
|
-
Transaction isolation
|
|
21
|
+
Transaction isolation levels.
|
|
22
22
|
|
|
23
23
|
```typescript
|
|
24
24
|
type IsolationLevel =
|
|
@@ -28,9 +28,9 @@ type IsolationLevel =
|
|
|
28
28
|
| "SERIALIZABLE";
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
##
|
|
31
|
+
## DataRecord
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
Recursive data record type for query results. Supports nested relations.
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
36
|
type DataRecord = {
|
|
@@ -38,9 +38,9 @@ type DataRecord = {
|
|
|
38
38
|
};
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
##
|
|
41
|
+
## DbContextExecutor
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Interface for DB connection and query execution. Implemented by `NodeDbContextExecutor` (server) or service-based executors (client).
|
|
44
44
|
|
|
45
45
|
```typescript
|
|
46
46
|
interface DbContextExecutor {
|
|
@@ -56,68 +56,74 @@ interface DbContextExecutor {
|
|
|
56
56
|
}
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|--------|-------------|
|
|
61
|
-
| `connect()` | Establish DB connection |
|
|
62
|
-
| `close()` | Close DB connection |
|
|
63
|
-
| `beginTransaction()` | Begin transaction with optional isolation level |
|
|
64
|
-
| `commitTransaction()` | Commit transaction |
|
|
65
|
-
| `rollbackTransaction()` | Rollback transaction |
|
|
66
|
-
| `executeDefs()` | Execute QueryDef array and return results |
|
|
59
|
+
## ResultMeta
|
|
67
60
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`QueryBuilder.build()` return type.
|
|
61
|
+
Metadata for transforming raw query results into typed TypeScript objects.
|
|
71
62
|
|
|
72
63
|
```typescript
|
|
73
|
-
interface
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
resultSetStride?: number;
|
|
64
|
+
interface ResultMeta {
|
|
65
|
+
columns: Record<string, ColumnPrimitiveStr>;
|
|
66
|
+
joins: Record<string, { isSingle: boolean }>;
|
|
77
67
|
}
|
|
78
68
|
```
|
|
79
69
|
|
|
80
|
-
| Field |
|
|
81
|
-
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `resultSetStride` | `number` | Extract every Nth result set from multiple results |
|
|
70
|
+
| Field | Description |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `columns` | Maps column name (dot-notation for nested) to TypeScript type name |
|
|
73
|
+
| `joins` | Maps JOIN alias to single/array indicator |
|
|
85
74
|
|
|
86
|
-
##
|
|
75
|
+
## Migration
|
|
87
76
|
|
|
88
|
-
|
|
77
|
+
Database migration definition for schema versioning.
|
|
89
78
|
|
|
90
79
|
```typescript
|
|
91
|
-
interface
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
interface Migration {
|
|
81
|
+
name: string;
|
|
82
|
+
up: (db: DbContextBase & DbContextDdlMethods) => Promise<void>;
|
|
94
83
|
}
|
|
95
84
|
```
|
|
96
85
|
|
|
97
86
|
| Field | Type | Description |
|
|
98
|
-
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `name` | `string` | Unique migration name (timestamp recommended) |
|
|
89
|
+
| `up` | `(db) => Promise<void>` | Migration function with DDL access |
|
|
101
90
|
|
|
102
|
-
##
|
|
91
|
+
## QueryBuildResult
|
|
103
92
|
|
|
104
|
-
|
|
93
|
+
Return type of `QueryBuilderBase.build()`.
|
|
105
94
|
|
|
106
95
|
```typescript
|
|
107
|
-
interface
|
|
108
|
-
|
|
109
|
-
|
|
96
|
+
interface QueryBuildResult {
|
|
97
|
+
sql: string;
|
|
98
|
+
resultSetIndex?: number;
|
|
99
|
+
resultSetStride?: number;
|
|
110
100
|
}
|
|
111
101
|
```
|
|
112
102
|
|
|
113
103
|
| Field | Type | Description |
|
|
114
|
-
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `sql` | `string` | Generated SQL string |
|
|
106
|
+
| `resultSetIndex` | `number` | Result set index to read (default: 0) |
|
|
107
|
+
| `resultSetStride` | `number` | Read every Nth result set (for multi-INSERT) |
|
|
108
|
+
|
|
109
|
+
## ColumnMeta
|
|
110
|
+
|
|
111
|
+
Column metadata generated by `ColumnBuilder`.
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
interface ColumnMeta {
|
|
115
|
+
type: ColumnPrimitiveStr;
|
|
116
|
+
dataType: DataType;
|
|
117
|
+
autoIncrement?: boolean;
|
|
118
|
+
nullable?: boolean;
|
|
119
|
+
default?: ColumnPrimitive;
|
|
120
|
+
description?: string;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
117
123
|
|
|
118
|
-
##
|
|
124
|
+
## DataType
|
|
119
125
|
|
|
120
|
-
SQL data type definition.
|
|
126
|
+
SQL data type definition. Discriminated union on `type` field.
|
|
121
127
|
|
|
122
128
|
```typescript
|
|
123
129
|
type DataType =
|
|
@@ -137,9 +143,30 @@ type DataType =
|
|
|
137
143
|
| { type: "uuid" };
|
|
138
144
|
```
|
|
139
145
|
|
|
140
|
-
|
|
146
|
+
**DBMS Mapping:**
|
|
147
|
+
|
|
148
|
+
| DataType | MySQL | MSSQL | PostgreSQL |
|
|
149
|
+
|---|---|---|---|
|
|
150
|
+
| `int` | INT | INT | INT |
|
|
151
|
+
| `bigint` | BIGINT | BIGINT | BIGINT |
|
|
152
|
+
| `float` | FLOAT | REAL | REAL |
|
|
153
|
+
| `double` | DOUBLE | FLOAT | DOUBLE PRECISION |
|
|
154
|
+
| `decimal` | DECIMAL(p,s) | DECIMAL(p,s) | DECIMAL(p,s) |
|
|
155
|
+
| `varchar` | VARCHAR(n) | NVARCHAR(n) | VARCHAR(n) |
|
|
156
|
+
| `char` | CHAR(n) | NCHAR(n) | CHAR(n) |
|
|
157
|
+
| `text` | LONGTEXT | NVARCHAR(MAX) | TEXT |
|
|
158
|
+
| `binary` | LONGBLOB | VARBINARY(MAX) | BYTEA |
|
|
159
|
+
| `boolean` | TINYINT(1) | BIT | BOOLEAN |
|
|
160
|
+
| `datetime` | DATETIME | DATETIME2 | TIMESTAMP |
|
|
161
|
+
| `date` | DATE | DATE | DATE |
|
|
162
|
+
| `time` | TIME | TIME | TIME |
|
|
163
|
+
| `uuid` | BINARY(16) | UNIQUEIDENTIFIER | UUID |
|
|
164
|
+
|
|
165
|
+
## Column Primitive Types
|
|
166
|
+
|
|
167
|
+
### ColumnPrimitiveMap
|
|
141
168
|
|
|
142
|
-
|
|
169
|
+
Maps TypeScript type names to actual types.
|
|
143
170
|
|
|
144
171
|
```typescript
|
|
145
172
|
type ColumnPrimitiveMap = {
|
|
@@ -154,15 +181,14 @@ type ColumnPrimitiveMap = {
|
|
|
154
181
|
};
|
|
155
182
|
```
|
|
156
183
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
Column primitive type name.
|
|
184
|
+
### ColumnPrimitiveStr
|
|
160
185
|
|
|
161
186
|
```typescript
|
|
162
187
|
type ColumnPrimitiveStr = keyof ColumnPrimitiveMap;
|
|
188
|
+
// "string" | "number" | "boolean" | "DateTime" | "DateOnly" | "Time" | "Uuid" | "Bytes"
|
|
163
189
|
```
|
|
164
190
|
|
|
165
|
-
|
|
191
|
+
### ColumnPrimitive
|
|
166
192
|
|
|
167
193
|
All primitive types that can be stored in columns. `undefined` represents NULL.
|
|
168
194
|
|
|
@@ -170,29 +196,24 @@ All primitive types that can be stored in columns. `undefined` represents NULL.
|
|
|
170
196
|
type ColumnPrimitive = ColumnPrimitiveMap[ColumnPrimitiveStr] | undefined;
|
|
171
197
|
```
|
|
172
198
|
|
|
173
|
-
|
|
199
|
+
### dataTypeStrToColumnPrimitiveStr
|
|
174
200
|
|
|
175
|
-
SQL DataType to
|
|
201
|
+
Constant mapping SQL DataType string to ColumnPrimitiveStr.
|
|
176
202
|
|
|
177
203
|
```typescript
|
|
178
|
-
const dataTypeStrToColumnPrimitiveStr:
|
|
179
|
-
|
|
180
|
-
varchar: "string"; char: "string"; text: "string";
|
|
181
|
-
binary: "Bytes"; boolean: "boolean";
|
|
182
|
-
datetime: "DateTime"; date: "DateOnly"; time: "Time"; uuid: "Uuid";
|
|
183
|
-
};
|
|
204
|
+
const dataTypeStrToColumnPrimitiveStr: Record<DataType["type"], ColumnPrimitiveStr>;
|
|
205
|
+
// { int: "number", bigint: "number", varchar: "string", datetime: "DateTime", ... }
|
|
184
206
|
```
|
|
185
207
|
|
|
186
|
-
|
|
208
|
+
### InferColumnPrimitiveFromDataType
|
|
187
209
|
|
|
188
|
-
TypeScript type
|
|
210
|
+
Infer TypeScript type from a `DataType`.
|
|
189
211
|
|
|
190
212
|
```typescript
|
|
191
|
-
type InferColumnPrimitiveFromDataType<
|
|
192
|
-
ColumnPrimitiveMap[(typeof dataTypeStrToColumnPrimitiveStr)[TDataType["type"]]];
|
|
213
|
+
type InferColumnPrimitiveFromDataType<T extends DataType> = ColumnPrimitiveMap[...];
|
|
193
214
|
```
|
|
194
215
|
|
|
195
|
-
|
|
216
|
+
### inferColumnPrimitiveStr
|
|
196
217
|
|
|
197
218
|
Infer `ColumnPrimitiveStr` from a runtime value.
|
|
198
219
|
|
|
@@ -200,41 +221,11 @@ Infer `ColumnPrimitiveStr` from a runtime value.
|
|
|
200
221
|
function inferColumnPrimitiveStr(value: ColumnPrimitive): ColumnPrimitiveStr;
|
|
201
222
|
```
|
|
202
223
|
|
|
203
|
-
##
|
|
204
|
-
|
|
205
|
-
Column metadata. Generated by `ColumnBuilder` and passed to `TableBuilder`.
|
|
206
|
-
|
|
207
|
-
```typescript
|
|
208
|
-
interface ColumnMeta {
|
|
209
|
-
type: ColumnPrimitiveStr;
|
|
210
|
-
dataType: DataType;
|
|
211
|
-
autoIncrement?: boolean;
|
|
212
|
-
nullable?: boolean;
|
|
213
|
-
default?: ColumnPrimitive;
|
|
214
|
-
description?: string;
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
| Field | Type | Description |
|
|
219
|
-
|-------|------|-------------|
|
|
220
|
-
| `type` | `ColumnPrimitiveStr` | TypeScript type name |
|
|
221
|
-
| `dataType` | `DataType` | SQL data type |
|
|
222
|
-
| `autoIncrement` | `boolean` | Whether to auto-increment |
|
|
223
|
-
| `nullable` | `boolean` | Whether to allow NULL |
|
|
224
|
-
| `default` | `ColumnPrimitive` | Default value |
|
|
225
|
-
| `description` | `string` | Column description (DDL comment) |
|
|
224
|
+
## QueryDef Types
|
|
226
225
|
|
|
227
|
-
|
|
226
|
+
All query definition types used by the QueryBuilder.
|
|
228
227
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
```typescript
|
|
232
|
-
type DateUnit = "year" | "month" | "day" | "hour" | "minute" | "second";
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
## `QueryDefObjectName`
|
|
236
|
-
|
|
237
|
-
DB object name (table, view, procedure, etc.).
|
|
228
|
+
### QueryDefObjectName
|
|
238
229
|
|
|
239
230
|
```typescript
|
|
240
231
|
interface QueryDefObjectName {
|
|
@@ -244,31 +235,17 @@ interface QueryDefObjectName {
|
|
|
244
235
|
}
|
|
245
236
|
```
|
|
246
237
|
|
|
247
|
-
|
|
248
|
-
|-------|------|-------------|
|
|
249
|
-
| `database` | `string` | Database name |
|
|
250
|
-
| `schema` | `string` | Schema name |
|
|
251
|
-
| `name` | `string` | Object name |
|
|
252
|
-
|
|
253
|
-
## `QueryDef`
|
|
254
|
-
|
|
255
|
-
All query definition union type. DML + DDL + Utils + Meta.
|
|
238
|
+
### CudOutputDef
|
|
256
239
|
|
|
257
240
|
```typescript
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
| RenameColumnQueryDef | DropPrimaryKeyQueryDef | AddPrimaryKeyQueryDef
|
|
264
|
-
| AddForeignKeyQueryDef | DropForeignKeyQueryDef | AddIndexQueryDef | DropIndexQueryDef
|
|
265
|
-
| CreateViewQueryDef | DropViewQueryDef | CreateProcQueryDef | DropProcQueryDef
|
|
266
|
-
| ExecProcQueryDef | SwitchFkQueryDef | SchemaExistsQueryDef;
|
|
241
|
+
interface CudOutputDef {
|
|
242
|
+
columns: string[];
|
|
243
|
+
pkColNames: string[];
|
|
244
|
+
aiColName?: string;
|
|
245
|
+
}
|
|
267
246
|
```
|
|
268
247
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
SELECT query definition.
|
|
248
|
+
### SelectQueryDef
|
|
272
249
|
|
|
273
250
|
```typescript
|
|
274
251
|
interface SelectQueryDef {
|
|
@@ -289,9 +266,7 @@ interface SelectQueryDef {
|
|
|
289
266
|
}
|
|
290
267
|
```
|
|
291
268
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
JOIN query definition. Extends `SelectQueryDef` with `isSingle` flag.
|
|
269
|
+
### SelectQueryDefJoin
|
|
295
270
|
|
|
296
271
|
```typescript
|
|
297
272
|
interface SelectQueryDefJoin extends SelectQueryDef {
|
|
@@ -299,9 +274,7 @@ interface SelectQueryDefJoin extends SelectQueryDef {
|
|
|
299
274
|
}
|
|
300
275
|
```
|
|
301
276
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
INSERT query definition.
|
|
277
|
+
### InsertQueryDef
|
|
305
278
|
|
|
306
279
|
```typescript
|
|
307
280
|
interface InsertQueryDef {
|
|
@@ -313,38 +286,30 @@ interface InsertQueryDef {
|
|
|
313
286
|
}
|
|
314
287
|
```
|
|
315
288
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
Conditional INSERT query definition. Insert only if not exists.
|
|
289
|
+
### InsertIfNotExistsQueryDef
|
|
319
290
|
|
|
320
291
|
```typescript
|
|
321
292
|
interface InsertIfNotExistsQueryDef {
|
|
322
293
|
type: "insertIfNotExists";
|
|
323
294
|
table: QueryDefObjectName;
|
|
324
295
|
record: Record<string, ColumnPrimitive>;
|
|
325
|
-
existsSelectQuery: SelectQueryDef
|
|
326
|
-
overrideIdentity?: boolean;
|
|
296
|
+
existsSelectQuery: Omit<SelectQueryDef, "select">;
|
|
327
297
|
output?: CudOutputDef;
|
|
328
298
|
}
|
|
329
299
|
```
|
|
330
300
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
INSERT INTO SELECT query definition. Insert subquery results.
|
|
301
|
+
### InsertIntoQueryDef
|
|
334
302
|
|
|
335
303
|
```typescript
|
|
336
304
|
interface InsertIntoQueryDef {
|
|
337
305
|
type: "insertInto";
|
|
338
306
|
table: QueryDefObjectName;
|
|
339
307
|
recordsSelectQuery: SelectQueryDef;
|
|
340
|
-
overrideIdentity?: boolean;
|
|
341
308
|
output?: CudOutputDef;
|
|
342
309
|
}
|
|
343
310
|
```
|
|
344
311
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
UPDATE query definition.
|
|
312
|
+
### UpdateQueryDef
|
|
348
313
|
|
|
349
314
|
```typescript
|
|
350
315
|
interface UpdateQueryDef {
|
|
@@ -360,9 +325,7 @@ interface UpdateQueryDef {
|
|
|
360
325
|
}
|
|
361
326
|
```
|
|
362
327
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
DELETE query definition.
|
|
328
|
+
### DeleteQueryDef
|
|
366
329
|
|
|
367
330
|
```typescript
|
|
368
331
|
interface DeleteQueryDef {
|
|
@@ -377,69 +340,162 @@ interface DeleteQueryDef {
|
|
|
377
340
|
}
|
|
378
341
|
```
|
|
379
342
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
UPSERT query definition. INSERT or UPDATE (MERGE pattern).
|
|
343
|
+
### UpsertQueryDef
|
|
383
344
|
|
|
384
345
|
```typescript
|
|
385
346
|
interface UpsertQueryDef {
|
|
386
347
|
type: "upsert";
|
|
387
348
|
table: QueryDefObjectName;
|
|
388
|
-
existsSelectQuery: SelectQueryDef
|
|
389
|
-
insertRecord: Record<string, Expr>;
|
|
349
|
+
existsSelectQuery: Omit<SelectQueryDef, "select">;
|
|
390
350
|
updateRecord: Record<string, Expr>;
|
|
391
|
-
|
|
351
|
+
insertRecord: Record<string, Expr>;
|
|
392
352
|
output?: CudOutputDef;
|
|
393
353
|
}
|
|
394
354
|
```
|
|
395
355
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
356
|
+
### DDL QueryDef Types
|
|
357
|
+
|
|
358
|
+
| Type | Description |
|
|
359
|
+
|---|---|
|
|
360
|
+
| `CreateTableQueryDef` | CREATE TABLE |
|
|
361
|
+
| `DropTableQueryDef` | DROP TABLE |
|
|
362
|
+
| `RenameTableQueryDef` | RENAME TABLE |
|
|
363
|
+
| `TruncateQueryDef` | TRUNCATE TABLE |
|
|
364
|
+
| `AddColumnQueryDef` | ADD COLUMN |
|
|
365
|
+
| `DropColumnQueryDef` | DROP COLUMN |
|
|
366
|
+
| `ModifyColumnQueryDef` | ALTER COLUMN |
|
|
367
|
+
| `RenameColumnQueryDef` | RENAME COLUMN |
|
|
368
|
+
| `AddPrimaryKeyQueryDef` | ADD PRIMARY KEY |
|
|
369
|
+
| `DropPrimaryKeyQueryDef` | DROP PRIMARY KEY |
|
|
370
|
+
| `AddForeignKeyQueryDef` | ADD FOREIGN KEY |
|
|
371
|
+
| `DropForeignKeyQueryDef` | DROP FOREIGN KEY |
|
|
372
|
+
| `AddIndexQueryDef` | CREATE INDEX |
|
|
373
|
+
| `DropIndexQueryDef` | DROP INDEX |
|
|
374
|
+
| `CreateViewQueryDef` | CREATE VIEW |
|
|
375
|
+
| `DropViewQueryDef` | DROP VIEW |
|
|
376
|
+
| `CreateProcQueryDef` | CREATE PROCEDURE |
|
|
377
|
+
| `DropProcQueryDef` | DROP PROCEDURE |
|
|
378
|
+
| `ExecProcQueryDef` | EXECUTE PROCEDURE |
|
|
379
|
+
| `ClearSchemaQueryDef` | Clear all objects in schema |
|
|
380
|
+
| `SchemaExistsQueryDef` | Check schema existence |
|
|
381
|
+
| `SwitchFkQueryDef` | Enable/disable FK constraints |
|
|
382
|
+
|
|
383
|
+
### QueryDef (union)
|
|
399
384
|
|
|
400
385
|
```typescript
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
386
|
+
type QueryDef = SelectQueryDef | InsertQueryDef | InsertIfNotExistsQueryDef
|
|
387
|
+
| InsertIntoQueryDef | UpdateQueryDef | DeleteQueryDef | UpsertQueryDef
|
|
388
|
+
| CreateTableQueryDef | DropTableQueryDef | RenameTableQueryDef
|
|
389
|
+
| TruncateQueryDef | AddColumnQueryDef | DropColumnQueryDef
|
|
390
|
+
| ModifyColumnQueryDef | RenameColumnQueryDef
|
|
391
|
+
| AddPrimaryKeyQueryDef | DropPrimaryKeyQueryDef
|
|
392
|
+
| AddForeignKeyQueryDef | DropForeignKeyQueryDef
|
|
393
|
+
| AddIndexQueryDef | DropIndexQueryDef
|
|
394
|
+
| CreateViewQueryDef | DropViewQueryDef
|
|
395
|
+
| CreateProcQueryDef | DropProcQueryDef | ExecProcQueryDef
|
|
396
|
+
| ClearSchemaQueryDef | SchemaExistsQueryDef | SwitchFkQueryDef;
|
|
406
397
|
```
|
|
407
398
|
|
|
408
|
-
##
|
|
399
|
+
## Expr Types
|
|
400
|
+
|
|
401
|
+
All expression AST node types. See [expression.md](expression.md) for the `expr` builder API.
|
|
409
402
|
|
|
410
|
-
|
|
403
|
+
### DateUnit
|
|
411
404
|
|
|
412
405
|
```typescript
|
|
413
|
-
|
|
406
|
+
type DateUnit = "year" | "month" | "day" | "hour" | "minute" | "second";
|
|
414
407
|
```
|
|
415
408
|
|
|
416
|
-
|
|
409
|
+
### WhereExpr
|
|
417
410
|
|
|
418
|
-
|
|
411
|
+
Union of all WHERE-clause expression types.
|
|
419
412
|
|
|
420
413
|
```typescript
|
|
421
|
-
type
|
|
414
|
+
type WhereExpr =
|
|
415
|
+
| ExprEq | ExprGt | ExprLt | ExprGte | ExprLte | ExprBetween
|
|
416
|
+
| ExprIsNull | ExprLike | ExprRegexp | ExprIn | ExprInQuery | ExprExists
|
|
417
|
+
| ExprNot | ExprAnd | ExprOr;
|
|
422
418
|
```
|
|
423
419
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
Union type `Expr` covers all expression types: value (`ExprColumn`, `ExprValue`, `ExprRaw`), string, numeric, date, conditional, aggregate, window, and subquery expressions.
|
|
420
|
+
### Expr
|
|
427
421
|
|
|
428
|
-
Union
|
|
422
|
+
Union of all expression types (values, functions, aggregates, window, etc.).
|
|
429
423
|
|
|
430
|
-
|
|
424
|
+
```typescript
|
|
425
|
+
type Expr =
|
|
426
|
+
| ExprColumn | ExprValue | ExprRaw
|
|
427
|
+
| ExprConcat | ExprLeft | ExprRight | ExprTrim | ExprPadStart | ExprReplace
|
|
428
|
+
| ExprUpper | ExprLower | ExprLength | ExprByteLength | ExprSubstring | ExprIndexOf
|
|
429
|
+
| ExprAbs | ExprRound | ExprCeil | ExprFloor
|
|
430
|
+
| ExprYear | ExprMonth | ExprDay | ExprHour | ExprMinute | ExprSecond
|
|
431
|
+
| ExprIsoWeek | ExprIsoWeekStartDate | ExprIsoYearMonth
|
|
432
|
+
| ExprDateDiff | ExprDateAdd | ExprFormatDate
|
|
433
|
+
| ExprCoalesce | ExprNullIf | ExprIs | ExprSwitch | ExprIf
|
|
434
|
+
| ExprCount | ExprSum | ExprAvg | ExprMax | ExprMin
|
|
435
|
+
| ExprGreatest | ExprLeast | ExprRowNum | ExprRandom | ExprCast
|
|
436
|
+
| ExprWindow | ExprSubquery;
|
|
437
|
+
```
|
|
431
438
|
|
|
432
|
-
|
|
439
|
+
### WinSpec
|
|
433
440
|
|
|
434
441
|
```typescript
|
|
435
442
|
interface WinSpec {
|
|
436
443
|
partitionBy?: Expr[];
|
|
437
444
|
orderBy?: [Expr, ("ASC" | "DESC")?][];
|
|
438
445
|
}
|
|
446
|
+
```
|
|
439
447
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
448
|
+
### WinFn
|
|
449
|
+
|
|
450
|
+
Union of all window function types.
|
|
451
|
+
|
|
452
|
+
```typescript
|
|
453
|
+
type WinFn =
|
|
454
|
+
| WinFnRowNumber | WinFnRank | WinFnDenseRank | WinFnNtile
|
|
455
|
+
| WinFnLag | WinFnLead | WinFnFirstValue | WinFnLastValue
|
|
456
|
+
| WinFnSum | WinFnAvg | WinFnCount | WinFnMin | WinFnMax;
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
## parseQueryResult
|
|
460
|
+
|
|
461
|
+
Transforms raw DB query results into typed TypeScript objects using `ResultMeta`. Handles type parsing, flat-to-nested conversion, and JOIN grouping.
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
async function parseQueryResult<TRecord>(
|
|
465
|
+
rawResults: Record<string, unknown>[],
|
|
466
|
+
meta: ResultMeta,
|
|
467
|
+
): Promise<TRecord[] | undefined>;
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
**Parameters:**
|
|
471
|
+
|
|
472
|
+
| Parameter | Type | Description |
|
|
473
|
+
|---|---|---|
|
|
474
|
+
| `rawResults` | `Record<string, unknown>[]` | Raw result rows from database |
|
|
475
|
+
| `meta` | `ResultMeta` | Type and JOIN structure metadata |
|
|
476
|
+
|
|
477
|
+
**Returns:** Typed and nested result array, or `undefined` if empty.
|
|
478
|
+
|
|
479
|
+
**Example:**
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
const raw = [
|
|
483
|
+
{ id: "1", name: "User1", "posts.id": "10", "posts.title": "Post1" },
|
|
484
|
+
{ id: "1", name: "User1", "posts.id": "11", "posts.title": "Post2" },
|
|
485
|
+
];
|
|
486
|
+
const meta = {
|
|
487
|
+
columns: { id: "number", name: "string", "posts.id": "number", "posts.title": "string" },
|
|
488
|
+
joins: { posts: { isSingle: false } },
|
|
489
|
+
};
|
|
490
|
+
const result = await parseQueryResult(raw, meta);
|
|
491
|
+
// [{ id: 1, name: "User1", posts: [{ id: 10, title: "Post1" }, { id: 11, title: "Post2" }] }]
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## _Migration
|
|
495
|
+
|
|
496
|
+
System migration table definition. Automatically added to every `DbContextDef` by `defineDbContext()`.
|
|
497
|
+
|
|
498
|
+
```typescript
|
|
499
|
+
const _Migration: TableBuilder<{ code: ColumnBuilder<string, ...> }, {}>;
|
|
500
|
+
// Table: "_migration", columns: { code: varchar(255) }, primaryKey: "code"
|
|
445
501
|
```
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/orm-common",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"author": "
|
|
3
|
+
"version": "14.0.4",
|
|
4
|
+
"description": "심플리즘 패키지 - ORM (common)",
|
|
5
|
+
"author": "심플리즘",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
17
|
"src",
|
|
18
|
-
"tests",
|
|
19
18
|
"docs"
|
|
20
19
|
],
|
|
21
20
|
"sideEffects": false,
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^20.19.37"
|
|
23
|
+
},
|
|
22
24
|
"dependencies": {
|
|
23
|
-
"@simplysm/core-common": "
|
|
25
|
+
"@simplysm/core-common": "14.0.4"
|
|
24
26
|
}
|
|
25
27
|
}
|