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