@mikro-orm/mssql 7.0.0-dev.5 → 7.0.0-dev.51
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 +1 -0
- package/MsSqlDriver.js +25 -2
- package/MsSqlMikroORM.d.ts +7 -8
- package/MsSqlMikroORM.js +6 -8
- package/MsSqlPlatform.d.ts +5 -2
- package/MsSqlPlatform.js +16 -2
- package/MsSqlQueryBuilder.js +6 -0
- package/README.md +3 -2
- package/package.json +6 -6
package/MsSqlDriver.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export declare class MsSqlDriver extends AbstractSqlDriver<MsSqlConnection> {
|
|
|
6
6
|
constructor(config: Configuration);
|
|
7
7
|
nativeInsertMany<T extends AnyEntity<T>>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
|
|
8
8
|
createQueryBuilder<T extends AnyEntity<T>>(entityName: string, ctx?: Transaction, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager): MsSqlQueryBuilder<T, any, any, any>;
|
|
9
|
+
private appendOutputTable;
|
|
9
10
|
}
|
package/MsSqlDriver.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueryFlag, Utils, } from '@mikro-orm/core';
|
|
1
|
+
import { QueryFlag, Utils, isRaw, } from '@mikro-orm/core';
|
|
2
2
|
import { AbstractSqlDriver } from '@mikro-orm/knex';
|
|
3
3
|
import { MsSqlConnection } from './MsSqlConnection.js';
|
|
4
4
|
import { MsSqlPlatform } from './MsSqlPlatform.js';
|
|
@@ -37,7 +37,7 @@ export class MsSqlDriver extends AbstractSqlDriver {
|
|
|
37
37
|
return `set identity_insert ${tableName} on; ${sql}; set identity_insert ${tableName} off`;
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
return super.nativeInsertMany(entityName, data, options);
|
|
40
|
+
return super.nativeInsertMany(entityName, data, options, sql => meta.hasTriggers ? this.appendOutputTable(entityName, data, sql) : sql);
|
|
41
41
|
}
|
|
42
42
|
createQueryBuilder(entityName, ctx, preferredConnectionType, convertCustomTypes, loggerContext, alias, em) {
|
|
43
43
|
// do not compute the connectionType if EM is provided as it will be computed from it in the QB later on
|
|
@@ -48,4 +48,27 @@ export class MsSqlDriver extends AbstractSqlDriver {
|
|
|
48
48
|
}
|
|
49
49
|
return qb;
|
|
50
50
|
}
|
|
51
|
+
appendOutputTable(entityName, data, sql) {
|
|
52
|
+
const meta = this.metadata.get(entityName);
|
|
53
|
+
const returningProps = meta.props
|
|
54
|
+
.filter(prop => prop.persist !== false && prop.defaultRaw || prop.autoincrement || prop.generated)
|
|
55
|
+
.filter(prop => !(prop.name in data[0]) || isRaw(data[0][prop.name]));
|
|
56
|
+
const returningFields = Utils.flatten(returningProps.map(prop => prop.fieldNames));
|
|
57
|
+
/* v8 ignore next 3 */
|
|
58
|
+
if (returningFields.length === 0) {
|
|
59
|
+
return sql;
|
|
60
|
+
}
|
|
61
|
+
const tableName = this.getTableName(meta, {}, true);
|
|
62
|
+
const selections = returningFields
|
|
63
|
+
.map((field) => `[t].${this.platform.quoteIdentifier(field)}`)
|
|
64
|
+
.join(',');
|
|
65
|
+
const position = sql.indexOf(' values ');
|
|
66
|
+
const sqlBeforeValues = sql.substring(0, position);
|
|
67
|
+
const sqlAfterValues = sql.substring(position + 1);
|
|
68
|
+
let outputSql = `select top(0) ${selections} into #out from ${tableName} as t left join ${tableName} on 0 = 1; `;
|
|
69
|
+
outputSql += `${sqlBeforeValues} into #out ${sqlAfterValues}; `;
|
|
70
|
+
outputSql += `select ${selections} from #out as t; `;
|
|
71
|
+
outputSql += `drop table #out`;
|
|
72
|
+
return outputSql;
|
|
73
|
+
}
|
|
51
74
|
}
|
package/MsSqlMikroORM.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
|
|
2
|
-
import { MsSqlDriver } from './MsSqlDriver.js';
|
|
1
|
+
import { type AnyEntity, type EntityClass, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
|
|
3
2
|
import type { SqlEntityManager } from '@mikro-orm/knex';
|
|
3
|
+
import { MsSqlDriver } from './MsSqlDriver.js';
|
|
4
|
+
export type MsSqlOptions<EM extends SqlEntityManager<MsSqlDriver> = SqlEntityManager<MsSqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Options<MsSqlDriver, EM, Entities>;
|
|
5
|
+
export declare function defineMsSqlConfig<EM extends SqlEntityManager<MsSqlDriver> = SqlEntityManager<MsSqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: MsSqlOptions<EM, Entities>): Options<MsSqlDriver, EM, Entities>;
|
|
4
6
|
/**
|
|
5
7
|
* @inheritDoc
|
|
6
8
|
*/
|
|
7
|
-
export declare class MsSqlMikroORM<EM extends
|
|
8
|
-
private static DRIVER;
|
|
9
|
+
export declare class MsSqlMikroORM<EM extends SqlEntityManager<MsSqlDriver> = SqlEntityManager<MsSqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends MikroORM<MsSqlDriver, EM, Entities> {
|
|
9
10
|
/**
|
|
10
11
|
* @inheritDoc
|
|
11
12
|
*/
|
|
12
|
-
static init<D extends IDatabaseDriver = MsSqlDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options
|
|
13
|
+
static init<D extends IDatabaseDriver = MsSqlDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Options<D, EM, Entities>): Promise<MikroORM<D, EM, Entities>>;
|
|
13
14
|
/**
|
|
14
15
|
* @inheritDoc
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
constructor(options: MsSqlOptions<EM, Entities>);
|
|
17
18
|
}
|
|
18
|
-
export type MsSqlOptions = Options<MsSqlDriver>;
|
|
19
|
-
export declare function defineMsSqlConfig(options: MsSqlOptions): Options<MsSqlDriver, SqlEntityManager<MsSqlDriver> & EntityManager<IDatabaseDriver<import("@mikro-orm/core").Connection>>>;
|
package/MsSqlMikroORM.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { defineConfig, MikroORM, } from '@mikro-orm/core';
|
|
2
2
|
import { MsSqlDriver } from './MsSqlDriver.js';
|
|
3
|
+
export function defineMsSqlConfig(options) {
|
|
4
|
+
return defineConfig({ driver: MsSqlDriver, ...options });
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* @inheritDoc
|
|
5
8
|
*/
|
|
6
9
|
export class MsSqlMikroORM extends MikroORM {
|
|
7
|
-
static DRIVER = MsSqlDriver;
|
|
8
10
|
/**
|
|
9
11
|
* @inheritDoc
|
|
10
12
|
*/
|
|
11
13
|
static async init(options) {
|
|
12
|
-
return super.init(options);
|
|
14
|
+
return super.init(defineMsSqlConfig(options));
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* @inheritDoc
|
|
16
18
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
constructor(options) {
|
|
20
|
+
super(defineMsSqlConfig(options));
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
/* v8 ignore next 3 */
|
|
22
|
-
export function defineMsSqlConfig(options) {
|
|
23
|
-
return defineConfig({ driver: MsSqlDriver, ...options });
|
|
24
|
-
}
|
package/MsSqlPlatform.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractSqlPlatform, type EntityMetadata, type IDatabaseDriver, type EntityManager, type MikroORM, Type, type Primary, type IPrimaryKey, MsSqlNativeQueryBuilder } from '@mikro-orm/knex';
|
|
1
|
+
import { AbstractSqlPlatform, type EntityMetadata, type IDatabaseDriver, type EntityManager, type MikroORM, Type, type Primary, type IPrimaryKey, QueryOrder, MsSqlNativeQueryBuilder } from '@mikro-orm/knex';
|
|
2
2
|
import { MsSqlSchemaHelper } from './MsSqlSchemaHelper.js';
|
|
3
3
|
import { MsSqlExceptionConverter } from './MsSqlExceptionConverter.js';
|
|
4
4
|
import { MsSqlSchemaGenerator } from './MsSqlSchemaGenerator.js';
|
|
@@ -55,9 +55,12 @@ export declare class MsSqlPlatform extends AbstractSqlPlatform {
|
|
|
55
55
|
usesEnumCheckConstraints(): boolean;
|
|
56
56
|
supportsMultipleCascadePaths(): boolean;
|
|
57
57
|
supportsMultipleStatements(): boolean;
|
|
58
|
-
quoteIdentifier(id: string
|
|
58
|
+
quoteIdentifier(id: string | {
|
|
59
|
+
toString: () => string;
|
|
60
|
+
}): string;
|
|
59
61
|
escape(value: any): string;
|
|
60
62
|
getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): MsSqlSchemaGenerator;
|
|
61
63
|
allowsComparingTuples(): boolean;
|
|
64
|
+
getOrderByExpression(column: string, direction: QueryOrder): string[];
|
|
62
65
|
getDefaultClientUrl(): string;
|
|
63
66
|
}
|
package/MsSqlPlatform.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractSqlPlatform, raw, Type, Utils, ALIAS_REPLACEMENT, DoubleType, FloatType, RawQueryFragment, MsSqlNativeQueryBuilder, } from '@mikro-orm/knex';
|
|
1
|
+
import { AbstractSqlPlatform, raw, Type, Utils, ALIAS_REPLACEMENT, DoubleType, FloatType, QueryOrder, RawQueryFragment, MsSqlNativeQueryBuilder, } from '@mikro-orm/knex';
|
|
2
2
|
// @ts-expect-error no types available
|
|
3
3
|
import SqlString from 'tsqlstring';
|
|
4
4
|
import { MsSqlSchemaHelper } from './MsSqlSchemaHelper.js';
|
|
@@ -175,7 +175,7 @@ export class MsSqlPlatform extends AbstractSqlPlatform {
|
|
|
175
175
|
if (RawQueryFragment.isKnownFragment(id)) {
|
|
176
176
|
return super.quoteIdentifier(id);
|
|
177
177
|
}
|
|
178
|
-
return `[${id.replace('.', `].[`)}]`;
|
|
178
|
+
return `[${id.toString().replace('.', `].[`)}]`;
|
|
179
179
|
}
|
|
180
180
|
escape(value) {
|
|
181
181
|
if (value instanceof UnicodeString) {
|
|
@@ -196,6 +196,20 @@ export class MsSqlPlatform extends AbstractSqlPlatform {
|
|
|
196
196
|
allowsComparingTuples() {
|
|
197
197
|
return false;
|
|
198
198
|
}
|
|
199
|
+
getOrderByExpression(column, direction) {
|
|
200
|
+
switch (direction.toUpperCase()) {
|
|
201
|
+
case QueryOrder.ASC_NULLS_FIRST:
|
|
202
|
+
return [`case when ${column} is null then 0 else 1 end, ${column} asc`];
|
|
203
|
+
case QueryOrder.ASC_NULLS_LAST:
|
|
204
|
+
return [`case when ${column} is null then 1 else 0 end, ${column} asc`];
|
|
205
|
+
case QueryOrder.DESC_NULLS_FIRST:
|
|
206
|
+
return [`case when ${column} is null then 0 else 1 end, ${column} desc`];
|
|
207
|
+
case QueryOrder.DESC_NULLS_LAST:
|
|
208
|
+
return [`case when ${column} is null then 1 else 0 end, ${column} desc`];
|
|
209
|
+
default:
|
|
210
|
+
return [`${column} ${direction.toLowerCase()}`];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
199
213
|
getDefaultClientUrl() {
|
|
200
214
|
return 'mssql://sa@localhost:1433';
|
|
201
215
|
}
|
package/MsSqlQueryBuilder.js
CHANGED
|
@@ -3,6 +3,12 @@ import { QueryBuilder } from '@mikro-orm/knex';
|
|
|
3
3
|
export class MsSqlQueryBuilder extends QueryBuilder {
|
|
4
4
|
insert(data) {
|
|
5
5
|
this.checkIdentityInsert(data);
|
|
6
|
+
if (!this.flags.has(QueryFlag.IDENTITY_INSERT) && this.metadata.has(this.mainAlias.entityName)) {
|
|
7
|
+
const meta = this.metadata.find(this.mainAlias.entityName);
|
|
8
|
+
if (meta.hasTriggers) {
|
|
9
|
+
this.setFlag(QueryFlag.OUTPUT_TABLE);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
6
12
|
return super.insert(data);
|
|
7
13
|
}
|
|
8
14
|
checkIdentityInsert(data) {
|
package/README.md
CHANGED
|
@@ -11,7 +11,6 @@ TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-or
|
|
|
11
11
|
[](https://discord.gg/w8bjxFHS7X)
|
|
12
12
|
[](https://www.npmjs.com/package/@mikro-orm/core)
|
|
13
13
|
[](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
|
|
14
|
-
[](https://codeclimate.com/github/mikro-orm/mikro-orm/maintainability)
|
|
15
14
|
[](https://github.com/mikro-orm/mikro-orm/actions?workflow=tests)
|
|
16
15
|
|
|
17
16
|
## 🤔 Unit of What?
|
|
@@ -141,7 +140,7 @@ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit m
|
|
|
141
140
|
- [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
|
|
142
141
|
- [Filters](https://mikro-orm.io/docs/filters)
|
|
143
142
|
- [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
|
|
144
|
-
- [
|
|
143
|
+
- [Populating relations](https://mikro-orm.io/docs/populating-relations)
|
|
145
144
|
- [Property Validation](https://mikro-orm.io/docs/property-validation)
|
|
146
145
|
- [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
|
|
147
146
|
- [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
|
|
@@ -382,6 +381,8 @@ See also the list of contributors who [participated](https://github.com/mikro-or
|
|
|
382
381
|
|
|
383
382
|
Please ⭐️ this repository if this project helped you!
|
|
384
383
|
|
|
384
|
+
> If you'd like to support my open-source work, consider sponsoring me directly at [github.com/sponsors/b4nan](https://github.com/sponsors/b4nan).
|
|
385
|
+
|
|
385
386
|
## 📝 License
|
|
386
387
|
|
|
387
388
|
Copyright © 2018 [Martin Adámek](https://github.com/b4nan).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mssql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.51",
|
|
5
5
|
"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.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/knex": "7.0.0-dev.
|
|
53
|
+
"@mikro-orm/knex": "7.0.0-dev.51",
|
|
54
54
|
"tarn": "3.0.2",
|
|
55
|
-
"tedious": "19.
|
|
55
|
+
"tedious": "19.1.0",
|
|
56
56
|
"tsqlstring": "1.0.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@mikro-orm/core": "^6.
|
|
60
|
-
"kysely": "
|
|
59
|
+
"@mikro-orm/core": "^6.6.0",
|
|
60
|
+
"kysely": "0.28.7"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
63
|
+
"@mikro-orm/core": "7.0.0-dev.51",
|
|
64
64
|
"kysely": "*"
|
|
65
65
|
}
|
|
66
66
|
}
|