metal-orm 1.0.16 → 1.0.18
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 +37 -40
- package/dist/decorators/index.cjs +344 -69
- package/dist/decorators/index.cjs.map +1 -1
- package/dist/decorators/index.d.cts +1 -1
- package/dist/decorators/index.d.ts +1 -1
- package/dist/decorators/index.js +344 -69
- package/dist/decorators/index.js.map +1 -1
- package/dist/index.cjs +567 -181
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -30
- package/dist/index.d.ts +66 -30
- package/dist/index.js +559 -181
- package/dist/index.js.map +1 -1
- package/dist/{select-BKZrMRCQ.d.cts → select-BuMpVcVt.d.cts} +265 -74
- package/dist/{select-BKZrMRCQ.d.ts → select-BuMpVcVt.d.ts} +265 -74
- package/package.json +5 -1
- package/src/codegen/naming-strategy.ts +15 -10
- package/src/core/ast/aggregate-functions.ts +50 -4
- package/src/core/ast/builders.ts +23 -3
- package/src/core/ast/expression-builders.ts +36 -16
- package/src/core/ast/expression-nodes.ts +17 -9
- package/src/core/ast/join-node.ts +5 -3
- package/src/core/ast/join.ts +16 -16
- package/src/core/ast/query.ts +44 -29
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +18 -0
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +11 -0
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +9 -0
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +9 -0
- package/src/core/ddl/introspect/functions/postgres.ts +2 -6
- package/src/core/dialect/abstract.ts +12 -8
- package/src/core/dialect/base/sql-dialect.ts +58 -46
- package/src/core/dialect/mssql/functions.ts +24 -15
- package/src/core/dialect/mssql/index.ts +53 -28
- package/src/core/dialect/postgres/functions.ts +33 -24
- package/src/core/dialect/sqlite/functions.ts +19 -12
- package/src/core/dialect/sqlite/index.ts +22 -13
- package/src/core/functions/datetime.ts +2 -1
- package/src/core/functions/numeric.ts +2 -1
- package/src/core/functions/standard-strategy.ts +52 -12
- package/src/core/functions/text.ts +2 -1
- package/src/core/functions/types.ts +8 -8
- package/src/index.ts +5 -4
- package/src/orm/domain-event-bus.ts +43 -25
- package/src/orm/entity-meta.ts +40 -0
- package/src/orm/execution-context.ts +6 -0
- package/src/orm/hydration-context.ts +6 -4
- package/src/orm/orm-session.ts +35 -24
- package/src/orm/orm.ts +10 -10
- package/src/orm/query-logger.ts +15 -0
- package/src/orm/runtime-types.ts +60 -2
- package/src/orm/transaction-runner.ts +7 -0
- package/src/orm/unit-of-work.ts +1 -0
- package/src/query-builder/column-selector.ts +9 -7
- package/src/query-builder/insert-query-state.ts +13 -3
- package/src/query-builder/query-ast-service.ts +59 -38
- package/src/query-builder/relation-conditions.ts +38 -34
- package/src/query-builder/relation-manager.ts +8 -3
- package/src/query-builder/relation-service.ts +59 -46
- package/src/query-builder/select-helpers.ts +50 -0
- package/src/query-builder/select-query-state.ts +19 -7
- package/src/query-builder/select.ts +339 -167
- package/src/query-builder/update-query-state.ts +31 -9
- package/src/schema/column.ts +75 -39
- package/src/schema/types.ts +17 -6
package/src/schema/column.ts
CHANGED
|
@@ -1,39 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Supported column data types for database schema definitions
|
|
3
3
|
*/
|
|
4
|
-
export type ColumnType =
|
|
5
|
-
| 'INT'
|
|
6
|
-
| 'INTEGER'
|
|
7
|
-
| 'BIGINT'
|
|
8
|
-
| 'VARCHAR'
|
|
9
|
-
| 'TEXT'
|
|
10
|
-
| 'JSON'
|
|
11
|
-
| 'ENUM'
|
|
12
|
-
| 'DECIMAL'
|
|
13
|
-
| 'FLOAT'
|
|
14
|
-
| 'DOUBLE'
|
|
15
|
-
| 'UUID'
|
|
16
|
-
| '
|
|
17
|
-
| '
|
|
18
|
-
| '
|
|
19
|
-
| '
|
|
20
|
-
| '
|
|
21
|
-
| '
|
|
22
|
-
| '
|
|
23
|
-
| '
|
|
24
|
-
| '
|
|
25
|
-
| '
|
|
26
|
-
| '
|
|
27
|
-
| '
|
|
28
|
-
| '
|
|
29
|
-
| '
|
|
30
|
-
| '
|
|
31
|
-
| '
|
|
32
|
-
| '
|
|
33
|
-
| '
|
|
34
|
-
| '
|
|
35
|
-
| '
|
|
36
|
-
| '
|
|
4
|
+
export type ColumnType =
|
|
5
|
+
| 'INT'
|
|
6
|
+
| 'INTEGER'
|
|
7
|
+
| 'BIGINT'
|
|
8
|
+
| 'VARCHAR'
|
|
9
|
+
| 'TEXT'
|
|
10
|
+
| 'JSON'
|
|
11
|
+
| 'ENUM'
|
|
12
|
+
| 'DECIMAL'
|
|
13
|
+
| 'FLOAT'
|
|
14
|
+
| 'DOUBLE'
|
|
15
|
+
| 'UUID'
|
|
16
|
+
| 'BINARY'
|
|
17
|
+
| 'VARBINARY'
|
|
18
|
+
| 'BLOB'
|
|
19
|
+
| 'BYTEA'
|
|
20
|
+
| 'DATE'
|
|
21
|
+
| 'DATETIME'
|
|
22
|
+
| 'TIMESTAMP'
|
|
23
|
+
| 'TIMESTAMPTZ'
|
|
24
|
+
| 'BOOLEAN'
|
|
25
|
+
| 'int'
|
|
26
|
+
| 'integer'
|
|
27
|
+
| 'bigint'
|
|
28
|
+
| 'varchar'
|
|
29
|
+
| 'text'
|
|
30
|
+
| 'json'
|
|
31
|
+
| 'enum'
|
|
32
|
+
| 'decimal'
|
|
33
|
+
| 'float'
|
|
34
|
+
| 'double'
|
|
35
|
+
| 'uuid'
|
|
36
|
+
| 'binary'
|
|
37
|
+
| 'varbinary'
|
|
38
|
+
| 'blob'
|
|
39
|
+
| 'bytea'
|
|
40
|
+
| 'date'
|
|
41
|
+
| 'datetime'
|
|
42
|
+
| 'timestamp'
|
|
43
|
+
| 'timestamptz'
|
|
44
|
+
| 'boolean';
|
|
37
45
|
|
|
38
46
|
export type ReferentialAction =
|
|
39
47
|
| 'NO ACTION'
|
|
@@ -138,12 +146,40 @@ export const col = {
|
|
|
138
146
|
/**
|
|
139
147
|
* Creates a UUID column definition
|
|
140
148
|
*/
|
|
141
|
-
uuid: (): ColumnDef<'UUID'> => ({ name: '', type: 'UUID' }),
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Creates a
|
|
145
|
-
*/
|
|
146
|
-
|
|
149
|
+
uuid: (): ColumnDef<'UUID'> => ({ name: '', type: 'UUID' }),
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Creates a binary large object column definition
|
|
153
|
+
*/
|
|
154
|
+
blob: (): ColumnDef<'BLOB'> => ({ name: '', type: 'BLOB' }),
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Creates a fixed-length binary column definition
|
|
158
|
+
*/
|
|
159
|
+
binary: (length?: number): ColumnDef<'BINARY'> => ({
|
|
160
|
+
name: '',
|
|
161
|
+
type: 'BINARY',
|
|
162
|
+
args: length !== undefined ? [length] : undefined
|
|
163
|
+
}),
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Creates a variable-length binary column definition
|
|
167
|
+
*/
|
|
168
|
+
varbinary: (length?: number): ColumnDef<'VARBINARY'> => ({
|
|
169
|
+
name: '',
|
|
170
|
+
type: 'VARBINARY',
|
|
171
|
+
args: length !== undefined ? [length] : undefined
|
|
172
|
+
}),
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Creates a Postgres bytea column definition
|
|
176
|
+
*/
|
|
177
|
+
bytea: (): ColumnDef<'BYTEA'> => ({ name: '', type: 'BYTEA' }),
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Creates a timestamp column definition
|
|
181
|
+
*/
|
|
182
|
+
timestamp: (): ColumnDef<'TIMESTAMP'> => ({ name: '', type: 'TIMESTAMP' }),
|
|
147
183
|
|
|
148
184
|
/**
|
|
149
185
|
* Creates a timestamptz column definition
|
package/src/schema/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ColumnDef } from './column.js';
|
|
2
|
-
import { TableDef } from './table.js';
|
|
1
|
+
import { ColumnDef } from './column.js';
|
|
2
|
+
import { TableDef } from './table.js';
|
|
3
3
|
import {
|
|
4
4
|
RelationDef,
|
|
5
5
|
HasManyRelation,
|
|
@@ -7,16 +7,27 @@ import {
|
|
|
7
7
|
BelongsToRelation,
|
|
8
8
|
BelongsToManyRelation
|
|
9
9
|
} from './relation.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolves a relation definition to its target table type.
|
|
13
|
+
*/
|
|
14
|
+
export type RelationTargetTable<TRel extends RelationDef> =
|
|
15
|
+
TRel extends HasManyRelation<infer TTarget> ? TTarget :
|
|
16
|
+
TRel extends HasOneRelation<infer TTarget> ? TTarget :
|
|
17
|
+
TRel extends BelongsToRelation<infer TTarget> ? TTarget :
|
|
18
|
+
TRel extends BelongsToManyRelation<infer TTarget> ? TTarget :
|
|
19
|
+
never;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Maps a ColumnDef to its TypeScript type representation
|
|
23
|
+
*/
|
|
14
24
|
export type ColumnToTs<T extends ColumnDef> =
|
|
15
25
|
T['type'] extends 'INT' | 'INTEGER' | 'int' | 'integer' ? number :
|
|
16
26
|
T['type'] extends 'BIGINT' | 'bigint' ? number | bigint :
|
|
17
27
|
T['type'] extends 'DECIMAL' | 'decimal' | 'FLOAT' | 'float' | 'DOUBLE' | 'double' ? number :
|
|
18
28
|
T['type'] extends 'BOOLEAN' | 'boolean' ? boolean :
|
|
19
29
|
T['type'] extends 'JSON' | 'json' ? unknown :
|
|
30
|
+
T['type'] extends 'BLOB' | 'blob' | 'BINARY' | 'binary' | 'VARBINARY' | 'varbinary' | 'BYTEA' | 'bytea' ? Buffer :
|
|
20
31
|
T['type'] extends 'DATE' | 'date' | 'DATETIME' | 'datetime' | 'TIMESTAMP' | 'timestamp' | 'TIMESTAMPTZ' | 'timestamptz' ? string :
|
|
21
32
|
string;
|
|
22
33
|
|