metal-orm 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -82
- package/dist/decorators/index.cjs +1600 -27
- package/dist/decorators/index.cjs.map +1 -1
- package/dist/decorators/index.d.cts +6 -2
- package/dist/decorators/index.d.ts +6 -2
- package/dist/decorators/index.js +1599 -27
- package/dist/decorators/index.js.map +1 -1
- package/dist/index.cjs +4608 -3429
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +511 -159
- package/dist/index.d.ts +511 -159
- package/dist/index.js +4526 -3415
- package/dist/index.js.map +1 -1
- package/dist/{select-CCp1oz9p.d.cts → select-Bkv8g8u_.d.cts} +193 -67
- package/dist/{select-CCp1oz9p.d.ts → select-Bkv8g8u_.d.ts} +193 -67
- package/package.json +1 -1
- package/src/codegen/typescript.ts +38 -35
- package/src/core/ast/adapters.ts +21 -0
- package/src/core/ast/aggregate-functions.ts +13 -13
- package/src/core/ast/builders.ts +56 -43
- package/src/core/ast/expression-builders.ts +34 -34
- package/src/core/ast/expression-nodes.ts +18 -16
- package/src/core/ast/expression-visitor.ts +122 -69
- package/src/core/ast/expression.ts +6 -4
- package/src/core/ast/join-metadata.ts +15 -0
- package/src/core/ast/join-node.ts +22 -20
- package/src/core/ast/join.ts +5 -5
- package/src/core/ast/query.ts +52 -88
- package/src/core/ast/types.ts +20 -0
- package/src/core/ast/window-functions.ts +55 -55
- package/src/core/ddl/dialects/base-schema-dialect.ts +20 -6
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +32 -8
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +21 -10
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +52 -7
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +23 -9
- package/src/core/ddl/introspect/catalogs/index.ts +1 -0
- package/src/core/ddl/introspect/catalogs/postgres.ts +143 -0
- package/src/core/ddl/introspect/context.ts +9 -0
- package/src/core/ddl/introspect/functions/postgres.ts +26 -0
- package/src/core/ddl/introspect/mssql.ts +149 -149
- package/src/core/ddl/introspect/mysql.ts +99 -99
- package/src/core/ddl/introspect/postgres.ts +245 -154
- package/src/core/ddl/introspect/registry.ts +26 -0
- package/src/core/ddl/introspect/run-select.ts +25 -0
- package/src/core/ddl/introspect/sqlite.ts +7 -7
- package/src/core/ddl/introspect/types.ts +23 -19
- package/src/core/ddl/introspect/utils.ts +1 -1
- package/src/core/ddl/naming-strategy.ts +10 -0
- package/src/core/ddl/schema-dialect.ts +41 -0
- package/src/core/ddl/schema-diff.ts +211 -179
- package/src/core/ddl/schema-generator.ts +16 -90
- package/src/core/ddl/schema-introspect.ts +25 -32
- package/src/core/ddl/schema-plan-executor.ts +17 -0
- package/src/core/ddl/schema-types.ts +46 -39
- package/src/core/ddl/sql-writing.ts +170 -0
- package/src/core/dialect/abstract.ts +144 -126
- package/src/core/dialect/base/cte-compiler.ts +33 -0
- package/src/core/dialect/base/function-table-formatter.ts +132 -0
- package/src/core/dialect/base/groupby-compiler.ts +21 -0
- package/src/core/dialect/base/join-compiler.ts +26 -0
- package/src/core/dialect/base/orderby-compiler.ts +21 -0
- package/src/core/dialect/base/pagination-strategy.ts +32 -0
- package/src/core/dialect/base/returning-strategy.ts +56 -0
- package/src/core/dialect/base/sql-dialect.ts +181 -204
- package/src/core/dialect/dialect-factory.ts +91 -0
- package/src/core/dialect/mssql/functions.ts +101 -0
- package/src/core/dialect/mssql/index.ts +128 -126
- package/src/core/dialect/mysql/functions.ts +101 -0
- package/src/core/dialect/mysql/index.ts +20 -18
- package/src/core/dialect/postgres/functions.ts +95 -0
- package/src/core/dialect/postgres/index.ts +30 -28
- package/src/core/dialect/sqlite/functions.ts +115 -0
- package/src/core/dialect/sqlite/index.ts +30 -28
- package/src/core/driver/database-driver.ts +11 -0
- package/src/core/driver/mssql-driver.ts +20 -0
- package/src/core/driver/mysql-driver.ts +20 -0
- package/src/core/driver/postgres-driver.ts +20 -0
- package/src/core/driver/sqlite-driver.ts +20 -0
- package/src/core/execution/db-executor.ts +63 -0
- package/src/core/execution/executors/mssql-executor.ts +39 -0
- package/src/core/execution/executors/mysql-executor.ts +47 -0
- package/src/core/execution/executors/postgres-executor.ts +32 -0
- package/src/core/execution/executors/sqlite-executor.ts +31 -0
- package/src/core/functions/datetime.ts +132 -0
- package/src/core/functions/numeric.ts +179 -0
- package/src/core/functions/standard-strategy.ts +47 -0
- package/src/core/functions/text.ts +147 -0
- package/src/core/functions/types.ts +18 -0
- package/src/core/hydration/types.ts +57 -0
- package/src/decorators/bootstrap.ts +10 -0
- package/src/decorators/relations.ts +15 -0
- package/src/index.ts +30 -19
- package/src/orm/entity-metadata.ts +7 -0
- package/src/orm/entity.ts +58 -27
- package/src/orm/hydration.ts +25 -17
- package/src/orm/lazy-batch.ts +46 -2
- package/src/orm/orm-context.ts +60 -60
- package/src/orm/query-logger.ts +1 -1
- package/src/orm/relation-change-processor.ts +43 -2
- package/src/orm/relations/has-one.ts +139 -0
- package/src/orm/transaction-runner.ts +1 -1
- package/src/orm/unit-of-work.ts +60 -60
- package/src/query-builder/delete.ts +22 -5
- package/src/query-builder/hydration-manager.ts +2 -1
- package/src/query-builder/hydration-planner.ts +8 -7
- package/src/query-builder/insert.ts +22 -5
- package/src/query-builder/relation-conditions.ts +9 -8
- package/src/query-builder/relation-service.ts +3 -2
- package/src/query-builder/select.ts +66 -61
- package/src/query-builder/update.ts +22 -5
- package/src/schema/column.ts +246 -246
- package/src/schema/relation.ts +35 -1
- package/src/schema/table.ts +28 -28
- package/src/schema/types.ts +41 -31
- package/src/orm/db-executor.ts +0 -11
package/src/schema/types.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ColumnDef } from './column.js';
|
|
2
2
|
import { TableDef } from './table.js';
|
|
3
|
-
import {
|
|
4
|
-
RelationDef,
|
|
5
|
-
HasManyRelation,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import {
|
|
4
|
+
RelationDef,
|
|
5
|
+
HasManyRelation,
|
|
6
|
+
HasOneRelation,
|
|
7
|
+
BelongsToRelation,
|
|
8
|
+
BelongsToManyRelation
|
|
9
|
+
} from './relation.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Maps a ColumnDef to its TypeScript type representation
|
|
@@ -26,11 +27,12 @@ export type InferRow<TTable extends TableDef> = {
|
|
|
26
27
|
[K in keyof TTable['columns']]: ColumnToTs<TTable['columns'][K]>;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
|
-
type RelationResult<T extends RelationDef> =
|
|
30
|
-
T extends HasManyRelation<infer TTarget> ? InferRow<TTarget>[] :
|
|
31
|
-
T extends
|
|
32
|
-
T extends
|
|
33
|
-
|
|
30
|
+
type RelationResult<T extends RelationDef> =
|
|
31
|
+
T extends HasManyRelation<infer TTarget> ? InferRow<TTarget>[] :
|
|
32
|
+
T extends HasOneRelation<infer TTarget> ? InferRow<TTarget> | null :
|
|
33
|
+
T extends BelongsToRelation<infer TTarget> ? InferRow<TTarget> | null :
|
|
34
|
+
T extends BelongsToManyRelation<infer TTarget> ? (InferRow<TTarget> & { _pivot?: any })[] :
|
|
35
|
+
never;
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* Maps relation names to the expected row results
|
|
@@ -48,11 +50,17 @@ export interface HasManyCollection<TChild> {
|
|
|
48
50
|
clear(): void;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
export interface BelongsToReference<TParent> {
|
|
52
|
-
load(): Promise<TParent | null>;
|
|
53
|
-
get(): TParent | null;
|
|
54
|
-
set(data: Partial<TParent> | TParent | null): TParent | null;
|
|
55
|
-
}
|
|
53
|
+
export interface BelongsToReference<TParent> {
|
|
54
|
+
load(): Promise<TParent | null>;
|
|
55
|
+
get(): TParent | null;
|
|
56
|
+
set(data: Partial<TParent> | TParent | null): TParent | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface HasOneReference<TChild> {
|
|
60
|
+
load(): Promise<TChild | null>;
|
|
61
|
+
get(): TChild | null;
|
|
62
|
+
set(data: Partial<TChild> | TChild | null): TChild | null;
|
|
63
|
+
}
|
|
56
64
|
|
|
57
65
|
export interface ManyToManyCollection<TTarget> {
|
|
58
66
|
load(): Promise<TTarget[]>;
|
|
@@ -62,18 +70,20 @@ export interface ManyToManyCollection<TTarget> {
|
|
|
62
70
|
syncByIds(ids: (number | string)[]): Promise<void>;
|
|
63
71
|
}
|
|
64
72
|
|
|
65
|
-
export type Entity<
|
|
66
|
-
TTable extends TableDef,
|
|
67
|
-
TRow = InferRow<TTable>
|
|
68
|
-
> = TRow & {
|
|
69
|
-
[K in keyof RelationMap<TTable>]:
|
|
70
|
-
TTable['relations'][K] extends HasManyRelation<infer TTarget>
|
|
71
|
-
? HasManyCollection<Entity<TTarget>>
|
|
72
|
-
: TTable['relations'][K] extends
|
|
73
|
-
?
|
|
74
|
-
: TTable['relations'][K] extends
|
|
75
|
-
?
|
|
76
|
-
:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
73
|
+
export type Entity<
|
|
74
|
+
TTable extends TableDef,
|
|
75
|
+
TRow = InferRow<TTable>
|
|
76
|
+
> = TRow & {
|
|
77
|
+
[K in keyof RelationMap<TTable>]:
|
|
78
|
+
TTable['relations'][K] extends HasManyRelation<infer TTarget>
|
|
79
|
+
? HasManyCollection<Entity<TTarget>>
|
|
80
|
+
: TTable['relations'][K] extends HasOneRelation<infer TTarget>
|
|
81
|
+
? HasOneReference<Entity<TTarget>>
|
|
82
|
+
: TTable['relations'][K] extends BelongsToManyRelation<infer TTarget>
|
|
83
|
+
? ManyToManyCollection<Entity<TTarget>>
|
|
84
|
+
: TTable['relations'][K] extends BelongsToRelation<infer TTarget>
|
|
85
|
+
? BelongsToReference<Entity<TTarget>>
|
|
86
|
+
: never;
|
|
87
|
+
} & {
|
|
88
|
+
$load<K extends keyof RelationMap<TTable>>(relation: K): Promise<RelationMap<TTable>[K]>;
|
|
89
|
+
};
|
package/src/orm/db-executor.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type QueryResult = {
|
|
2
|
-
columns: string[];
|
|
3
|
-
values: unknown[][];
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export interface DbExecutor {
|
|
7
|
-
executeSql(sql: string, params?: unknown[]): Promise<QueryResult[]>;
|
|
8
|
-
beginTransaction?(): Promise<void>;
|
|
9
|
-
commitTransaction?(): Promise<void>;
|
|
10
|
-
rollbackTransaction?(): Promise<void>;
|
|
11
|
-
}
|