@spinajs/orm-mssql 2.0.180 → 2.0.181
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/lib/cjs/compilers.d.ts +49 -49
- package/lib/cjs/compilers.js +252 -252
- package/lib/cjs/compilers.js.map +1 -1
- package/lib/cjs/converters.d.ts +6 -6
- package/lib/cjs/converters.js +24 -24
- package/lib/cjs/dehydrator.d.ts +4 -4
- package/lib/cjs/dehydrator.js +16 -16
- package/lib/cjs/index.d.ts +16 -16
- package/lib/cjs/index.js +200 -200
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +17 -17
- package/lib/cjs/types.js +2 -2
- package/lib/mjs/compilers.d.ts +49 -49
- package/lib/mjs/compilers.js +246 -246
- package/lib/mjs/compilers.js.map +1 -1
- package/lib/mjs/converters.d.ts +6 -6
- package/lib/mjs/converters.js +20 -20
- package/lib/mjs/dehydrator.d.ts +4 -4
- package/lib/mjs/dehydrator.js +12 -12
- package/lib/mjs/index.d.ts +16 -16
- package/lib/mjs/index.js +194 -194
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/types.d.ts +17 -17
- package/lib/mjs/types.js +1 -1
- package/lib/mjs/util.d.ts +1 -1
- package/lib/mjs/util.js +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +5 -5
package/lib/cjs/compilers.d.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { IContainer } from '@spinajs/di';
|
|
2
|
-
import { TableExistsCompiler, TableExistsQueryBuilder, ICompilerOutput, ColumnQueryBuilder, TableAliasCompiler, IQueryBuilder, InsertQueryBuilder } from '@spinajs/orm';
|
|
3
|
-
import { SqlColumnQueryCompiler, SqlDeleteQueryCompiler, SqlInsertQueryCompiler, SqlLimitQueryCompiler, SqlOrderByQueryCompiler, SqlTableQueryCompiler, SqlOnDuplicateQueryCompiler } from '@spinajs/orm-sql';
|
|
4
|
-
export declare class MsSqlOnDuplicateQueryCompiler extends SqlOnDuplicateQueryCompiler {
|
|
5
|
-
compile(): {
|
|
6
|
-
bindings: any[];
|
|
7
|
-
expression: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export declare class MsSqlInsertQueryCompiler extends SqlInsertQueryCompiler {
|
|
11
|
-
protected isDuplicate: boolean;
|
|
12
|
-
constructor(container: IContainer, builder: InsertQueryBuilder);
|
|
13
|
-
compile(): {
|
|
14
|
-
bindings: any[];
|
|
15
|
-
expression: string;
|
|
16
|
-
};
|
|
17
|
-
protected into(): string;
|
|
18
|
-
}
|
|
19
|
-
export declare class MsSqlTableExistsCompiler implements TableExistsCompiler {
|
|
20
|
-
protected builder: TableExistsQueryBuilder;
|
|
21
|
-
constructor(builder: TableExistsQueryBuilder);
|
|
22
|
-
compile(): ICompilerOutput;
|
|
23
|
-
}
|
|
24
|
-
export declare class MsSqlLimitCompiler extends SqlLimitQueryCompiler {
|
|
25
|
-
compile(): ICompilerOutput;
|
|
26
|
-
}
|
|
27
|
-
export declare class MsSqlOrderByCompiler extends SqlOrderByQueryCompiler {
|
|
28
|
-
compile(): ICompilerOutput;
|
|
29
|
-
}
|
|
30
|
-
export declare class MsSqlTableQueryCompiler extends SqlTableQueryCompiler {
|
|
31
|
-
compile(): ICompilerOutput[];
|
|
32
|
-
protected _columns(): string;
|
|
33
|
-
protected _foreignKeys(): string;
|
|
34
|
-
protected _table(): string;
|
|
35
|
-
}
|
|
36
|
-
export declare class MsSqlColumnQueryCompiler extends SqlColumnQueryCompiler {
|
|
37
|
-
protected builder: ColumnQueryBuilder;
|
|
38
|
-
constructor(builder: ColumnQueryBuilder);
|
|
39
|
-
}
|
|
40
|
-
export declare class MsSqlDeleteQueryCompiler extends SqlDeleteQueryCompiler {
|
|
41
|
-
compile(): {
|
|
42
|
-
bindings: any[];
|
|
43
|
-
expression: string;
|
|
44
|
-
};
|
|
45
|
-
protected from(): string;
|
|
46
|
-
}
|
|
47
|
-
export declare class MsSqlTableAliasCompiler implements TableAliasCompiler {
|
|
48
|
-
compile(builder: IQueryBuilder, tbl?: string): string;
|
|
49
|
-
}
|
|
1
|
+
import { IContainer } from '@spinajs/di';
|
|
2
|
+
import { TableExistsCompiler, TableExistsQueryBuilder, ICompilerOutput, ColumnQueryBuilder, TableAliasCompiler, IQueryBuilder, InsertQueryBuilder } from '@spinajs/orm';
|
|
3
|
+
import { SqlColumnQueryCompiler, SqlDeleteQueryCompiler, SqlInsertQueryCompiler, SqlLimitQueryCompiler, SqlOrderByQueryCompiler, SqlTableQueryCompiler, SqlOnDuplicateQueryCompiler } from '@spinajs/orm-sql';
|
|
4
|
+
export declare class MsSqlOnDuplicateQueryCompiler extends SqlOnDuplicateQueryCompiler {
|
|
5
|
+
compile(): {
|
|
6
|
+
bindings: any[];
|
|
7
|
+
expression: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export declare class MsSqlInsertQueryCompiler extends SqlInsertQueryCompiler {
|
|
11
|
+
protected isDuplicate: boolean;
|
|
12
|
+
constructor(container: IContainer, builder: InsertQueryBuilder);
|
|
13
|
+
compile(): {
|
|
14
|
+
bindings: any[];
|
|
15
|
+
expression: string;
|
|
16
|
+
};
|
|
17
|
+
protected into(): string;
|
|
18
|
+
}
|
|
19
|
+
export declare class MsSqlTableExistsCompiler implements TableExistsCompiler {
|
|
20
|
+
protected builder: TableExistsQueryBuilder;
|
|
21
|
+
constructor(builder: TableExistsQueryBuilder);
|
|
22
|
+
compile(): ICompilerOutput;
|
|
23
|
+
}
|
|
24
|
+
export declare class MsSqlLimitCompiler extends SqlLimitQueryCompiler {
|
|
25
|
+
compile(): ICompilerOutput;
|
|
26
|
+
}
|
|
27
|
+
export declare class MsSqlOrderByCompiler extends SqlOrderByQueryCompiler {
|
|
28
|
+
compile(): ICompilerOutput;
|
|
29
|
+
}
|
|
30
|
+
export declare class MsSqlTableQueryCompiler extends SqlTableQueryCompiler {
|
|
31
|
+
compile(): ICompilerOutput[];
|
|
32
|
+
protected _columns(): string;
|
|
33
|
+
protected _foreignKeys(): string;
|
|
34
|
+
protected _table(): string;
|
|
35
|
+
}
|
|
36
|
+
export declare class MsSqlColumnQueryCompiler extends SqlColumnQueryCompiler {
|
|
37
|
+
protected builder: ColumnQueryBuilder;
|
|
38
|
+
constructor(builder: ColumnQueryBuilder);
|
|
39
|
+
}
|
|
40
|
+
export declare class MsSqlDeleteQueryCompiler extends SqlDeleteQueryCompiler {
|
|
41
|
+
compile(): {
|
|
42
|
+
bindings: any[];
|
|
43
|
+
expression: string;
|
|
44
|
+
};
|
|
45
|
+
protected from(): string;
|
|
46
|
+
}
|
|
47
|
+
export declare class MsSqlTableAliasCompiler implements TableAliasCompiler {
|
|
48
|
+
compile(builder: IQueryBuilder, tbl?: string): string;
|
|
49
|
+
}
|
|
50
50
|
//# sourceMappingURL=compilers.d.ts.map
|
package/lib/cjs/compilers.js
CHANGED
|
@@ -1,260 +1,260 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.MsSqlTableAliasCompiler = exports.MsSqlDeleteQueryCompiler = exports.MsSqlColumnQueryCompiler = exports.MsSqlTableQueryCompiler = exports.MsSqlOrderByCompiler = exports.MsSqlLimitCompiler = exports.MsSqlTableExistsCompiler = exports.MsSqlInsertQueryCompiler = exports.MsSqlOnDuplicateQueryCompiler = void 0;
|
|
16
|
-
const configuration_1 = require("@spinajs/configuration");
|
|
17
|
-
const di_1 = require("@spinajs/di");
|
|
18
|
-
const orm_1 = require("@spinajs/orm");
|
|
19
|
-
const orm_sql_1 = require("@spinajs/orm-sql");
|
|
20
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
21
|
-
let MsSqlOnDuplicateQueryCompiler = class MsSqlOnDuplicateQueryCompiler extends orm_sql_1.SqlOnDuplicateQueryCompiler {
|
|
22
|
-
compile() {
|
|
23
|
-
const table = this._builder.getParent().Container.resolve(orm_1.TableAliasCompiler).compile(this._builder.getParent());
|
|
24
|
-
const descriptor = (0, orm_1.extractModelDescriptor)(this._builder.getParent().Model);
|
|
25
|
-
if (this._builder.getColumn().length === 0) {
|
|
26
|
-
throw new orm_1.OrmException(`no unique columns defined in table ${this._builder.getParent().Table}`);
|
|
27
|
-
}
|
|
28
|
-
const columns = this._builder
|
|
29
|
-
.getColumnsToUpdate()
|
|
30
|
-
.map((c) => {
|
|
31
|
-
if (lodash_1.default.isString(c)) {
|
|
32
|
-
return `\`${c}\` = ?`;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return c.Query;
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
.join(',');
|
|
39
|
-
const parent = this._builder.getParent();
|
|
40
|
-
const valueMap = parent.getColumns()
|
|
41
|
-
.map((c) => c.Column);
|
|
42
|
-
const bindings = this._builder.getColumnsToUpdate().map((c) => {
|
|
43
|
-
if (lodash_1.default.isString(c)) {
|
|
44
|
-
return parent.Values[0][valueMap.indexOf(c)];
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return c.Bindings;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
const wBindings = this._builder.getColumn().map((c) => {
|
|
51
|
-
return parent.Values[0][valueMap.indexOf(c)];
|
|
52
|
-
});
|
|
53
|
-
return {
|
|
54
|
-
bindings: wBindings.concat(bindings),
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MsSqlTableAliasCompiler = exports.MsSqlDeleteQueryCompiler = exports.MsSqlColumnQueryCompiler = exports.MsSqlTableQueryCompiler = exports.MsSqlOrderByCompiler = exports.MsSqlLimitCompiler = exports.MsSqlTableExistsCompiler = exports.MsSqlInsertQueryCompiler = exports.MsSqlOnDuplicateQueryCompiler = void 0;
|
|
16
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
17
|
+
const di_1 = require("@spinajs/di");
|
|
18
|
+
const orm_1 = require("@spinajs/orm");
|
|
19
|
+
const orm_sql_1 = require("@spinajs/orm-sql");
|
|
20
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
21
|
+
let MsSqlOnDuplicateQueryCompiler = class MsSqlOnDuplicateQueryCompiler extends orm_sql_1.SqlOnDuplicateQueryCompiler {
|
|
22
|
+
compile() {
|
|
23
|
+
const table = this._builder.getParent().Container.resolve(orm_1.TableAliasCompiler).compile(this._builder.getParent());
|
|
24
|
+
const descriptor = (0, orm_1.extractModelDescriptor)(this._builder.getParent().Model);
|
|
25
|
+
if (this._builder.getColumn().length === 0) {
|
|
26
|
+
throw new orm_1.OrmException(`no unique columns defined in table ${this._builder.getParent().Table}`);
|
|
27
|
+
}
|
|
28
|
+
const columns = this._builder
|
|
29
|
+
.getColumnsToUpdate()
|
|
30
|
+
.map((c) => {
|
|
31
|
+
if (lodash_1.default.isString(c)) {
|
|
32
|
+
return `\`${c}\` = ?`;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return c.Query;
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
.join(',');
|
|
39
|
+
const parent = this._builder.getParent();
|
|
40
|
+
const valueMap = parent.getColumns()
|
|
41
|
+
.map((c) => c.Column);
|
|
42
|
+
const bindings = this._builder.getColumnsToUpdate().map((c) => {
|
|
43
|
+
if (lodash_1.default.isString(c)) {
|
|
44
|
+
return parent.Values[0][valueMap.indexOf(c)];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return c.Bindings;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const wBindings = this._builder.getColumn().map((c) => {
|
|
51
|
+
return parent.Values[0][valueMap.indexOf(c)];
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
bindings: wBindings.concat(bindings),
|
|
55
55
|
expression: `MERGE INTO ${table} WITH (HOLDLOCK) AS target
|
|
56
|
-
USING (SELECT * FROM ${table} WHERE ${this._builder.getColumn().map((c) => {
|
|
57
|
-
return `${c} = ?`;
|
|
56
|
+
USING (SELECT * FROM ${table} WHERE ${this._builder.getColumn().map((c) => {
|
|
57
|
+
return `${c} = ?`;
|
|
58
58
|
})}) as source
|
|
59
59
|
ON (target.${descriptor.PrimaryKey} = source.${descriptor.PrimaryKey})
|
|
60
60
|
WHEN MATCHED
|
|
61
61
|
THEN UPDATE
|
|
62
62
|
SET ${columns}
|
|
63
63
|
WHEN NOT MATCHED
|
|
64
|
-
THEN `.replace(/(\r\n|\n|\r)/gm, ''),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
MsSqlOnDuplicateQueryCompiler =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
let MsSqlInsertQueryCompiler = class MsSqlInsertQueryCompiler extends orm_sql_1.SqlInsertQueryCompiler {
|
|
73
|
-
constructor(container, builder) {
|
|
74
|
-
super(container, builder);
|
|
75
|
-
this.isDuplicate = false;
|
|
76
|
-
this.isDuplicate = this._builder.DuplicateQueryBuilder !== null && this._builder.DuplicateQueryBuilder !== undefined;
|
|
77
|
-
}
|
|
78
|
-
compile() {
|
|
79
|
-
if (this._builder.Ignore) {
|
|
80
|
-
throw new orm_1.OrmException(`mssql insert or ignore is not supported`);
|
|
81
|
-
}
|
|
82
|
-
const into = this.into();
|
|
83
|
-
const columns = this.columns();
|
|
84
|
-
const values = this.values();
|
|
85
|
-
const iBindings = values.bindings;
|
|
86
|
-
const iExpression = `${into} ${columns} ${values.data}`;
|
|
87
|
-
const dResult = super.upsort();
|
|
88
|
-
return {
|
|
89
|
-
bindings: dResult.bindings.concat(iBindings),
|
|
90
|
-
expression: dResult.expression + iExpression + '; SELECT SCOPE_IDENTITY() as ID;',
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
into() {
|
|
94
|
-
return `INSERT ${this.isDuplicate ? '' : `INTO ${this._container.resolve(orm_1.TableAliasCompiler).compile(this._builder)}`} `;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
MsSqlInsertQueryCompiler =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
let MsSqlTableExistsCompiler = class MsSqlTableExistsCompiler {
|
|
103
|
-
constructor(builder) {
|
|
104
|
-
this.builder = builder;
|
|
105
|
-
if (builder === null) {
|
|
106
|
-
throw new Error('table exists query builder cannot be null');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
compile() {
|
|
110
|
-
const bindings = [this.builder.Table];
|
|
111
|
-
let expression = '';
|
|
112
|
-
if (this.builder.Database) {
|
|
113
|
-
bindings.push(this.builder.Database);
|
|
114
|
-
expression = `SELECT TOP(1) * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=? AND TABLE_CATALOG=? ORDER BY TABLE_NAME`;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
expression = `SELECT TOP(1) * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=? ORDER BY TABLE_NAME`;
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
bindings,
|
|
121
|
-
expression,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
MsSqlTableExistsCompiler =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let MsSqlLimitCompiler = class MsSqlLimitCompiler extends orm_sql_1.SqlLimitQueryCompiler {
|
|
131
|
-
compile() {
|
|
132
|
-
const limits = this._builder.getLimits();
|
|
133
|
-
const bindings = [];
|
|
134
|
-
let stmt = '';
|
|
135
|
-
if (limits.limit > 0) {
|
|
136
|
-
stmt += ` OFFSET ? ROWS`;
|
|
137
|
-
bindings.push(Math.max(limits.offset, 0));
|
|
138
|
-
stmt += ` FETCH NEXT ? ROWS ONLY`;
|
|
139
|
-
bindings.push(limits.limit);
|
|
140
|
-
}
|
|
141
|
-
return {
|
|
142
|
-
bindings,
|
|
143
|
-
expression: stmt,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
MsSqlLimitCompiler =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
let MsSqlOrderByCompiler = class MsSqlOrderByCompiler extends orm_sql_1.SqlOrderByQueryCompiler {
|
|
152
|
-
compile() {
|
|
153
|
-
const sort = this._builder.getSort();
|
|
154
|
-
let stmt = '';
|
|
155
|
-
const bindings = [];
|
|
156
|
-
if (sort) {
|
|
157
|
-
stmt = ` ORDER BY \`${sort.column}\` ${sort.order.toLowerCase() === 'asc' ? 'ASC' : 'DESC'}`;
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
bindings,
|
|
161
|
-
expression: stmt,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
MsSqlOrderByCompiler =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
let MsSqlTableQueryCompiler = class MsSqlTableQueryCompiler extends orm_sql_1.SqlTableQueryCompiler {
|
|
170
|
-
compile() {
|
|
171
|
-
const _table = this._table();
|
|
172
|
-
const _columns = this._columns();
|
|
173
|
-
const _keys = [this._foreignKeys()];
|
|
174
|
-
const _unique = this.builder.Columns.filter((c) => c.Unique).map((c) => c.Name);
|
|
175
|
-
return [
|
|
176
|
-
{
|
|
177
|
-
bindings: [],
|
|
178
|
-
expression: `${_table} (${_columns} ${_unique.length !== 0 ? `, UNIQUE(${_unique.join(',')}) ` : ''} ${_keys ? ',' + _keys.filter((k) => k && k !== '').join(',') : ''})`,
|
|
179
|
-
},
|
|
180
|
-
];
|
|
181
|
-
}
|
|
182
|
-
_columns() {
|
|
183
|
-
return this.builder.Columns.map((c) => {
|
|
184
|
-
const expr = this.container.resolve(orm_1.ColumnQueryCompiler, [c]).compile().expression;
|
|
185
|
-
if (c.PrimaryKey) {
|
|
186
|
-
return expr + ' PRIMARY KEY';
|
|
187
|
-
}
|
|
188
|
-
return expr;
|
|
189
|
-
}).join(',');
|
|
190
|
-
}
|
|
191
|
-
_foreignKeys() {
|
|
192
|
-
return this.builder.ForeignKeys.map((f) => {
|
|
193
|
-
return this.container.resolve(orm_1.ForeignKeyQueryCompiler, [f]).compile().expression;
|
|
194
|
-
}).join(',');
|
|
195
|
-
}
|
|
196
|
-
_table() {
|
|
197
|
-
return `CREATE${this.builder.Temporary ? ' TEMPORARY ' : ' '}TABLE ${this.builder.CheckExists ? 'IF NOT EXISTS ' : ''}${this.container.resolve(orm_1.TableAliasCompiler).compile(this.builder)}`;
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
MsSqlTableQueryCompiler =
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
let MsSqlColumnQueryCompiler = class MsSqlColumnQueryCompiler extends orm_sql_1.SqlColumnQueryCompiler {
|
|
205
|
-
constructor(builder) {
|
|
206
|
-
super(builder);
|
|
207
|
-
this.builder = builder;
|
|
208
|
-
// MSSQL usess this expression for AUTO_INCREMENT
|
|
209
|
-
this._statementsMappings.autoincrement = () => `IDENTITY(1,1)`;
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
MsSqlColumnQueryCompiler =
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
let MsSqlDeleteQueryCompiler = class MsSqlDeleteQueryCompiler extends orm_sql_1.SqlDeleteQueryCompiler {
|
|
218
|
-
compile() {
|
|
219
|
-
const _bindings = [];
|
|
220
|
-
const _from = this.from();
|
|
221
|
-
const _where = this.where(this._builder);
|
|
222
|
-
const _expression = _from + (_where.expression ? ` WHERE ${_where.expression}` : '');
|
|
223
|
-
_bindings.push(..._where.bindings);
|
|
224
|
-
return {
|
|
225
|
-
bindings: _bindings,
|
|
226
|
-
expression: _expression.trim(),
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
from() {
|
|
230
|
-
const lBuilder = this._builder;
|
|
231
|
-
const limits = lBuilder.getLimits();
|
|
232
|
-
return `DELETE ${limits.limit > 0 ? `TOP ${limits.limit} ` : ''}FROM ${this._container.resolve(orm_1.TableAliasCompiler).compile(this._builder)}`;
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
MsSqlDeleteQueryCompiler =
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
let MsSqlTableAliasCompiler = class MsSqlTableAliasCompiler {
|
|
240
|
-
compile(builder, tbl) {
|
|
241
|
-
let table = '';
|
|
242
|
-
if (builder.Database) {
|
|
243
|
-
table += `\`${builder.Database}\`.`;
|
|
244
|
-
}
|
|
245
|
-
if (builder.Driver.Options.Options?.Schema) {
|
|
246
|
-
table += `\`${builder.Driver.Options.Options?.Schema}\`.`;
|
|
247
|
-
}
|
|
248
|
-
table += `\`${tbl ? tbl : builder.Table}\``;
|
|
249
|
-
if (builder.TableAlias) {
|
|
250
|
-
table += ` as \`${builder.TableAlias}\``;
|
|
251
|
-
}
|
|
252
|
-
return table;
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
MsSqlTableAliasCompiler =
|
|
256
|
-
|
|
257
|
-
(0, di_1.
|
|
258
|
-
|
|
259
|
-
|
|
64
|
+
THEN `.replace(/(\r\n|\n|\r)/gm, ''),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
exports.MsSqlOnDuplicateQueryCompiler = MsSqlOnDuplicateQueryCompiler;
|
|
69
|
+
exports.MsSqlOnDuplicateQueryCompiler = MsSqlOnDuplicateQueryCompiler = __decorate([
|
|
70
|
+
(0, di_1.NewInstance)()
|
|
71
|
+
], MsSqlOnDuplicateQueryCompiler);
|
|
72
|
+
let MsSqlInsertQueryCompiler = class MsSqlInsertQueryCompiler extends orm_sql_1.SqlInsertQueryCompiler {
|
|
73
|
+
constructor(container, builder) {
|
|
74
|
+
super(container, builder);
|
|
75
|
+
this.isDuplicate = false;
|
|
76
|
+
this.isDuplicate = this._builder.DuplicateQueryBuilder !== null && this._builder.DuplicateQueryBuilder !== undefined;
|
|
77
|
+
}
|
|
78
|
+
compile() {
|
|
79
|
+
if (this._builder.Ignore) {
|
|
80
|
+
throw new orm_1.OrmException(`mssql insert or ignore is not supported`);
|
|
81
|
+
}
|
|
82
|
+
const into = this.into();
|
|
83
|
+
const columns = this.columns();
|
|
84
|
+
const values = this.values();
|
|
85
|
+
const iBindings = values.bindings;
|
|
86
|
+
const iExpression = `${into} ${columns} ${values.data}`;
|
|
87
|
+
const dResult = super.upsort();
|
|
88
|
+
return {
|
|
89
|
+
bindings: dResult.bindings.concat(iBindings),
|
|
90
|
+
expression: dResult.expression + iExpression + '; SELECT SCOPE_IDENTITY() as ID;',
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
into() {
|
|
94
|
+
return `INSERT ${this.isDuplicate ? '' : `INTO ${this._container.resolve(orm_1.TableAliasCompiler).compile(this._builder)}`} `;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.MsSqlInsertQueryCompiler = MsSqlInsertQueryCompiler;
|
|
98
|
+
exports.MsSqlInsertQueryCompiler = MsSqlInsertQueryCompiler = __decorate([
|
|
99
|
+
(0, di_1.NewInstance)(),
|
|
100
|
+
__metadata("design:paramtypes", [Object, orm_1.InsertQueryBuilder])
|
|
101
|
+
], MsSqlInsertQueryCompiler);
|
|
102
|
+
let MsSqlTableExistsCompiler = class MsSqlTableExistsCompiler {
|
|
103
|
+
constructor(builder) {
|
|
104
|
+
this.builder = builder;
|
|
105
|
+
if (builder === null) {
|
|
106
|
+
throw new Error('table exists query builder cannot be null');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
compile() {
|
|
110
|
+
const bindings = [this.builder.Table];
|
|
111
|
+
let expression = '';
|
|
112
|
+
if (this.builder.Database) {
|
|
113
|
+
bindings.push(this.builder.Database);
|
|
114
|
+
expression = `SELECT TOP(1) * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=? AND TABLE_CATALOG=? ORDER BY TABLE_NAME`;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
expression = `SELECT TOP(1) * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=? ORDER BY TABLE_NAME`;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
bindings,
|
|
121
|
+
expression,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
exports.MsSqlTableExistsCompiler = MsSqlTableExistsCompiler;
|
|
126
|
+
exports.MsSqlTableExistsCompiler = MsSqlTableExistsCompiler = __decorate([
|
|
127
|
+
(0, di_1.NewInstance)(),
|
|
128
|
+
__metadata("design:paramtypes", [orm_1.TableExistsQueryBuilder])
|
|
129
|
+
], MsSqlTableExistsCompiler);
|
|
130
|
+
let MsSqlLimitCompiler = class MsSqlLimitCompiler extends orm_sql_1.SqlLimitQueryCompiler {
|
|
131
|
+
compile() {
|
|
132
|
+
const limits = this._builder.getLimits();
|
|
133
|
+
const bindings = [];
|
|
134
|
+
let stmt = '';
|
|
135
|
+
if (limits.limit > 0) {
|
|
136
|
+
stmt += ` OFFSET ? ROWS`;
|
|
137
|
+
bindings.push(Math.max(limits.offset, 0));
|
|
138
|
+
stmt += ` FETCH NEXT ? ROWS ONLY`;
|
|
139
|
+
bindings.push(limits.limit);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
bindings,
|
|
143
|
+
expression: stmt,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
exports.MsSqlLimitCompiler = MsSqlLimitCompiler;
|
|
148
|
+
exports.MsSqlLimitCompiler = MsSqlLimitCompiler = __decorate([
|
|
149
|
+
(0, di_1.NewInstance)()
|
|
150
|
+
], MsSqlLimitCompiler);
|
|
151
|
+
let MsSqlOrderByCompiler = class MsSqlOrderByCompiler extends orm_sql_1.SqlOrderByQueryCompiler {
|
|
152
|
+
compile() {
|
|
153
|
+
const sort = this._builder.getSort();
|
|
154
|
+
let stmt = '';
|
|
155
|
+
const bindings = [];
|
|
156
|
+
if (sort) {
|
|
157
|
+
stmt = ` ORDER BY \`${sort.column}\` ${sort.order.toLowerCase() === 'asc' ? 'ASC' : 'DESC'}`;
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
bindings,
|
|
161
|
+
expression: stmt,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
exports.MsSqlOrderByCompiler = MsSqlOrderByCompiler;
|
|
166
|
+
exports.MsSqlOrderByCompiler = MsSqlOrderByCompiler = __decorate([
|
|
167
|
+
(0, di_1.NewInstance)()
|
|
168
|
+
], MsSqlOrderByCompiler);
|
|
169
|
+
let MsSqlTableQueryCompiler = class MsSqlTableQueryCompiler extends orm_sql_1.SqlTableQueryCompiler {
|
|
170
|
+
compile() {
|
|
171
|
+
const _table = this._table();
|
|
172
|
+
const _columns = this._columns();
|
|
173
|
+
const _keys = [this._foreignKeys()];
|
|
174
|
+
const _unique = this.builder.Columns.filter((c) => c.Unique).map((c) => c.Name);
|
|
175
|
+
return [
|
|
176
|
+
{
|
|
177
|
+
bindings: [],
|
|
178
|
+
expression: `${_table} (${_columns} ${_unique.length !== 0 ? `, UNIQUE(${_unique.join(',')}) ` : ''} ${_keys ? ',' + _keys.filter((k) => k && k !== '').join(',') : ''})`,
|
|
179
|
+
},
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
_columns() {
|
|
183
|
+
return this.builder.Columns.map((c) => {
|
|
184
|
+
const expr = this.container.resolve(orm_1.ColumnQueryCompiler, [c]).compile().expression;
|
|
185
|
+
if (c.PrimaryKey) {
|
|
186
|
+
return expr + ' PRIMARY KEY';
|
|
187
|
+
}
|
|
188
|
+
return expr;
|
|
189
|
+
}).join(',');
|
|
190
|
+
}
|
|
191
|
+
_foreignKeys() {
|
|
192
|
+
return this.builder.ForeignKeys.map((f) => {
|
|
193
|
+
return this.container.resolve(orm_1.ForeignKeyQueryCompiler, [f]).compile().expression;
|
|
194
|
+
}).join(',');
|
|
195
|
+
}
|
|
196
|
+
_table() {
|
|
197
|
+
return `CREATE${this.builder.Temporary ? ' TEMPORARY ' : ' '}TABLE ${this.builder.CheckExists ? 'IF NOT EXISTS ' : ''}${this.container.resolve(orm_1.TableAliasCompiler).compile(this.builder)}`;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
exports.MsSqlTableQueryCompiler = MsSqlTableQueryCompiler;
|
|
201
|
+
exports.MsSqlTableQueryCompiler = MsSqlTableQueryCompiler = __decorate([
|
|
202
|
+
(0, di_1.NewInstance)()
|
|
203
|
+
], MsSqlTableQueryCompiler);
|
|
204
|
+
let MsSqlColumnQueryCompiler = class MsSqlColumnQueryCompiler extends orm_sql_1.SqlColumnQueryCompiler {
|
|
205
|
+
constructor(builder) {
|
|
206
|
+
super(builder);
|
|
207
|
+
this.builder = builder;
|
|
208
|
+
// MSSQL usess this expression for AUTO_INCREMENT
|
|
209
|
+
this._statementsMappings.autoincrement = () => `IDENTITY(1,1)`;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
exports.MsSqlColumnQueryCompiler = MsSqlColumnQueryCompiler;
|
|
213
|
+
exports.MsSqlColumnQueryCompiler = MsSqlColumnQueryCompiler = __decorate([
|
|
214
|
+
(0, di_1.NewInstance)(),
|
|
215
|
+
__metadata("design:paramtypes", [orm_1.ColumnQueryBuilder])
|
|
216
|
+
], MsSqlColumnQueryCompiler);
|
|
217
|
+
let MsSqlDeleteQueryCompiler = class MsSqlDeleteQueryCompiler extends orm_sql_1.SqlDeleteQueryCompiler {
|
|
218
|
+
compile() {
|
|
219
|
+
const _bindings = [];
|
|
220
|
+
const _from = this.from();
|
|
221
|
+
const _where = this.where(this._builder);
|
|
222
|
+
const _expression = _from + (_where.expression ? ` WHERE ${_where.expression}` : '');
|
|
223
|
+
_bindings.push(..._where.bindings);
|
|
224
|
+
return {
|
|
225
|
+
bindings: _bindings,
|
|
226
|
+
expression: _expression.trim(),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
from() {
|
|
230
|
+
const lBuilder = this._builder;
|
|
231
|
+
const limits = lBuilder.getLimits();
|
|
232
|
+
return `DELETE ${limits.limit > 0 ? `TOP ${limits.limit} ` : ''}FROM ${this._container.resolve(orm_1.TableAliasCompiler).compile(this._builder)}`;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
exports.MsSqlDeleteQueryCompiler = MsSqlDeleteQueryCompiler;
|
|
236
|
+
exports.MsSqlDeleteQueryCompiler = MsSqlDeleteQueryCompiler = __decorate([
|
|
237
|
+
(0, di_1.NewInstance)()
|
|
238
|
+
], MsSqlDeleteQueryCompiler);
|
|
239
|
+
let MsSqlTableAliasCompiler = class MsSqlTableAliasCompiler {
|
|
240
|
+
compile(builder, tbl) {
|
|
241
|
+
let table = '';
|
|
242
|
+
if (builder.Database) {
|
|
243
|
+
table += `\`${builder.Database}\`.`;
|
|
244
|
+
}
|
|
245
|
+
if (builder.Driver.Options.Options?.Schema) {
|
|
246
|
+
table += `\`${builder.Driver.Options.Options?.Schema}\`.`;
|
|
247
|
+
}
|
|
248
|
+
table += `\`${tbl ? tbl : builder.Table}\``;
|
|
249
|
+
if (builder.TableAlias) {
|
|
250
|
+
table += ` as \`${builder.TableAlias}\``;
|
|
251
|
+
}
|
|
252
|
+
return table;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
exports.MsSqlTableAliasCompiler = MsSqlTableAliasCompiler;
|
|
256
|
+
exports.MsSqlTableAliasCompiler = MsSqlTableAliasCompiler = __decorate([
|
|
257
|
+
(0, di_1.Inject)(configuration_1.Configuration),
|
|
258
|
+
(0, di_1.NewInstance)()
|
|
259
|
+
], MsSqlTableAliasCompiler);
|
|
260
260
|
//# sourceMappingURL=compilers.js.map
|