metal-orm 1.1.9 → 1.1.10
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 +769 -764
- package/dist/index.cjs +2147 -239
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +559 -39
- package/dist/index.d.ts +559 -39
- package/dist/index.js +2119 -239
- package/dist/index.js.map +1 -1
- package/package.json +17 -12
- package/src/bulk/bulk-context.ts +83 -0
- package/src/bulk/bulk-delete-executor.ts +89 -0
- package/src/bulk/bulk-executor.base.ts +73 -0
- package/src/bulk/bulk-insert-executor.ts +74 -0
- package/src/bulk/bulk-types.ts +70 -0
- package/src/bulk/bulk-update-executor.ts +192 -0
- package/src/bulk/bulk-upsert-executor.ts +95 -0
- package/src/bulk/bulk-utils.ts +91 -0
- package/src/bulk/index.ts +18 -0
- package/src/codegen/typescript.ts +30 -21
- package/src/core/ast/expression-builders.ts +107 -10
- package/src/core/ast/expression-nodes.ts +52 -22
- package/src/core/ast/expression-visitor.ts +23 -13
- package/src/core/dialect/abstract.ts +30 -17
- package/src/core/dialect/mysql/index.ts +20 -5
- package/src/core/execution/db-executor.ts +96 -64
- package/src/core/execution/executors/better-sqlite3-executor.ts +94 -0
- package/src/core/execution/executors/mssql-executor.ts +66 -34
- package/src/core/execution/executors/mysql-executor.ts +98 -66
- package/src/core/execution/executors/postgres-executor.ts +33 -11
- package/src/core/execution/executors/sqlite-executor.ts +86 -30
- package/src/decorators/bootstrap.ts +482 -398
- package/src/decorators/column-decorator.ts +87 -96
- package/src/decorators/decorator-metadata.ts +100 -24
- package/src/decorators/entity.ts +27 -24
- package/src/decorators/relations.ts +231 -149
- package/src/decorators/transformers/transformer-decorators.ts +26 -29
- package/src/decorators/validators/country-validators-decorators.ts +9 -15
- package/src/dto/apply-filter.ts +568 -551
- package/src/index.ts +16 -9
- package/src/orm/entity-hydration.ts +116 -72
- package/src/orm/entity-metadata.ts +347 -301
- package/src/orm/entity-relations.ts +264 -207
- package/src/orm/entity.ts +199 -199
- package/src/orm/execute.ts +13 -13
- package/src/orm/lazy-batch/morph-many.ts +70 -0
- package/src/orm/lazy-batch/morph-one.ts +69 -0
- package/src/orm/lazy-batch/morph-to.ts +59 -0
- package/src/orm/lazy-batch.ts +4 -1
- package/src/orm/orm-session.ts +170 -104
- package/src/orm/pooled-executor-factory.ts +99 -58
- package/src/orm/query-logger.ts +49 -40
- package/src/orm/relation-change-processor.ts +198 -96
- package/src/orm/relations/belongs-to.ts +143 -143
- package/src/orm/relations/has-many.ts +204 -204
- package/src/orm/relations/has-one.ts +174 -174
- package/src/orm/relations/many-to-many.ts +288 -288
- package/src/orm/relations/morph-many.ts +156 -0
- package/src/orm/relations/morph-one.ts +151 -0
- package/src/orm/relations/morph-to.ts +162 -0
- package/src/orm/save-graph.ts +116 -1
- package/src/query-builder/expression-table-mapper.ts +5 -0
- package/src/query-builder/hydration-manager.ts +345 -345
- package/src/query-builder/hydration-planner.ts +178 -148
- package/src/query-builder/relation-conditions.ts +171 -151
- package/src/query-builder/relation-cte-builder.ts +5 -1
- package/src/query-builder/relation-filter-utils.ts +9 -6
- package/src/query-builder/relation-include-strategies.ts +44 -2
- package/src/query-builder/relation-join-strategies.ts +8 -1
- package/src/query-builder/relation-service.ts +250 -241
- package/src/query-builder/select/select-operations.ts +110 -105
- package/src/query-builder/update-include.ts +4 -0
- package/src/schema/relation.ts +296 -188
- package/src/schema/types.ts +138 -123
- package/src/tree/tree-decorator.ts +127 -137
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
// src/core/execution/executors/sqlite-executor.ts
|
|
2
|
-
import {
|
|
3
|
-
DbExecutor,
|
|
4
|
-
toExecutionPayload,
|
|
5
|
-
rowsToQueryResult
|
|
6
|
-
} from '../db-executor.js';
|
|
2
|
+
import {
|
|
3
|
+
DbExecutor,
|
|
4
|
+
toExecutionPayload,
|
|
5
|
+
rowsToQueryResult
|
|
6
|
+
} from '../db-executor.js';
|
|
7
7
|
|
|
8
|
-
export interface SqliteClientLike {
|
|
8
|
+
export interface SqliteClientLike {
|
|
9
9
|
all(
|
|
10
10
|
sql: string,
|
|
11
11
|
params?: unknown[]
|
|
12
12
|
): Promise<Array<Record<string, unknown>>>;
|
|
13
13
|
run?(sql: string, params?: unknown[]): Promise<unknown>;
|
|
14
|
-
beginTransaction?(): Promise<void>;
|
|
15
|
-
commitTransaction?(): Promise<void>;
|
|
16
|
-
rollbackTransaction?(): Promise<void>;
|
|
17
|
-
|
|
14
|
+
beginTransaction?(): Promise<void>;
|
|
15
|
+
commitTransaction?(): Promise<void>;
|
|
16
|
+
rollbackTransaction?(): Promise<void>;
|
|
17
|
+
savepoint?(name: string): Promise<void>;
|
|
18
|
+
releaseSavepoint?(name: string): Promise<void>;
|
|
19
|
+
rollbackToSavepoint?(name: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const SAVEPOINT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
23
|
+
|
|
24
|
+
const sanitizeSavepointName = (name: string): string => {
|
|
25
|
+
const trimmed = name.trim();
|
|
26
|
+
if (!SAVEPOINT_NAME_PATTERN.test(trimmed)) {
|
|
27
|
+
throw new Error(`Invalid savepoint name: "${name}"`);
|
|
28
|
+
}
|
|
29
|
+
return trimmed;
|
|
30
|
+
};
|
|
18
31
|
|
|
19
32
|
/**
|
|
20
33
|
* Creates a database executor for SQLite.
|
|
@@ -24,20 +37,30 @@ export interface SqliteClientLike {
|
|
|
24
37
|
export function createSqliteExecutor(
|
|
25
38
|
client: SqliteClientLike
|
|
26
39
|
): DbExecutor {
|
|
27
|
-
const supportsTransactions =
|
|
28
|
-
typeof client.beginTransaction === 'function' &&
|
|
29
|
-
typeof client.commitTransaction === 'function' &&
|
|
30
|
-
typeof client.rollbackTransaction === 'function';
|
|
40
|
+
const supportsTransactions =
|
|
41
|
+
typeof client.beginTransaction === 'function' &&
|
|
42
|
+
typeof client.commitTransaction === 'function' &&
|
|
43
|
+
typeof client.rollbackTransaction === 'function';
|
|
44
|
+
const supportsSavepoints = supportsTransactions;
|
|
45
|
+
|
|
46
|
+
const executeControlStatement = async (sql: string): Promise<void> => {
|
|
47
|
+
if (typeof client.run === 'function') {
|
|
48
|
+
await client.run(sql);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
await client.all(sql);
|
|
52
|
+
};
|
|
31
53
|
|
|
32
54
|
return {
|
|
33
|
-
capabilities: {
|
|
34
|
-
transactions: supportsTransactions,
|
|
35
|
-
|
|
36
|
-
async executeSql(sql, params) {
|
|
37
|
-
const rows = await client.all(sql, params);
|
|
38
|
-
const result = rowsToQueryResult(rows);
|
|
39
|
-
return toExecutionPayload([result]);
|
|
55
|
+
capabilities: {
|
|
56
|
+
transactions: supportsTransactions,
|
|
57
|
+
...(supportsSavepoints ? { savepoints: true } : {}),
|
|
40
58
|
},
|
|
59
|
+
async executeSql(sql, params) {
|
|
60
|
+
const rows = await client.all(sql, params);
|
|
61
|
+
const result = rowsToQueryResult(rows);
|
|
62
|
+
return toExecutionPayload([result]);
|
|
63
|
+
},
|
|
41
64
|
async beginTransaction() {
|
|
42
65
|
if (!supportsTransactions) {
|
|
43
66
|
throw new Error('Transactions are not supported by this executor');
|
|
@@ -50,14 +73,47 @@ export function createSqliteExecutor(
|
|
|
50
73
|
}
|
|
51
74
|
await client.commitTransaction!();
|
|
52
75
|
},
|
|
53
|
-
async rollbackTransaction() {
|
|
54
|
-
if (!supportsTransactions) {
|
|
55
|
-
throw new Error('Transactions are not supported by this executor');
|
|
56
|
-
}
|
|
57
|
-
await client.rollbackTransaction!();
|
|
58
|
-
},
|
|
59
|
-
async
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
async rollbackTransaction() {
|
|
77
|
+
if (!supportsTransactions) {
|
|
78
|
+
throw new Error('Transactions are not supported by this executor');
|
|
79
|
+
}
|
|
80
|
+
await client.rollbackTransaction!();
|
|
81
|
+
},
|
|
82
|
+
async savepoint(name: string) {
|
|
83
|
+
if (!supportsSavepoints) {
|
|
84
|
+
throw new Error('Savepoints are not supported by this executor');
|
|
85
|
+
}
|
|
86
|
+
const savepoint = sanitizeSavepointName(name);
|
|
87
|
+
if (typeof client.savepoint === 'function') {
|
|
88
|
+
await client.savepoint(savepoint);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
await executeControlStatement(`SAVEPOINT ${savepoint}`);
|
|
92
|
+
},
|
|
93
|
+
async releaseSavepoint(name: string) {
|
|
94
|
+
if (!supportsSavepoints) {
|
|
95
|
+
throw new Error('Savepoints are not supported by this executor');
|
|
96
|
+
}
|
|
97
|
+
const savepoint = sanitizeSavepointName(name);
|
|
98
|
+
if (typeof client.releaseSavepoint === 'function') {
|
|
99
|
+
await client.releaseSavepoint(savepoint);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
await executeControlStatement(`RELEASE SAVEPOINT ${savepoint}`);
|
|
103
|
+
},
|
|
104
|
+
async rollbackToSavepoint(name: string) {
|
|
105
|
+
if (!supportsSavepoints) {
|
|
106
|
+
throw new Error('Savepoints are not supported by this executor');
|
|
107
|
+
}
|
|
108
|
+
const savepoint = sanitizeSavepointName(name);
|
|
109
|
+
if (typeof client.rollbackToSavepoint === 'function') {
|
|
110
|
+
await client.rollbackToSavepoint(savepoint);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
await executeControlStatement(`ROLLBACK TO SAVEPOINT ${savepoint}`);
|
|
114
|
+
},
|
|
115
|
+
async dispose() {
|
|
116
|
+
// Connection lifecycle is owned by the caller/driver. Pool lease executors should implement dispose.
|
|
117
|
+
},
|
|
62
118
|
};
|
|
63
119
|
}
|