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