@mikro-orm/mssql 7.2.2-dev.3 → 7.2.2-dev.30
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/MsSqlDriver.d.ts +2 -1
- package/MsSqlDriver.js +10 -0
- package/MsSqlQueryBuilder.d.ts +1 -0
- package/MsSqlQueryBuilder.js +28 -1
- package/package.json +3 -3
package/MsSqlDriver.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnyEntity, type Configuration, type ConnectionType, type EntityDictionary, type EntityName, type LoggingOptions, type NativeInsertUpdateManyOptions, type QueryResult, type Transaction, type Constructor } from '@mikro-orm/core';
|
|
1
|
+
import { type AnyEntity, type Configuration, type ConnectionType, type EntityDictionary, type EntityName, type LoggingOptions, type NativeInsertUpdateManyOptions, type QueryResult, type Transaction, type Constructor, type FilterQuery, type UpsertManyOptions } from '@mikro-orm/core';
|
|
2
2
|
import { AbstractSqlDriver, type SqlEntityManager } from '@mikro-orm/sql';
|
|
3
3
|
import { MsSqlConnection } from './MsSqlConnection.js';
|
|
4
4
|
import { MsSqlQueryBuilder } from './MsSqlQueryBuilder.js';
|
|
@@ -7,6 +7,7 @@ import { MsSqlMikroORM } from './MsSqlMikroORM.js';
|
|
|
7
7
|
export declare class MsSqlDriver extends AbstractSqlDriver<MsSqlConnection> {
|
|
8
8
|
constructor(config: Configuration);
|
|
9
9
|
nativeInsertMany<T extends AnyEntity<T>>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
|
|
10
|
+
nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
|
|
10
11
|
createQueryBuilder<T extends AnyEntity<T>>(entityName: EntityName<T>, ctx?: Transaction, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager): MsSqlQueryBuilder<T, any, any, any>;
|
|
11
12
|
private appendOutputTable;
|
|
12
13
|
/** @inheritDoc */
|
package/MsSqlDriver.js
CHANGED
|
@@ -54,6 +54,16 @@ export class MsSqlDriver extends AbstractSqlDriver {
|
|
|
54
54
|
return sql;
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
+
async nativeUpdateMany(entityName, where, data, options = {}) {
|
|
58
|
+
const meta = this.metadata.get(entityName);
|
|
59
|
+
return super.nativeUpdateMany(entityName, where, data, options, sql => {
|
|
60
|
+
if (!meta.hasTriggers) {
|
|
61
|
+
return sql;
|
|
62
|
+
}
|
|
63
|
+
const fields = this.getUpdateReturningProperties(meta, data).flatMap(prop => prop.fieldNames);
|
|
64
|
+
return this.appendOutputTable(entityName, fields, sql, sql.lastIndexOf(' where '), options);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
57
67
|
createQueryBuilder(entityName, ctx, preferredConnectionType, convertCustomTypes, loggerContext, alias, em) {
|
|
58
68
|
// do not compute the connectionType if EM is provided as it will be computed from it in the QB later on
|
|
59
69
|
const connectionType = em
|
package/MsSqlQueryBuilder.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ import { type InsertQueryBuilder, type UpdateQueryBuilder, QueryBuilder } from '
|
|
|
4
4
|
export declare class MsSqlQueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never> extends QueryBuilder<Entity, RootAlias, Hint, Context> {
|
|
5
5
|
insert(data: RequiredEntityData<Entity> | RequiredEntityData<Entity>[]): InsertQueryBuilder<Entity, RootAlias, Context>;
|
|
6
6
|
update(data: EntityData<Entity>): UpdateQueryBuilder<Entity, RootAlias, Context>;
|
|
7
|
+
private applyInsertDefaults;
|
|
7
8
|
private checkIdentityInsert;
|
|
8
9
|
}
|
package/MsSqlQueryBuilder.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { QueryFlag, Utils } from '@mikro-orm/core';
|
|
1
|
+
import { QueryFlag, Utils, raw } from '@mikro-orm/core';
|
|
2
2
|
import { QueryBuilder } from '@mikro-orm/sql';
|
|
3
3
|
/** Query builder with MSSQL-specific behavior such as identity insert handling. */
|
|
4
4
|
export class MsSqlQueryBuilder extends QueryBuilder {
|
|
5
5
|
insert(data) {
|
|
6
|
+
data = this.applyInsertDefaults(data);
|
|
6
7
|
this.checkIdentityInsert(data);
|
|
7
8
|
if (this.mainAlias.meta?.hasTriggers) {
|
|
8
9
|
this.setFlag(QueryFlag.OUTPUT_TABLE);
|
|
@@ -15,6 +16,32 @@ export class MsSqlQueryBuilder extends QueryBuilder {
|
|
|
15
16
|
}
|
|
16
17
|
return super.update(data);
|
|
17
18
|
}
|
|
19
|
+
applyInsertDefaults(data) {
|
|
20
|
+
if (!Array.isArray(data) || data.length < 2) {
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
const meta = this.mainAlias.meta;
|
|
24
|
+
const keys = Utils.unique(data.flatMap(row => Utils.keys(row))).filter(key => meta.properties[key]?.defaultRaw);
|
|
25
|
+
if (keys.length === 0) {
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
const schemaHelper = this.platform.getSchemaHelper();
|
|
29
|
+
// MERGE uses a derived VALUES table, where DEFAULT is not allowed.
|
|
30
|
+
return data.map(row => {
|
|
31
|
+
let copy = row;
|
|
32
|
+
for (const key of keys) {
|
|
33
|
+
if (row[key] === undefined) {
|
|
34
|
+
if (copy === row) {
|
|
35
|
+
copy = { ...row };
|
|
36
|
+
}
|
|
37
|
+
const prop = meta.properties[key];
|
|
38
|
+
// same normalization as the DDL, e.g. `true` is not a valid MSSQL literal
|
|
39
|
+
copy[key] = raw(`${schemaHelper.normalizeDefaultValue(prop.defaultRaw, prop.length)}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return copy;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
18
45
|
checkIdentityInsert(data) {
|
|
19
46
|
const meta = this.mainAlias.meta;
|
|
20
47
|
const dataKeys = Utils.unique(Utils.asArray(data).flatMap(d => Utils.keys(d)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mssql",
|
|
3
|
-
"version": "7.2.2-dev.
|
|
3
|
+
"version": "7.2.2-dev.30",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@mikro-orm/sql": "7.2.2-dev.
|
|
50
|
+
"@mikro-orm/sql": "7.2.2-dev.30",
|
|
51
51
|
"kysely": "0.29.6",
|
|
52
52
|
"tarn": "3.1.2",
|
|
53
53
|
"tedious": "20.0.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@mikro-orm/core": "^7.2.1"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@mikro-orm/core": "7.2.2-dev.
|
|
60
|
+
"@mikro-orm/core": "7.2.2-dev.30"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">= 22.17.0"
|