@mikro-orm/sql 7.0.3-dev.8 → 7.0.3
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/AbstractSqlConnection.d.ts +94 -58
- package/AbstractSqlConnection.js +235 -238
- package/AbstractSqlDriver.d.ts +410 -155
- package/AbstractSqlDriver.js +2064 -1937
- package/AbstractSqlPlatform.d.ts +83 -73
- package/AbstractSqlPlatform.js +162 -158
- package/PivotCollectionPersister.d.ts +33 -15
- package/PivotCollectionPersister.js +158 -160
- package/README.md +2 -2
- package/SqlEntityManager.d.ts +67 -22
- package/SqlEntityManager.js +54 -38
- package/SqlEntityRepository.d.ts +14 -14
- package/SqlEntityRepository.js +23 -23
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +12 -12
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +192 -194
- package/dialects/mysql/BaseMySqlPlatform.d.ts +64 -45
- package/dialects/mysql/BaseMySqlPlatform.js +134 -131
- package/dialects/mysql/MySqlExceptionConverter.d.ts +6 -6
- package/dialects/mysql/MySqlExceptionConverter.js +91 -77
- package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +3 -3
- package/dialects/mysql/MySqlNativeQueryBuilder.js +66 -69
- package/dialects/mysql/MySqlSchemaHelper.d.ts +39 -39
- package/dialects/mysql/MySqlSchemaHelper.js +327 -319
- package/dialects/oracledb/OracleDialect.d.ts +81 -52
- package/dialects/oracledb/OracleDialect.js +155 -149
- package/dialects/oracledb/OracleNativeQueryBuilder.d.ts +12 -12
- package/dialects/oracledb/OracleNativeQueryBuilder.js +232 -236
- package/dialects/postgresql/BasePostgreSqlPlatform.d.ts +108 -105
- package/dialects/postgresql/BasePostgreSqlPlatform.js +351 -350
- package/dialects/postgresql/FullTextType.d.ts +10 -6
- package/dialects/postgresql/FullTextType.js +51 -51
- package/dialects/postgresql/PostgreSqlExceptionConverter.d.ts +5 -5
- package/dialects/postgresql/PostgreSqlExceptionConverter.js +55 -43
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +4 -4
- package/dialects/postgresql/PostgreSqlSchemaHelper.d.ts +102 -82
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +733 -683
- package/dialects/sqlite/BaseSqliteConnection.d.ts +3 -5
- package/dialects/sqlite/BaseSqliteConnection.js +21 -19
- package/dialects/sqlite/NodeSqliteDialect.d.ts +1 -1
- package/dialects/sqlite/NodeSqliteDialect.js +23 -23
- package/dialects/sqlite/SqliteDriver.d.ts +1 -1
- package/dialects/sqlite/SqliteDriver.js +3 -3
- package/dialects/sqlite/SqliteExceptionConverter.d.ts +6 -6
- package/dialects/sqlite/SqliteExceptionConverter.js +67 -51
- package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +2 -2
- package/dialects/sqlite/SqliteNativeQueryBuilder.js +7 -7
- package/dialects/sqlite/SqlitePlatform.d.ts +63 -72
- package/dialects/sqlite/SqlitePlatform.js +139 -139
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +70 -60
- package/dialects/sqlite/SqliteSchemaHelper.js +533 -520
- package/package.json +3 -3
- package/plugin/index.d.ts +42 -35
- package/plugin/index.js +43 -36
- package/plugin/transformer.d.ts +117 -94
- package/plugin/transformer.js +890 -881
- package/query/ArrayCriteriaNode.d.ts +4 -4
- package/query/ArrayCriteriaNode.js +18 -18
- package/query/CriteriaNode.d.ts +35 -25
- package/query/CriteriaNode.js +133 -123
- package/query/CriteriaNodeFactory.d.ts +49 -6
- package/query/CriteriaNodeFactory.js +97 -94
- package/query/NativeQueryBuilder.d.ts +118 -118
- package/query/NativeQueryBuilder.js +484 -480
- package/query/ObjectCriteriaNode.d.ts +12 -12
- package/query/ObjectCriteriaNode.js +298 -282
- package/query/QueryBuilder.d.ts +1546 -904
- package/query/QueryBuilder.js +2294 -2144
- package/query/QueryBuilderHelper.d.ts +153 -72
- package/query/QueryBuilderHelper.js +1079 -1028
- package/query/ScalarCriteriaNode.d.ts +3 -3
- package/query/ScalarCriteriaNode.js +53 -46
- package/query/enums.d.ts +14 -14
- package/query/enums.js +14 -14
- package/query/raw.d.ts +16 -6
- package/query/raw.js +10 -10
- package/schema/DatabaseSchema.d.ts +73 -50
- package/schema/DatabaseSchema.js +331 -307
- package/schema/DatabaseTable.d.ts +96 -73
- package/schema/DatabaseTable.js +1012 -927
- package/schema/SchemaComparator.d.ts +70 -66
- package/schema/SchemaComparator.js +766 -740
- package/schema/SchemaHelper.d.ts +109 -95
- package/schema/SchemaHelper.js +675 -659
- package/schema/SqlSchemaGenerator.d.ts +78 -58
- package/schema/SqlSchemaGenerator.js +535 -501
- package/typings.d.ts +380 -266
|
@@ -1,177 +1,175 @@
|
|
|
1
1
|
class InsertStatement {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
order;
|
|
3
|
+
#keys;
|
|
4
|
+
#data;
|
|
5
|
+
constructor(keys, data, order) {
|
|
6
|
+
this.order = order;
|
|
7
|
+
this.#keys = keys;
|
|
8
|
+
this.#data = data;
|
|
9
|
+
}
|
|
10
|
+
getHash() {
|
|
11
|
+
return JSON.stringify(this.#data);
|
|
12
|
+
}
|
|
13
|
+
getData() {
|
|
14
|
+
const data = {};
|
|
15
|
+
this.#keys.forEach((key, idx) => (data[key] = this.#data[idx]));
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
19
|
class DeleteStatement {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
#keys;
|
|
21
|
+
#cond;
|
|
22
|
+
constructor(keys, cond) {
|
|
23
|
+
this.#keys = keys;
|
|
24
|
+
this.#cond = cond;
|
|
25
|
+
}
|
|
26
|
+
getHash() {
|
|
27
|
+
return JSON.stringify(this.#cond);
|
|
28
|
+
}
|
|
29
|
+
getCondition() {
|
|
30
|
+
const cond = {};
|
|
31
|
+
this.#keys.forEach((key, idx) => (cond[key] = this.#cond[idx]));
|
|
32
|
+
return cond;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class PivotCollectionPersister {
|
|
36
|
+
#inserts = new Map();
|
|
37
|
+
#upserts = new Map();
|
|
38
|
+
#deletes = new Map();
|
|
39
|
+
#batchSize;
|
|
40
|
+
#order = 0;
|
|
41
|
+
#meta;
|
|
42
|
+
#driver;
|
|
43
|
+
#ctx;
|
|
44
|
+
#schema;
|
|
45
|
+
#loggerContext;
|
|
46
|
+
constructor(meta, driver, ctx, schema, loggerContext) {
|
|
47
|
+
this.#meta = meta;
|
|
48
|
+
this.#driver = driver;
|
|
49
|
+
this.#ctx = ctx;
|
|
50
|
+
this.#schema = schema;
|
|
51
|
+
this.#loggerContext = loggerContext;
|
|
52
|
+
this.#batchSize = this.#driver.config.get('batchSize');
|
|
53
|
+
}
|
|
54
|
+
enqueueUpdate(prop, insertDiff, deleteDiff, pks, isInitialized = true) {
|
|
55
|
+
if (insertDiff.length) {
|
|
56
|
+
if (isInitialized) {
|
|
57
|
+
this.enqueueInsert(prop, insertDiff, pks);
|
|
58
|
+
} else {
|
|
59
|
+
this.enqueueUpsert(prop, insertDiff, pks);
|
|
60
|
+
}
|
|
25
61
|
}
|
|
26
|
-
|
|
27
|
-
|
|
62
|
+
if (deleteDiff === true || (Array.isArray(deleteDiff) && deleteDiff.length)) {
|
|
63
|
+
this.enqueueDelete(prop, deleteDiff, pks);
|
|
28
64
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
65
|
+
}
|
|
66
|
+
enqueueInsert(prop, insertDiff, pks) {
|
|
67
|
+
for (const fks of insertDiff) {
|
|
68
|
+
const statement = this.createInsertStatement(prop, fks, pks);
|
|
69
|
+
const hash = statement.getHash();
|
|
70
|
+
if (prop.owner || !this.#inserts.has(hash)) {
|
|
71
|
+
this.#inserts.set(hash, statement);
|
|
72
|
+
}
|
|
33
73
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
#driver;
|
|
43
|
-
#ctx;
|
|
44
|
-
#schema;
|
|
45
|
-
#loggerContext;
|
|
46
|
-
constructor(meta, driver, ctx, schema, loggerContext) {
|
|
47
|
-
this.#meta = meta;
|
|
48
|
-
this.#driver = driver;
|
|
49
|
-
this.#ctx = ctx;
|
|
50
|
-
this.#schema = schema;
|
|
51
|
-
this.#loggerContext = loggerContext;
|
|
52
|
-
this.#batchSize = this.#driver.config.get('batchSize');
|
|
74
|
+
}
|
|
75
|
+
enqueueUpsert(prop, insertDiff, pks) {
|
|
76
|
+
for (const fks of insertDiff) {
|
|
77
|
+
const statement = this.createInsertStatement(prop, fks, pks);
|
|
78
|
+
const hash = statement.getHash();
|
|
79
|
+
if (prop.owner || !this.#upserts.has(hash)) {
|
|
80
|
+
this.#upserts.set(hash, statement);
|
|
81
|
+
}
|
|
53
82
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
83
|
+
}
|
|
84
|
+
createInsertStatement(prop, fks, pks) {
|
|
85
|
+
const { data, keys } = this.buildPivotKeysAndData(prop, fks, pks);
|
|
86
|
+
return new InsertStatement(keys, data, this.#order++);
|
|
87
|
+
}
|
|
88
|
+
enqueueDelete(prop, deleteDiff, pks) {
|
|
89
|
+
if (deleteDiff === true) {
|
|
90
|
+
const { data, keys } = this.buildPivotKeysAndData(prop, [], pks, true);
|
|
91
|
+
const statement = new DeleteStatement(keys, data);
|
|
92
|
+
this.#deletes.set(statement.getHash(), statement);
|
|
93
|
+
return;
|
|
66
94
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (prop.owner || !this.#inserts.has(hash)) {
|
|
72
|
-
this.#inserts.set(hash, statement);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
95
|
+
for (const fks of deleteDiff) {
|
|
96
|
+
const { data, keys } = this.buildPivotKeysAndData(prop, fks, pks);
|
|
97
|
+
const statement = new DeleteStatement(keys, data);
|
|
98
|
+
this.#deletes.set(statement.getHash(), statement);
|
|
75
99
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build the keys and data arrays for pivot table operations.
|
|
103
|
+
* Handles polymorphic M:N by prepending the discriminator column/value.
|
|
104
|
+
*/
|
|
105
|
+
buildPivotKeysAndData(prop, fks, pks, deleteAll = false) {
|
|
106
|
+
let data;
|
|
107
|
+
let keys;
|
|
108
|
+
if (deleteAll) {
|
|
109
|
+
data = pks;
|
|
110
|
+
keys = prop.joinColumns;
|
|
111
|
+
} else {
|
|
112
|
+
data = prop.owner ? [...fks, ...pks] : [...pks, ...fks];
|
|
113
|
+
keys = prop.owner
|
|
114
|
+
? [...prop.inverseJoinColumns, ...prop.joinColumns]
|
|
115
|
+
: [...prop.joinColumns, ...prop.inverseJoinColumns];
|
|
84
116
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
117
|
+
if (prop.polymorphic && prop.discriminatorColumn && prop.discriminatorValue) {
|
|
118
|
+
data = [prop.discriminatorValue, ...data];
|
|
119
|
+
keys = [prop.discriminatorColumn, ...keys];
|
|
88
120
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
for (const fks of deleteDiff) {
|
|
97
|
-
const { data, keys } = this.buildPivotKeysAndData(prop, fks, pks);
|
|
98
|
-
const statement = new DeleteStatement(keys, data);
|
|
99
|
-
this.#deletes.set(statement.getHash(), statement);
|
|
100
|
-
}
|
|
121
|
+
return { data, keys };
|
|
122
|
+
}
|
|
123
|
+
collectStatements(statements) {
|
|
124
|
+
const items = [];
|
|
125
|
+
for (const statement of statements.values()) {
|
|
126
|
+
items[statement.order] = statement.getData();
|
|
101
127
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
data = prop.owner ? [...fks, ...pks] : [...pks, ...fks];
|
|
115
|
-
keys = prop.owner
|
|
116
|
-
? [...prop.inverseJoinColumns, ...prop.joinColumns]
|
|
117
|
-
: [...prop.joinColumns, ...prop.inverseJoinColumns];
|
|
118
|
-
}
|
|
119
|
-
if (prop.polymorphic && prop.discriminatorColumn && prop.discriminatorValue) {
|
|
120
|
-
data = [prop.discriminatorValue, ...data];
|
|
121
|
-
keys = [prop.discriminatorColumn, ...keys];
|
|
128
|
+
return items.filter(Boolean);
|
|
129
|
+
}
|
|
130
|
+
async execute() {
|
|
131
|
+
if (this.#deletes.size > 0) {
|
|
132
|
+
const deletes = [...this.#deletes.values()];
|
|
133
|
+
for (let i = 0; i < deletes.length; i += this.#batchSize) {
|
|
134
|
+
const chunk = deletes.slice(i, i + this.#batchSize);
|
|
135
|
+
const cond = { $or: [] };
|
|
136
|
+
for (const item of chunk) {
|
|
137
|
+
cond.$or.push(item.getCondition());
|
|
122
138
|
}
|
|
123
|
-
|
|
139
|
+
await this.#driver.nativeDelete(this.#meta.class, cond, {
|
|
140
|
+
ctx: this.#ctx,
|
|
141
|
+
schema: this.#schema,
|
|
142
|
+
loggerContext: this.#loggerContext,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
124
145
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
146
|
+
if (this.#inserts.size > 0) {
|
|
147
|
+
const filtered = this.collectStatements(this.#inserts);
|
|
148
|
+
for (let i = 0; i < filtered.length; i += this.#batchSize) {
|
|
149
|
+
const chunk = filtered.slice(i, i + this.#batchSize);
|
|
150
|
+
await this.#driver.nativeInsertMany(this.#meta.class, chunk, {
|
|
151
|
+
ctx: this.#ctx,
|
|
152
|
+
schema: this.#schema,
|
|
153
|
+
convertCustomTypes: false,
|
|
154
|
+
processCollections: false,
|
|
155
|
+
loggerContext: this.#loggerContext,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
131
158
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (this.#inserts.size > 0) {
|
|
149
|
-
const filtered = this.collectStatements(this.#inserts);
|
|
150
|
-
for (let i = 0; i < filtered.length; i += this.#batchSize) {
|
|
151
|
-
const chunk = filtered.slice(i, i + this.#batchSize);
|
|
152
|
-
await this.#driver.nativeInsertMany(this.#meta.class, chunk, {
|
|
153
|
-
ctx: this.#ctx,
|
|
154
|
-
schema: this.#schema,
|
|
155
|
-
convertCustomTypes: false,
|
|
156
|
-
processCollections: false,
|
|
157
|
-
loggerContext: this.#loggerContext,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (this.#upserts.size > 0) {
|
|
162
|
-
const filtered = this.collectStatements(this.#upserts);
|
|
163
|
-
for (let i = 0; i < filtered.length; i += this.#batchSize) {
|
|
164
|
-
const chunk = filtered.slice(i, i + this.#batchSize);
|
|
165
|
-
await this.#driver.nativeUpdateMany(this.#meta.class, [], chunk, {
|
|
166
|
-
ctx: this.#ctx,
|
|
167
|
-
schema: this.#schema,
|
|
168
|
-
convertCustomTypes: false,
|
|
169
|
-
processCollections: false,
|
|
170
|
-
upsert: true,
|
|
171
|
-
onConflictAction: 'ignore',
|
|
172
|
-
loggerContext: this.#loggerContext,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
159
|
+
if (this.#upserts.size > 0) {
|
|
160
|
+
const filtered = this.collectStatements(this.#upserts);
|
|
161
|
+
for (let i = 0; i < filtered.length; i += this.#batchSize) {
|
|
162
|
+
const chunk = filtered.slice(i, i + this.#batchSize);
|
|
163
|
+
await this.#driver.nativeUpdateMany(this.#meta.class, [], chunk, {
|
|
164
|
+
ctx: this.#ctx,
|
|
165
|
+
schema: this.#schema,
|
|
166
|
+
convertCustomTypes: false,
|
|
167
|
+
processCollections: false,
|
|
168
|
+
upsert: true,
|
|
169
|
+
onConflictAction: 'ignore',
|
|
170
|
+
loggerContext: this.#loggerContext,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
176
173
|
}
|
|
174
|
+
}
|
|
177
175
|
}
|
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ export class Book extends BookSchema.class {}
|
|
|
64
64
|
BookSchema.setClass(Book);
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
You can also define entities using [decorators](https://mikro-orm.io/docs/
|
|
67
|
+
You can also define entities using [decorators](https://mikro-orm.io/docs/using-decorators) or [`EntitySchema`](https://mikro-orm.io/docs/define-entity#entityschema-low-level-api). See the [defining entities guide](https://mikro-orm.io/docs/defining-entities) for all options.
|
|
68
68
|
|
|
69
69
|
### Initialize and Use
|
|
70
70
|
|
|
@@ -133,7 +133,7 @@ const author = await em.findOneOrFail(Author, 1, {
|
|
|
133
133
|
populate: ['books'],
|
|
134
134
|
});
|
|
135
135
|
author.name = 'Jon Snow II';
|
|
136
|
-
author.books.getItems().forEach(book => book.title += ' (2nd ed.)');
|
|
136
|
+
author.books.getItems().forEach(book => (book.title += ' (2nd ed.)'));
|
|
137
137
|
author.books.add(orm.em.create(Book, { title: 'New Book', author }));
|
|
138
138
|
|
|
139
139
|
// Flush computes change sets and executes them in a single transaction
|
package/SqlEntityManager.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type EntitySchemaWithMeta,
|
|
3
|
+
EntityManager,
|
|
4
|
+
type AnyEntity,
|
|
5
|
+
type ConnectionType,
|
|
6
|
+
type EntityData,
|
|
7
|
+
type EntityName,
|
|
8
|
+
type EntityRepository,
|
|
9
|
+
type GetRepository,
|
|
10
|
+
type QueryResult,
|
|
11
|
+
type FilterQuery,
|
|
12
|
+
type LoggingOptions,
|
|
13
|
+
type RawQueryFragment,
|
|
14
|
+
} from '@mikro-orm/core';
|
|
2
15
|
import type { AbstractSqlDriver } from './AbstractSqlDriver.js';
|
|
3
16
|
import type { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
4
17
|
import type { QueryBuilder } from './query/QueryBuilder.js';
|
|
@@ -8,30 +21,62 @@ import type { InferClassEntityDB, InferKyselyDB } from './typings.js';
|
|
|
8
21
|
import { type MikroKyselyPluginOptions } from './plugin/index.js';
|
|
9
22
|
/** Options for `SqlEntityManager.getKysely()`. */
|
|
10
23
|
export interface GetKyselyOptions extends MikroKyselyPluginOptions {
|
|
11
|
-
|
|
12
|
-
|
|
24
|
+
/** Connection type to use (`'read'` or `'write'`). */
|
|
25
|
+
type?: ConnectionType;
|
|
13
26
|
}
|
|
14
27
|
/**
|
|
15
28
|
* @inheritDoc
|
|
16
29
|
*/
|
|
17
|
-
export declare class SqlEntityManager<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
export declare class SqlEntityManager<
|
|
31
|
+
Driver extends AbstractSqlDriver = AbstractSqlDriver,
|
|
32
|
+
> extends EntityManager<Driver> {
|
|
33
|
+
/**
|
|
34
|
+
* Creates a QueryBuilder instance
|
|
35
|
+
*/
|
|
36
|
+
createQueryBuilder<Entity extends object, RootAlias extends string = never>(
|
|
37
|
+
entityName: EntityName<Entity> | QueryBuilder<Entity>,
|
|
38
|
+
alias?: RootAlias,
|
|
39
|
+
type?: ConnectionType,
|
|
40
|
+
loggerContext?: LoggingOptions,
|
|
41
|
+
): QueryBuilder<Entity, RootAlias>;
|
|
42
|
+
/**
|
|
43
|
+
* Shortcut for `createQueryBuilder()`
|
|
44
|
+
*/
|
|
45
|
+
qb<Entity extends object, RootAlias extends string = never>(
|
|
46
|
+
entityName: EntityName<Entity>,
|
|
47
|
+
alias?: RootAlias,
|
|
48
|
+
type?: ConnectionType,
|
|
49
|
+
loggerContext?: LoggingOptions,
|
|
50
|
+
): QueryBuilder<Entity, RootAlias>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns configured Kysely instance.
|
|
53
|
+
*/
|
|
54
|
+
getKysely<TDB = undefined, TOptions extends GetKyselyOptions = GetKyselyOptions>(
|
|
55
|
+
options?: TOptions,
|
|
56
|
+
): Kysely<
|
|
57
|
+
TDB extends undefined
|
|
58
|
+
? InferKyselyDB<EntitiesFromManager<this>, TOptions> & InferClassEntityDB<AllEntitiesFromManager<this>, TOptions>
|
|
59
|
+
: TDB
|
|
60
|
+
>;
|
|
61
|
+
/** Executes a raw SQL query, using the current transaction context if available. */
|
|
62
|
+
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(
|
|
63
|
+
query: string | NativeQueryBuilder | RawQueryFragment,
|
|
64
|
+
params?: any[],
|
|
65
|
+
method?: 'all' | 'get' | 'run',
|
|
66
|
+
loggerContext?: LoggingOptions,
|
|
67
|
+
): Promise<T>;
|
|
68
|
+
getRepository<T extends object, U extends EntityRepository<T> = SqlEntityRepository<T>>(
|
|
69
|
+
entityName: EntityName<T>,
|
|
70
|
+
): GetRepository<T, U>;
|
|
71
|
+
protected applyDiscriminatorCondition<Entity extends object>(
|
|
72
|
+
entityName: EntityName<Entity>,
|
|
73
|
+
where: FilterQuery<Entity>,
|
|
74
|
+
): FilterQuery<Entity>;
|
|
34
75
|
}
|
|
35
|
-
type EntitiesFromManager<TEntityManager extends EntityManager<any>> =
|
|
36
|
-
|
|
76
|
+
type EntitiesFromManager<TEntityManager extends EntityManager<any>> =
|
|
77
|
+
NonNullable<TEntityManager['~entities']> extends any[]
|
|
78
|
+
? Extract<NonNullable<TEntityManager['~entities']>[number], EntitySchemaWithMeta>
|
|
79
|
+
: never;
|
|
80
|
+
type AllEntitiesFromManager<TEntityManager extends EntityManager<any>> =
|
|
81
|
+
NonNullable<TEntityManager['~entities']> extends any[] ? NonNullable<TEntityManager['~entities']>[number] : never;
|
|
37
82
|
export {};
|
package/SqlEntityManager.js
CHANGED
|
@@ -1,45 +1,61 @@
|
|
|
1
|
-
import { EntityManager
|
|
1
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
2
2
|
import { MikroKyselyPlugin } from './plugin/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* @inheritDoc
|
|
5
5
|
*/
|
|
6
6
|
export class SqlEntityManager extends EntityManager {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
applyDiscriminatorCondition(entityName, where) {
|
|
42
|
-
// this is handled in QueryBuilder now for SQL drivers
|
|
43
|
-
return where;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a QueryBuilder instance
|
|
9
|
+
*/
|
|
10
|
+
createQueryBuilder(entityName, alias, type, loggerContext) {
|
|
11
|
+
const context = this.getContext(false);
|
|
12
|
+
return this.driver.createQueryBuilder(
|
|
13
|
+
entityName,
|
|
14
|
+
context.getTransactionContext(),
|
|
15
|
+
type,
|
|
16
|
+
true,
|
|
17
|
+
loggerContext ?? context.loggerContext,
|
|
18
|
+
alias,
|
|
19
|
+
this,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Shortcut for `createQueryBuilder()`
|
|
24
|
+
*/
|
|
25
|
+
qb(entityName, alias, type, loggerContext) {
|
|
26
|
+
return this.createQueryBuilder(entityName, alias, type, loggerContext);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns configured Kysely instance.
|
|
30
|
+
*/
|
|
31
|
+
getKysely(options = {}) {
|
|
32
|
+
let kysely = this.getConnection(options.type).getClient();
|
|
33
|
+
if (
|
|
34
|
+
options.columnNamingStrategy != null ||
|
|
35
|
+
options.tableNamingStrategy != null ||
|
|
36
|
+
options.processOnCreateHooks != null ||
|
|
37
|
+
options.processOnUpdateHooks != null ||
|
|
38
|
+
options.convertValues != null
|
|
39
|
+
) {
|
|
40
|
+
kysely = kysely.withPlugin(new MikroKyselyPlugin(this, options));
|
|
44
41
|
}
|
|
42
|
+
return kysely;
|
|
43
|
+
}
|
|
44
|
+
/** Executes a raw SQL query, using the current transaction context if available. */
|
|
45
|
+
async execute(query, params = [], method = 'all', loggerContext) {
|
|
46
|
+
return this.getDriver().execute(
|
|
47
|
+
query,
|
|
48
|
+
params,
|
|
49
|
+
method,
|
|
50
|
+
this.getContext(false).getTransactionContext(),
|
|
51
|
+
loggerContext,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
getRepository(entityName) {
|
|
55
|
+
return super.getRepository(entityName);
|
|
56
|
+
}
|
|
57
|
+
applyDiscriminatorCondition(entityName, where) {
|
|
58
|
+
// this is handled in QueryBuilder now for SQL drivers
|
|
59
|
+
return where;
|
|
60
|
+
}
|
|
45
61
|
}
|
package/SqlEntityRepository.d.ts
CHANGED
|
@@ -3,18 +3,18 @@ import type { SqlEntityManager } from './SqlEntityManager.js';
|
|
|
3
3
|
import type { QueryBuilder } from './query/QueryBuilder.js';
|
|
4
4
|
/** SQL-specific entity repository with QueryBuilder support. */
|
|
5
5
|
export declare class SqlEntityRepository<Entity extends object> extends EntityRepository<Entity> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
protected readonly em: SqlEntityManager;
|
|
7
|
+
constructor(em: SqlEntityManager, entityName: EntityName<Entity>);
|
|
8
|
+
/**
|
|
9
|
+
* Creates a QueryBuilder instance
|
|
10
|
+
*/
|
|
11
|
+
createQueryBuilder<RootAlias extends string = never>(alias?: RootAlias): QueryBuilder<Entity, RootAlias>;
|
|
12
|
+
/**
|
|
13
|
+
* Shortcut for `createQueryBuilder()`
|
|
14
|
+
*/
|
|
15
|
+
qb<RootAlias extends string = never>(alias?: RootAlias): QueryBuilder<Entity, RootAlias>;
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
getEntityManager(): SqlEntityManager;
|
|
20
20
|
}
|
package/SqlEntityRepository.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { EntityRepository } from '@mikro-orm/core';
|
|
2
2
|
/** SQL-specific entity repository with QueryBuilder support. */
|
|
3
3
|
export class SqlEntityRepository extends EntityRepository {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
em;
|
|
5
|
+
constructor(em, entityName) {
|
|
6
|
+
super(em, entityName);
|
|
7
|
+
this.em = em;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a QueryBuilder instance
|
|
11
|
+
*/
|
|
12
|
+
createQueryBuilder(alias) {
|
|
13
|
+
return this.getEntityManager().createQueryBuilder(this.entityName, alias);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Shortcut for `createQueryBuilder()`
|
|
17
|
+
*/
|
|
18
|
+
qb(alias) {
|
|
19
|
+
return this.createQueryBuilder(alias);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
getEntityManager() {
|
|
25
|
+
return this.em;
|
|
26
|
+
}
|
|
27
27
|
}
|