@spinajs/orm-sql 2.0.485 → 2.0.487
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 +27 -4
- package/lib/cjs/compilers.d.ts.map +1 -1
- package/lib/cjs/compilers.js +80 -18
- package/lib/cjs/compilers.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +1 -13
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/statements.d.ts +31 -2
- package/lib/cjs/statements.d.ts.map +1 -1
- package/lib/cjs/statements.js +141 -62
- package/lib/cjs/statements.js.map +1 -1
- package/lib/mjs/compilers.d.ts +27 -4
- package/lib/mjs/compilers.d.ts.map +1 -1
- package/lib/mjs/compilers.js +81 -19
- package/lib/mjs/compilers.js.map +1 -1
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +3 -15
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/statements.d.ts +31 -2
- package/lib/mjs/statements.d.ts.map +1 -1
- package/lib/mjs/statements.js +119 -41
- package/lib/mjs/statements.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.SqlDriver = void 0;
|
|
18
|
-
const builders_js_1 = require("./builders.js");
|
|
19
18
|
const compilers_js_1 = require("./compilers.js");
|
|
20
19
|
/* eslint-disable prettier/prettier */
|
|
21
20
|
const converters_js_1 = require("./converters.js");
|
|
@@ -23,6 +22,7 @@ const orm_1 = require("@spinajs/orm");
|
|
|
23
22
|
const statements_js_1 = require("./statements.js");
|
|
24
23
|
const log_common_1 = require("@spinajs/log-common");
|
|
25
24
|
__exportStar(require("./compilers.js"), exports);
|
|
25
|
+
__exportStar(require("./builders.js"), exports);
|
|
26
26
|
__exportStar(require("./statements.js"), exports);
|
|
27
27
|
class SqlDriver extends orm_1.OrmDriver {
|
|
28
28
|
/**
|
|
@@ -86,34 +86,22 @@ class SqlDriver extends orm_1.OrmDriver {
|
|
|
86
86
|
this.Container.register(statements_js_1.SqlDateTimeWrapper).as(orm_1.DateTimeWrapper);
|
|
87
87
|
this.Container.register(statements_js_1.SqlDateWrapper).as(orm_1.DateWrapper);
|
|
88
88
|
this.Container.register(statements_js_1.SqlLazyQueryStatement).as(orm_1.LazyQueryStatement);
|
|
89
|
-
this.Container.register(compilers_js_1.SqlWithRecursiveCompiler).as(orm_1.RecursiveQueryCompiler);
|
|
90
89
|
this.Container.register(compilers_js_1.SqlSelectQueryCompiler).as(orm_1.SelectQueryCompiler);
|
|
91
90
|
this.Container.register(compilers_js_1.SqlUpdateQueryCompiler).as(orm_1.UpdateQueryCompiler);
|
|
92
91
|
this.Container.register(compilers_js_1.SqlDeleteQueryCompiler).as(orm_1.DeleteQueryCompiler);
|
|
93
92
|
this.Container.register(compilers_js_1.SqlInsertQueryCompiler).as(orm_1.InsertQueryCompiler);
|
|
94
93
|
this.Container.register(compilers_js_1.SqlDropTableQueryCompiler).as(orm_1.DropTableCompiler);
|
|
95
|
-
this.Container.register(compilers_js_1.SqlTruncateTableQueryCompiler).as(orm_1.TruncateTableQueryCompiler);
|
|
96
94
|
this.Container.register(compilers_js_1.SqlTableQueryCompiler).as(orm_1.TableQueryCompiler);
|
|
97
95
|
this.Container.register(compilers_js_1.SqlOrderByQueryCompiler).as(orm_1.OrderByQueryCompiler);
|
|
98
|
-
this.Container.register(compilers_js_1.SqlOnDuplicateQueryCompiler).as(orm_1.OnDuplicateQueryCompiler);
|
|
99
96
|
this.Container.register(compilers_js_1.SqlIndexQueryCompiler).as(orm_1.IndexQueryCompiler);
|
|
100
97
|
this.Container.register(compilers_js_1.SqlForeignKeyQueryCompiler).as(orm_1.ForeignKeyQueryCompiler);
|
|
101
|
-
this.Container.register(compilers_js_1.SqlColumnQueryCompiler).as(orm_1.ColumnQueryCompiler);
|
|
102
98
|
this.Container.register(compilers_js_1.SqlGroupByCompiler).as(orm_1.GroupByQueryCompiler);
|
|
103
|
-
this.Container.register(compilers_js_1.SqlTableCloneQueryCompiler).as(orm_1.TableCloneQueryCompiler);
|
|
104
|
-
this.Container.register(compilers_js_1.SqlAlterColumnQueryCompiler).as(orm_1.AlterColumnQueryCompiler);
|
|
105
|
-
this.Container.register(compilers_js_1.SqlAlterTableQueryCompiler).as(orm_1.AlterTableQueryCompiler);
|
|
106
99
|
this.Container.register(converters_js_1.SqlSetConverter).as(orm_1.SetValueConverter);
|
|
107
|
-
this.Container.register(compilers_js_1.SqlLimitQueryCompiler).as(orm_1.LimitQueryCompiler);
|
|
108
100
|
this.Container.register(compilers_js_1.SqlTableAliasCompiler).as(orm_1.TableAliasCompiler);
|
|
109
101
|
this.Container.register(converters_js_1.SqlDatetimeValueConverter).as(orm_1.DatetimeValueConverter);
|
|
110
102
|
this.Container.register(converters_js_1.SqlTimeValueConverter).as(orm_1.TimeValueConverter);
|
|
111
103
|
this.Container.register(converters_js_1.SqlBooleanValueConverter).as(orm_1.BooleanValueConverter);
|
|
112
104
|
this.Container.register(statements_js_1.SqlInSetStatement).as(orm_1.InSetStatement);
|
|
113
|
-
this.Container.register(builders_js_1.SqlDefaultValueBuilder).as(orm_1.DefaultValueBuilder);
|
|
114
|
-
this.Container.register(compilers_js_1.SqlDropEventQueryCompiler).as(orm_1.DropEventQueryCompiler);
|
|
115
|
-
this.Container.register(compilers_js_1.SqlEventQueryCompiler).as(orm_1.EventQueryCompiler);
|
|
116
|
-
this.Container.register(compilers_js_1.SqlTableHistoryQueryCompiler).as(orm_1.TableHistoryQueryCompiler);
|
|
117
105
|
this.Container.register(compilers_js_1.SqlRawSchemaQueryCompiler).as(orm_1.RawSchemaQueryCompiler);
|
|
118
106
|
this.Container.register(compilers_js_1.SqlDropViewQueryCompiler).as(orm_1.DropViewCompiler);
|
|
119
107
|
}
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA8V;AAC9V,sCAAsC;AACtC,mDAA8H;AAC9H,sCAA4sB;AAC5sB,mDAAgX;AAChX,oDAA2C;AAE3C,iDAA+B;AAC/B,gDAA8B;AAC9B,kDAAgC;AAEhC,MAAsB,SAAU,SAAQ,eAAS;IAG/C;;;;;;;;;;;OAWG;IACO,QAAQ,CAAC,UAAkB,EAAE,QAAmB,EAAE,OAAqB;QAC/E,+EAA+E;QAC/E,0EAA0E;QAC1E,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,CAAC;IAChI,CAAC;IAEM,OAAO,CAAC,OAAqB;QAClC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;YAChC,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YAE3G,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC5B,0BAA0B;gBAC1B,OAAO,OAAO,CAAC,GAAG,C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AC,CAAC,EAAE,CAAC,uBAAiB,CAAC,CAAC;QAC/D,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,oCAAqB,CAAC,CAAC,EAAE,CAAC,wBAAkB,CAAC,CAAC;QACtE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,yCAAyB,CAAC,CAAC,EAAE,CAAC,4BAAsB,CAAC,CAAC;QAC9E,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,qCAAqB,CAAC,CAAC,EAAE,CAAC,wBAAkB,CAAC,CAAC;QACtE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,wCAAwB,CAAC,CAAC,EAAE,CAAC,2BAAqB,CAAC,CAAC;QAC5E,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,iCAAiB,CAAC,CAAC,EAAE,CAAC,oBAAc,CAAC,CAAC;QAG9D,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,wCAAyB,CAAC,CAAC,EAAE,CAAC,4BAAsB,CAAC,CAAC;QAE9E,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,uCAAwB,CAAC,CAAC,EAAE,CAAC,sBAAgB,CAAC,CAAC;IACzE,CAAC;CACF;AA7FD,8BA6FC"}
|
package/lib/cjs/statements.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { IQueryStatement, LazyQueryStatement, QueryBuilder, SelectQueryBuilder, WhereBuilder } from '@spinajs/orm';
|
|
2
|
-
|
|
1
|
+
import { IQueryStatement, LazyQueryStatement, QueryBuilder, SelectQueryBuilder, WhereBuilder, BetweenStatement, JoinStatement, ColumnStatement, ColumnRawStatement, InStatement, InSetStatement, IQueryStatementResult, RawQueryStatement, WhereStatement, ExistsQueryStatement, ColumnMethodStatement, WhereQueryStatement, WithRecursiveStatement, GroupByStatement, DateWrapper, DateTimeWrapper, IdentifierQuoter } from '@spinajs/orm';
|
|
2
|
+
/**
|
|
3
|
+
* Exported so driver packages can wrap a column exactly the way the shared
|
|
4
|
+
* statements do — a driver writing its own dialect statement must not have to
|
|
5
|
+
* re-derive alias rules. Quoting itself comes from the driver's own
|
|
6
|
+
* {@link IdentifierQuoter}, which is why it is a parameter rather than an import.
|
|
7
|
+
*/
|
|
8
|
+
export declare function _columnWrap(quoter: IdentifierQuoter, column: string, tableAlias: string | undefined, isAggregate?: boolean): string;
|
|
3
9
|
export declare class SqlRawStatement extends RawQueryStatement {
|
|
4
10
|
clone(): SqlRawStatement;
|
|
5
11
|
build(): IQueryStatementResult;
|
|
@@ -13,41 +19,64 @@ export declare class SqlWithRecursiveStatement extends WithRecursiveStatement {
|
|
|
13
19
|
build(): IQueryStatementResult;
|
|
14
20
|
}
|
|
15
21
|
export declare class SqlBetweenStatement extends BetweenStatement {
|
|
22
|
+
Quoter: IdentifierQuoter;
|
|
16
23
|
clone(): SqlBetweenStatement;
|
|
17
24
|
build(): IQueryStatementResult;
|
|
18
25
|
}
|
|
19
26
|
export declare class SqlGroupByStatement extends GroupByStatement {
|
|
27
|
+
Quoter: IdentifierQuoter;
|
|
20
28
|
clone(): SqlGroupByStatement;
|
|
21
29
|
build(): IQueryStatementResult;
|
|
22
30
|
}
|
|
23
31
|
export declare class SqlWhereStatement extends WhereStatement {
|
|
32
|
+
Quoter: IdentifierQuoter;
|
|
24
33
|
clone<T extends QueryBuilder | SelectQueryBuilder | WhereBuilder<any>>(_builder?: T): SqlWhereStatement;
|
|
25
34
|
build(): IQueryStatementResult;
|
|
26
35
|
}
|
|
27
36
|
export declare class SqlJoinStatement extends JoinStatement {
|
|
37
|
+
Quoter: IdentifierQuoter;
|
|
28
38
|
clone<T extends QueryBuilder | SelectQueryBuilder | WhereBuilder<any>>(parent?: T): IQueryStatement;
|
|
29
39
|
build(): IQueryStatementResult;
|
|
30
40
|
}
|
|
31
41
|
export declare class SqlInStatement extends InStatement {
|
|
42
|
+
Quoter: IdentifierQuoter;
|
|
32
43
|
clone<T extends QueryBuilder | SelectQueryBuilder | WhereBuilder<any>>(parent?: T): IQueryStatement;
|
|
33
44
|
build(): IQueryStatementResult;
|
|
34
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Portable membership test against a delimited `@Set()` column.
|
|
48
|
+
*
|
|
49
|
+
* Plain equality plus three LIKE patterns — value alone, first, last, in the middle —
|
|
50
|
+
* so it needs no dialect function and no string concatenation operator ( `||` on
|
|
51
|
+
* SQLite, `+` on MSSQL, `CONCAT()` on MySQL: there is no spelling all three accept ).
|
|
52
|
+
* Every driver that ships with spinajs replaces this with its native form; this is
|
|
53
|
+
* what an unknown driver gets, and it is correct rather than fast.
|
|
54
|
+
*
|
|
55
|
+
* This used to emit `FIND_IN_SET`, which exists only in MySQL — on SQLite and MSSQL
|
|
56
|
+
* every `whereInSet` ( and therefore every `withRole` ) died with "no such function"
|
|
57
|
+
* at query time.
|
|
58
|
+
*/
|
|
35
59
|
export declare class SqlInSetStatement extends InSetStatement {
|
|
60
|
+
Quoter: IdentifierQuoter;
|
|
36
61
|
build(): IQueryStatementResult;
|
|
37
62
|
clone(): IQueryStatement;
|
|
38
63
|
}
|
|
39
64
|
export declare class SqlColumnStatement extends ColumnStatement {
|
|
65
|
+
Quoter: IdentifierQuoter;
|
|
40
66
|
clone(): SqlColumnStatement;
|
|
41
67
|
build(): IQueryStatementResult;
|
|
42
68
|
}
|
|
43
69
|
export declare class SqlColumnMethodStatement extends ColumnMethodStatement {
|
|
70
|
+
Quoter: IdentifierQuoter;
|
|
44
71
|
clone(): SqlColumnMethodStatement;
|
|
45
72
|
build(): IQueryStatementResult;
|
|
46
73
|
}
|
|
47
74
|
export declare abstract class SqlDateWrapper extends DateWrapper {
|
|
75
|
+
Quoter: IdentifierQuoter;
|
|
48
76
|
wrap(): string;
|
|
49
77
|
}
|
|
50
78
|
export declare abstract class SqlDateTimeWrapper extends DateTimeWrapper {
|
|
79
|
+
Quoter: IdentifierQuoter;
|
|
51
80
|
wrap(): string;
|
|
52
81
|
}
|
|
53
82
|
export declare class SqlColumnRawStatement extends ColumnRawStatement {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/statements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAc,kBAAkB,EAAE,YAAY,EAAE,kBAAkB,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/statements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAc,kBAAkB,EAAE,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAA0B,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,kBAAkB,EAAE,WAAW,EAAE,cAAc,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,cAAc,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,gBAAgB,EAAY,WAAW,EAAE,eAAe,EAAgF,gBAAgB,EAAwC,MAAM,cAAc,CAAC;AAO9kB;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,CAMnI;AAgBD,qBACa,eAAgB,SAAQ,iBAAiB;IAC7C,KAAK,IAAI,eAAe;IAIxB,KAAK,IAAI,qBAAqB;CAMtC;AAED,qBACa,qBAAsB,SAAQ,kBAAkB;IAEpD,KAAK,IAAI,qBAAqB;IAIrC,KAAK,IAAI,qBAAqB;CAgB/B;AAED,qBACa,yBAA0B,SAAQ,sBAAsB;IAC5D,KAAK,IAAI,yBAAyB;IAIlC,KAAK,IAAI,qBAAqB;CAgDtC;AAED,qBACa,mBAAoB,SAAQ,gBAAgB;IAEhD,MAAM,EAAE,gBAAgB,CAAC;IAEzB,KAAK,IAAI,mBAAmB;IAI5B,KAAK,IAAI,qBAAqB;CAQtC;AAED,qBACa,mBAAoB,SAAQ,gBAAgB;IAEhD,MAAM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CAAC;IAEzB,IAAI,IAAI,MAAM;CAOtB;AAED,8BAAsB,kBAAmB,SAAQ,eAAe;IAEvD,MAAM,EAAE,gBAAgB,CAAC;IAEzB,IAAI,IAAI,MAAM;CAOtB;AAED,qBACa,qBAAsB,SAAQ,kBAAkB;IACpD,KAAK,IAAI,qBAAqB;IAI9B,KAAK,IAAI,qBAAqB;CAMtC;AAED,qBACa,sBAAuB,SAAQ,mBAAmB;IACtD,KAAK,CAAC,CAAC,SAAS,YAAY,GAAG,kBAAkB,GAAG,YAAY,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,eAAe;IAMpG,KAAK;;;;CASb;AAED,qBACa,uBAAwB,SAAQ,oBAAoB;IACxD,KAAK,CAAC,CAAC,SAAS,YAAY,GAAG,kBAAkB,GAAG,YAAY,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,eAAe;IAUpG,KAAK,IAAI,qBAAqB;CAetC"}
|
package/lib/cjs/statements.js
CHANGED
|
@@ -5,22 +5,43 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
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
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
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
|
+
};
|
|
8
11
|
var SqlRawStatement_1, SqlLazyQueryStatement_1, SqlWithRecursiveStatement_1, SqlBetweenStatement_1, SqlGroupByStatement_1, SqlWhereStatement_1, SqlJoinStatement_1, SqlInStatement_1, SqlInSetStatement_1, SqlColumnStatement_1, SqlColumnMethodStatement_1, SqlColumnRawStatement_1, SqlWhereQueryStatement_1, SqlExistsQueryStatement_1;
|
|
9
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
13
|
exports.SqlExistsQueryStatement = exports.SqlWhereQueryStatement = exports.SqlColumnRawStatement = exports.SqlDateTimeWrapper = exports.SqlDateWrapper = exports.SqlColumnMethodStatement = exports.SqlColumnStatement = exports.SqlInSetStatement = exports.SqlInStatement = exports.SqlJoinStatement = exports.SqlWhereStatement = exports.SqlGroupByStatement = exports.SqlBetweenStatement = exports.SqlWithRecursiveStatement = exports.SqlLazyQueryStatement = exports.SqlRawStatement = void 0;
|
|
14
|
+
exports._columnWrap = _columnWrap;
|
|
11
15
|
const orm_1 = require("@spinajs/orm");
|
|
12
16
|
/* eslint-disable prettier/prettier */
|
|
13
17
|
const compilers_js_1 = require("./compilers.js");
|
|
14
18
|
const di_1 = require("@spinajs/di");
|
|
15
|
-
const orm_2 = require("@spinajs/orm");
|
|
16
19
|
const exceptions_1 = require("@spinajs/exceptions");
|
|
17
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Exported so driver packages can wrap a column exactly the way the shared
|
|
22
|
+
* statements do — a driver writing its own dialect statement must not have to
|
|
23
|
+
* re-derive alias rules. Quoting itself comes from the driver's own
|
|
24
|
+
* {@link IdentifierQuoter}, which is why it is a parameter rather than an import.
|
|
25
|
+
*/
|
|
26
|
+
function _columnWrap(quoter, column, tableAlias, isAggregate) {
|
|
18
27
|
if (tableAlias && !isAggregate) {
|
|
19
|
-
return `${
|
|
28
|
+
return `${quoter.quote(tableAlias)}.${quoter.quote(column)}`;
|
|
20
29
|
}
|
|
21
|
-
return
|
|
30
|
+
return quoter.quote(column);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Copies the injected quoter onto a hand-constructed clone.
|
|
34
|
+
*
|
|
35
|
+
* `clone()` builds statements with `new`, which bypasses the container — so property
|
|
36
|
+
* injection never runs on a clone and `this.Quoter` would be undefined the moment the
|
|
37
|
+
* cloned statement compiled. Every clone of a statement that quotes anything goes
|
|
38
|
+
* through here.
|
|
39
|
+
*/
|
|
40
|
+
function _carryQuoter(clone, source) {
|
|
41
|
+
clone.Quoter = source.Quoter;
|
|
42
|
+
return clone;
|
|
22
43
|
}
|
|
23
|
-
let SqlRawStatement = SqlRawStatement_1 = class SqlRawStatement extends
|
|
44
|
+
let SqlRawStatement = SqlRawStatement_1 = class SqlRawStatement extends orm_1.RawQueryStatement {
|
|
24
45
|
clone() {
|
|
25
46
|
return new SqlRawStatement_1(this._query, this._bindings);
|
|
26
47
|
}
|
|
@@ -55,7 +76,7 @@ exports.SqlLazyQueryStatement = SqlLazyQueryStatement;
|
|
|
55
76
|
exports.SqlLazyQueryStatement = SqlLazyQueryStatement = SqlLazyQueryStatement_1 = __decorate([
|
|
56
77
|
(0, di_1.NewInstance)()
|
|
57
78
|
], SqlLazyQueryStatement);
|
|
58
|
-
let SqlWithRecursiveStatement = SqlWithRecursiveStatement_1 = class SqlWithRecursiveStatement extends
|
|
79
|
+
let SqlWithRecursiveStatement = SqlWithRecursiveStatement_1 = class SqlWithRecursiveStatement extends orm_1.WithRecursiveStatement {
|
|
59
80
|
clone() {
|
|
60
81
|
return new SqlWithRecursiveStatement_1(this.container, this._name, this._query, this._rcKeyName, this._pkName);
|
|
61
82
|
}
|
|
@@ -75,7 +96,7 @@ let SqlWithRecursiveStatement = SqlWithRecursiveStatement_1 = class SqlWithRecur
|
|
|
75
96
|
// common table expression rather than a model, so there is no descriptor to read a driver
|
|
76
97
|
// from. It is the source query's own driver by construction — a CTE lives in the same
|
|
77
98
|
// statement, and therefore the same connection, as the query that declares it.
|
|
78
|
-
const joinStmt = this.container.resolve(
|
|
99
|
+
const joinStmt = this.container.resolve(orm_1.JoinStatement, [
|
|
79
100
|
{
|
|
80
101
|
builder: this._query,
|
|
81
102
|
sourceModel: this._query.Model,
|
|
@@ -110,28 +131,32 @@ exports.SqlWithRecursiveStatement = SqlWithRecursiveStatement;
|
|
|
110
131
|
exports.SqlWithRecursiveStatement = SqlWithRecursiveStatement = SqlWithRecursiveStatement_1 = __decorate([
|
|
111
132
|
(0, di_1.NewInstance)()
|
|
112
133
|
], SqlWithRecursiveStatement);
|
|
113
|
-
let SqlBetweenStatement = SqlBetweenStatement_1 = class SqlBetweenStatement extends
|
|
134
|
+
let SqlBetweenStatement = SqlBetweenStatement_1 = class SqlBetweenStatement extends orm_1.BetweenStatement {
|
|
114
135
|
clone() {
|
|
115
|
-
return new SqlBetweenStatement_1(this._column, this._val, this._not, this._tableAlias);
|
|
136
|
+
return _carryQuoter(new SqlBetweenStatement_1(this._column, this._val, this._not, this._tableAlias), this);
|
|
116
137
|
}
|
|
117
138
|
build() {
|
|
118
139
|
const exprr = this._not ? 'NOT BETWEEN' : 'BETWEEN';
|
|
119
140
|
return {
|
|
120
141
|
Bindings: this._val,
|
|
121
|
-
Statements: [`${_columnWrap(this._column, this._tableAlias)} ${exprr} ? AND ?`],
|
|
142
|
+
Statements: [`${_columnWrap(this.Quoter, this._column, this._tableAlias)} ${exprr} ? AND ?`],
|
|
122
143
|
};
|
|
123
144
|
}
|
|
124
145
|
};
|
|
125
146
|
exports.SqlBetweenStatement = SqlBetweenStatement;
|
|
147
|
+
__decorate([
|
|
148
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
149
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
150
|
+
], SqlBetweenStatement.prototype, "Quoter", void 0);
|
|
126
151
|
exports.SqlBetweenStatement = SqlBetweenStatement = SqlBetweenStatement_1 = __decorate([
|
|
127
152
|
(0, di_1.NewInstance)()
|
|
128
153
|
], SqlBetweenStatement);
|
|
129
|
-
let SqlGroupByStatement = SqlGroupByStatement_1 = class SqlGroupByStatement extends
|
|
154
|
+
let SqlGroupByStatement = SqlGroupByStatement_1 = class SqlGroupByStatement extends orm_1.GroupByStatement {
|
|
130
155
|
clone() {
|
|
131
|
-
return new SqlGroupByStatement_1(this._expr, this.TableAlias);
|
|
156
|
+
return _carryQuoter(new SqlGroupByStatement_1(this._expr, this.TableAlias), this);
|
|
132
157
|
}
|
|
133
158
|
build() {
|
|
134
|
-
if (this._expr instanceof
|
|
159
|
+
if (this._expr instanceof orm_1.RawQuery) {
|
|
135
160
|
return {
|
|
136
161
|
Bindings: this._expr.Bindings ?? [],
|
|
137
162
|
Statements: [`${this._expr.Query}`],
|
|
@@ -140,38 +165,42 @@ let SqlGroupByStatement = SqlGroupByStatement_1 = class SqlGroupByStatement exte
|
|
|
140
165
|
else {
|
|
141
166
|
return {
|
|
142
167
|
Bindings: [],
|
|
143
|
-
Statements: [
|
|
168
|
+
Statements: [this.Quoter.quote(this._expr)],
|
|
144
169
|
};
|
|
145
170
|
}
|
|
146
171
|
}
|
|
147
172
|
};
|
|
148
173
|
exports.SqlGroupByStatement = SqlGroupByStatement;
|
|
174
|
+
__decorate([
|
|
175
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
176
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
177
|
+
], SqlGroupByStatement.prototype, "Quoter", void 0);
|
|
149
178
|
exports.SqlGroupByStatement = SqlGroupByStatement = SqlGroupByStatement_1 = __decorate([
|
|
150
179
|
(0, di_1.NewInstance)()
|
|
151
180
|
], SqlGroupByStatement);
|
|
152
|
-
let SqlWhereStatement = SqlWhereStatement_1 = class SqlWhereStatement extends
|
|
181
|
+
let SqlWhereStatement = SqlWhereStatement_1 = class SqlWhereStatement extends orm_1.WhereStatement {
|
|
153
182
|
clone(_builder) {
|
|
154
|
-
return new SqlWhereStatement_1(this._column, this._operator, this._value, this._builder);
|
|
183
|
+
return _carryQuoter(new SqlWhereStatement_1(this._column, this._operator, this._value, this._builder), this);
|
|
155
184
|
}
|
|
156
185
|
build() {
|
|
157
|
-
const isNullableQuery = this._operator ===
|
|
186
|
+
const isNullableQuery = this._operator === orm_1.SqlOperator.NOT_NULL || this._operator === orm_1.SqlOperator.NULL;
|
|
158
187
|
const binding = isNullableQuery ? '' : ' ?';
|
|
159
188
|
let column = this._column;
|
|
160
189
|
let val = this._value;
|
|
161
190
|
if (this._model) {
|
|
162
|
-
const desc = (0,
|
|
191
|
+
const desc = (0, orm_1.extractModelDescriptor)(this._model);
|
|
163
192
|
const rel = desc.Relations.get(column);
|
|
164
193
|
if (rel) {
|
|
165
194
|
column = rel.ForeignKey;
|
|
166
195
|
}
|
|
167
196
|
}
|
|
168
|
-
if (column instanceof
|
|
197
|
+
if (column instanceof orm_1.Wrap) {
|
|
169
198
|
const wrapper = this._container.resolve(column.Wrapper, [column.Column, this._builder.TableAlias]);
|
|
170
199
|
column = wrapper.wrap();
|
|
171
200
|
}
|
|
172
201
|
else {
|
|
173
|
-
column = _columnWrap(column, this._builder.TableAlias, this.IsAggregate);
|
|
174
|
-
if (val instanceof
|
|
202
|
+
column = _columnWrap(this.Quoter, column, this._builder.TableAlias, this.IsAggregate);
|
|
203
|
+
if (val instanceof orm_1.ModelBase) {
|
|
175
204
|
// A composite key unwraps to a tuple, which would bind an array into a single `?`.
|
|
176
205
|
const pk = val.PrimaryKeyValue;
|
|
177
206
|
if (Array.isArray(pk)) {
|
|
@@ -180,7 +209,7 @@ let SqlWhereStatement = SqlWhereStatement_1 = class SqlWhereStatement extends or
|
|
|
180
209
|
val = pk;
|
|
181
210
|
}
|
|
182
211
|
else {
|
|
183
|
-
const dsc = (0,
|
|
212
|
+
const dsc = (0, orm_1.extractModelDescriptor)(this._model);
|
|
184
213
|
let converter = null;
|
|
185
214
|
if (dsc && dsc.Converters.has(this._column)) {
|
|
186
215
|
converter = this._container.resolve(dsc.Converters.get(this._column).Class);
|
|
@@ -204,15 +233,19 @@ let SqlWhereStatement = SqlWhereStatement_1 = class SqlWhereStatement extends or
|
|
|
204
233
|
}
|
|
205
234
|
};
|
|
206
235
|
exports.SqlWhereStatement = SqlWhereStatement;
|
|
236
|
+
__decorate([
|
|
237
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
238
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
239
|
+
], SqlWhereStatement.prototype, "Quoter", void 0);
|
|
207
240
|
exports.SqlWhereStatement = SqlWhereStatement = SqlWhereStatement_1 = __decorate([
|
|
208
241
|
(0, di_1.NewInstance)()
|
|
209
242
|
], SqlWhereStatement);
|
|
210
|
-
let SqlJoinStatement = SqlJoinStatement_1 = class SqlJoinStatement extends
|
|
243
|
+
let SqlJoinStatement = SqlJoinStatement_1 = class SqlJoinStatement extends orm_1.JoinStatement {
|
|
211
244
|
clone(parent) {
|
|
212
|
-
return new SqlJoinStatement_1({
|
|
245
|
+
return _carryQuoter(new SqlJoinStatement_1({
|
|
213
246
|
...this._options,
|
|
214
247
|
builder: parent ?? this._options.builder,
|
|
215
|
-
});
|
|
248
|
+
}), this);
|
|
216
249
|
}
|
|
217
250
|
build() {
|
|
218
251
|
const method = this._options.method === orm_1.JoinMethod.RECURSIVE ? orm_1.JoinMethod.INNER : this._options.method ?? orm_1.JoinMethod.LEFT;
|
|
@@ -222,8 +255,8 @@ let SqlJoinStatement = SqlJoinStatement_1 = class SqlJoinStatement extends orm_2
|
|
|
222
255
|
Statements: [`${method} ${this._options.query.Query}`],
|
|
223
256
|
};
|
|
224
257
|
}
|
|
225
|
-
const sourceModel = this._options.sourceModel ? (0,
|
|
226
|
-
const joinModel = this._options.joinModel ? (0,
|
|
258
|
+
const sourceModel = this._options.sourceModel ? (0, orm_1.extractModelDescriptor)(this._options.sourceModel) : null;
|
|
259
|
+
const joinModel = this._options.joinModel ? (0, orm_1.extractModelDescriptor)(this._options.joinModel) : null;
|
|
227
260
|
const sourceModelDriver = sourceModel ? sourceModel.Driver : this._options.builder ? this._options.builder.Driver : null;
|
|
228
261
|
const joinModelDriver = !joinModel ? this._options.joinTableDriver : joinModel.Driver;
|
|
229
262
|
if (!sourceModelDriver) {
|
|
@@ -258,19 +291,19 @@ let SqlJoinStatement = SqlJoinStatement_1 = class SqlJoinStatement extends orm_2
|
|
|
258
291
|
if (sourceTableAlias) {
|
|
259
292
|
const sourceDb = sourceModelDriver.Options.Database;
|
|
260
293
|
if (sourceDb) {
|
|
261
|
-
sourceTable = `${
|
|
294
|
+
sourceTable = `${this.Quoter.quote(sourceDb)}.${this.Quoter.quote(sourceTable)} as ${this.Quoter.quote(sourceTableAlias)}`;
|
|
262
295
|
}
|
|
263
296
|
else {
|
|
264
|
-
sourceTable = `${
|
|
297
|
+
sourceTable = `${this.Quoter.quote(sourceTable)} as ${this.Quoter.quote(sourceTableAlias)}`;
|
|
265
298
|
}
|
|
266
299
|
}
|
|
267
300
|
if (joinTableAlias) {
|
|
268
301
|
const joinDb = joinModelDriver.Options.Database;
|
|
269
302
|
if (joinDb) {
|
|
270
|
-
joinTable = `${
|
|
303
|
+
joinTable = `${this.Quoter.quote(joinDb)}.${this.Quoter.quote(joinTable)} as ${this.Quoter.quote(joinTableAlias)}`;
|
|
271
304
|
}
|
|
272
305
|
else {
|
|
273
|
-
joinTable = `${
|
|
306
|
+
joinTable = `${this.Quoter.quote(joinTable)} as ${this.Quoter.quote(joinTableAlias)}`;
|
|
274
307
|
}
|
|
275
308
|
}
|
|
276
309
|
// NOTE: only the table alias part of the ON keys is escaped here. The join
|
|
@@ -278,8 +311,8 @@ let SqlJoinStatement = SqlJoinStatement_1 = class SqlJoinStatement extends orm_2
|
|
|
278
311
|
// as-is on purpose: they come from validated relation descriptors and the
|
|
279
312
|
// existing suite asserts the unquoted form, so escaping them would change
|
|
280
313
|
// byte output for normal identifiers.
|
|
281
|
-
const primaryKey = sourceTableAlias ? `${
|
|
282
|
-
const foreignKey = joinTableAlias ? `${
|
|
314
|
+
const primaryKey = sourceTableAlias ? `${this.Quoter.quote(sourceTableAlias)}.${this._options.sourceTablePrimaryKey}` : `${this.Quoter.quote(sourceTable)}.${this._options.sourceTablePrimaryKey}`;
|
|
315
|
+
const foreignKey = joinTableAlias ? `${this.Quoter.quote(joinTableAlias)}.${this._options.joinTableForeignKey}` : `${this.Quoter.quote(joinTable)}.${this._options.joinTableForeignKey}`;
|
|
283
316
|
// Conditions supplied via the join callback (e.g. `.leftJoin(rel, b => b.where('Key', 'x'))`)
|
|
284
317
|
// belong in the JOIN's ON clause, not the main WHERE — otherwise an outer
|
|
285
318
|
// join is silently narrowed to an inner one. We compile the join sub-builder's
|
|
@@ -305,16 +338,20 @@ let SqlJoinStatement = SqlJoinStatement_1 = class SqlJoinStatement extends orm_2
|
|
|
305
338
|
}
|
|
306
339
|
};
|
|
307
340
|
exports.SqlJoinStatement = SqlJoinStatement;
|
|
341
|
+
__decorate([
|
|
342
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
343
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
344
|
+
], SqlJoinStatement.prototype, "Quoter", void 0);
|
|
308
345
|
exports.SqlJoinStatement = SqlJoinStatement = SqlJoinStatement_1 = __decorate([
|
|
309
346
|
(0, di_1.NewInstance)()
|
|
310
347
|
], SqlJoinStatement);
|
|
311
|
-
let SqlInStatement = SqlInStatement_1 = class SqlInStatement extends
|
|
348
|
+
let SqlInStatement = SqlInStatement_1 = class SqlInStatement extends orm_1.InStatement {
|
|
312
349
|
clone(parent) {
|
|
313
|
-
return new SqlInStatement_1(this._column, this._val, this._not, (parent ?? this._builder));
|
|
350
|
+
return _carryQuoter(new SqlInStatement_1(this._column, this._val, this._not, (parent ?? this._builder)), this);
|
|
314
351
|
}
|
|
315
352
|
build() {
|
|
316
353
|
const exprr = this._not ? 'NOT IN' : 'IN';
|
|
317
|
-
|
|
354
|
+
const column = _columnWrap(this.Quoter, this._column, this._builder.TableAlias);
|
|
318
355
|
return {
|
|
319
356
|
Bindings: this._val,
|
|
320
357
|
Statements: [`${column} ${exprr} (${this._val.map(() => '?').join(',')})`],
|
|
@@ -322,31 +359,57 @@ let SqlInStatement = SqlInStatement_1 = class SqlInStatement extends orm_2.InSta
|
|
|
322
359
|
}
|
|
323
360
|
};
|
|
324
361
|
exports.SqlInStatement = SqlInStatement;
|
|
362
|
+
__decorate([
|
|
363
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
364
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
365
|
+
], SqlInStatement.prototype, "Quoter", void 0);
|
|
325
366
|
exports.SqlInStatement = SqlInStatement = SqlInStatement_1 = __decorate([
|
|
326
367
|
(0, di_1.NewInstance)()
|
|
327
368
|
], SqlInStatement);
|
|
328
|
-
|
|
369
|
+
/**
|
|
370
|
+
* Portable membership test against a delimited `@Set()` column.
|
|
371
|
+
*
|
|
372
|
+
* Plain equality plus three LIKE patterns — value alone, first, last, in the middle —
|
|
373
|
+
* so it needs no dialect function and no string concatenation operator ( `||` on
|
|
374
|
+
* SQLite, `+` on MSSQL, `CONCAT()` on MySQL: there is no spelling all three accept ).
|
|
375
|
+
* Every driver that ships with spinajs replaces this with its native form; this is
|
|
376
|
+
* what an unknown driver gets, and it is correct rather than fast.
|
|
377
|
+
*
|
|
378
|
+
* This used to emit `FIND_IN_SET`, which exists only in MySQL — on SQLite and MSSQL
|
|
379
|
+
* every `whereInSet` ( and therefore every `withRole` ) died with "no such function"
|
|
380
|
+
* at query time.
|
|
381
|
+
*/
|
|
382
|
+
let SqlInSetStatement = SqlInSetStatement_1 = class SqlInSetStatement extends orm_1.InSetStatement {
|
|
329
383
|
build() {
|
|
330
|
-
const column = _columnWrap(this._column, this._tableAlias);
|
|
331
|
-
const
|
|
332
|
-
const
|
|
333
|
-
|
|
384
|
+
const column = _columnWrap(this.Quoter, this._column, this._tableAlias);
|
|
385
|
+
const bindings = [];
|
|
386
|
+
const expressions = this.values().map((value) => {
|
|
387
|
+
const pattern = (0, orm_1.escapeLikeValue)(value);
|
|
388
|
+
// exact ( the column holds this value alone ), first, last, middle
|
|
389
|
+
bindings.push(value, `${pattern}${orm_1.SET_DELIMITER}%`, `%${orm_1.SET_DELIMITER}${pattern}`, `%${orm_1.SET_DELIMITER}${pattern}${orm_1.SET_DELIMITER}%`);
|
|
390
|
+
const like = `${column} LIKE ? ESCAPE '${orm_1.LIKE_ESCAPE_CHARACTER}'`;
|
|
391
|
+
return `(${column} = ? OR ${like} OR ${like} OR ${like})`;
|
|
392
|
+
});
|
|
334
393
|
return {
|
|
335
|
-
Bindings:
|
|
336
|
-
Statements: [
|
|
394
|
+
Bindings: bindings,
|
|
395
|
+
Statements: [this.combine(expressions)],
|
|
337
396
|
};
|
|
338
397
|
}
|
|
339
398
|
clone() {
|
|
340
|
-
return new SqlInSetStatement_1(this._column, this._val, this._not, this._tableAlias);
|
|
399
|
+
return _carryQuoter(new SqlInSetStatement_1(this._column, this._val, this._not, this._tableAlias), this);
|
|
341
400
|
}
|
|
342
401
|
};
|
|
343
402
|
exports.SqlInSetStatement = SqlInSetStatement;
|
|
403
|
+
__decorate([
|
|
404
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
405
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
406
|
+
], SqlInSetStatement.prototype, "Quoter", void 0);
|
|
344
407
|
exports.SqlInSetStatement = SqlInSetStatement = SqlInSetStatement_1 = __decorate([
|
|
345
408
|
(0, di_1.NewInstance)()
|
|
346
409
|
], SqlInSetStatement);
|
|
347
|
-
let SqlColumnStatement = SqlColumnStatement_1 = class SqlColumnStatement extends
|
|
410
|
+
let SqlColumnStatement = SqlColumnStatement_1 = class SqlColumnStatement extends orm_1.ColumnStatement {
|
|
348
411
|
clone() {
|
|
349
|
-
return new SqlColumnStatement_1(this._column, this._alias, this._tableAlias, this.Descriptor);
|
|
412
|
+
return _carryQuoter(new SqlColumnStatement_1(this._column, this._alias, this._tableAlias, this.Descriptor), this);
|
|
350
413
|
}
|
|
351
414
|
build() {
|
|
352
415
|
let exprr = '';
|
|
@@ -354,13 +417,13 @@ let SqlColumnStatement = SqlColumnStatement_1 = class SqlColumnStatement extends
|
|
|
354
417
|
exprr = '*';
|
|
355
418
|
}
|
|
356
419
|
else {
|
|
357
|
-
exprr =
|
|
420
|
+
exprr = this.Quoter.quote(this._column);
|
|
358
421
|
if (this._alias) {
|
|
359
|
-
exprr += ` as ${
|
|
422
|
+
exprr += ` as ${this.Quoter.quote(this._alias)}`;
|
|
360
423
|
}
|
|
361
424
|
}
|
|
362
425
|
if (this._tableAlias) {
|
|
363
|
-
exprr = `${
|
|
426
|
+
exprr = `${this.Quoter.quote(this._tableAlias)}.${exprr}`;
|
|
364
427
|
}
|
|
365
428
|
return {
|
|
366
429
|
Bindings: [],
|
|
@@ -369,12 +432,16 @@ let SqlColumnStatement = SqlColumnStatement_1 = class SqlColumnStatement extends
|
|
|
369
432
|
}
|
|
370
433
|
};
|
|
371
434
|
exports.SqlColumnStatement = SqlColumnStatement;
|
|
435
|
+
__decorate([
|
|
436
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
437
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
438
|
+
], SqlColumnStatement.prototype, "Quoter", void 0);
|
|
372
439
|
exports.SqlColumnStatement = SqlColumnStatement = SqlColumnStatement_1 = __decorate([
|
|
373
440
|
(0, di_1.NewInstance)()
|
|
374
441
|
], SqlColumnStatement);
|
|
375
|
-
let SqlColumnMethodStatement = SqlColumnMethodStatement_1 = class SqlColumnMethodStatement extends
|
|
442
|
+
let SqlColumnMethodStatement = SqlColumnMethodStatement_1 = class SqlColumnMethodStatement extends orm_1.ColumnMethodStatement {
|
|
376
443
|
clone() {
|
|
377
|
-
return new SqlColumnMethodStatement_1(this._column, this._method, this._alias, this._tableAlias);
|
|
444
|
+
return _carryQuoter(new SqlColumnMethodStatement_1(this._column, this._method, this._alias, this._tableAlias), this);
|
|
378
445
|
}
|
|
379
446
|
build() {
|
|
380
447
|
let _exprr = '';
|
|
@@ -382,10 +449,10 @@ let SqlColumnMethodStatement = SqlColumnMethodStatement_1 = class SqlColumnMetho
|
|
|
382
449
|
_exprr = `${this._method}(${this._column})`;
|
|
383
450
|
}
|
|
384
451
|
else {
|
|
385
|
-
_exprr = `${this._method}(${
|
|
452
|
+
_exprr = `${this._method}(${this.Quoter.quote(this._column)})`;
|
|
386
453
|
}
|
|
387
454
|
if (this._alias) {
|
|
388
|
-
_exprr += ` as ${
|
|
455
|
+
_exprr += ` as ${this.Quoter.quote(this._alias)}`;
|
|
389
456
|
}
|
|
390
457
|
return {
|
|
391
458
|
Bindings: [],
|
|
@@ -394,31 +461,43 @@ let SqlColumnMethodStatement = SqlColumnMethodStatement_1 = class SqlColumnMetho
|
|
|
394
461
|
}
|
|
395
462
|
};
|
|
396
463
|
exports.SqlColumnMethodStatement = SqlColumnMethodStatement;
|
|
464
|
+
__decorate([
|
|
465
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
466
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
467
|
+
], SqlColumnMethodStatement.prototype, "Quoter", void 0);
|
|
397
468
|
exports.SqlColumnMethodStatement = SqlColumnMethodStatement = SqlColumnMethodStatement_1 = __decorate([
|
|
398
469
|
(0, di_1.NewInstance)()
|
|
399
470
|
], SqlColumnMethodStatement);
|
|
400
|
-
let SqlDateWrapper = class SqlDateWrapper extends
|
|
471
|
+
let SqlDateWrapper = class SqlDateWrapper extends orm_1.DateWrapper {
|
|
401
472
|
wrap() {
|
|
402
473
|
if (this._tableAlias) {
|
|
403
|
-
return `DATE(${
|
|
474
|
+
return `DATE(${this.Quoter.quote(this._tableAlias)}.${this.Quoter.quote(this._value)})`;
|
|
404
475
|
}
|
|
405
|
-
return `DATE(${
|
|
476
|
+
return `DATE(${this.Quoter.quote(this._value)})`;
|
|
406
477
|
}
|
|
407
478
|
};
|
|
408
479
|
exports.SqlDateWrapper = SqlDateWrapper;
|
|
480
|
+
__decorate([
|
|
481
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
482
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
483
|
+
], SqlDateWrapper.prototype, "Quoter", void 0);
|
|
409
484
|
exports.SqlDateWrapper = SqlDateWrapper = __decorate([
|
|
410
485
|
(0, di_1.NewInstance)()
|
|
411
486
|
], SqlDateWrapper);
|
|
412
|
-
class SqlDateTimeWrapper extends
|
|
487
|
+
class SqlDateTimeWrapper extends orm_1.DateTimeWrapper {
|
|
413
488
|
wrap() {
|
|
414
489
|
if (this._tableAlias) {
|
|
415
|
-
return `DATETIME(${
|
|
490
|
+
return `DATETIME(${this.Quoter.quote(this._tableAlias)}.${this.Quoter.quote(this._value)})`;
|
|
416
491
|
}
|
|
417
|
-
return `DATETIME(${
|
|
492
|
+
return `DATETIME(${this.Quoter.quote(this._value)})`;
|
|
418
493
|
}
|
|
419
494
|
}
|
|
420
495
|
exports.SqlDateTimeWrapper = SqlDateTimeWrapper;
|
|
421
|
-
|
|
496
|
+
__decorate([
|
|
497
|
+
(0, di_1.Autoinject)(orm_1.IdentifierQuoter),
|
|
498
|
+
__metadata("design:type", orm_1.IdentifierQuoter)
|
|
499
|
+
], SqlDateTimeWrapper.prototype, "Quoter", void 0);
|
|
500
|
+
let SqlColumnRawStatement = SqlColumnRawStatement_1 = class SqlColumnRawStatement extends orm_1.ColumnRawStatement {
|
|
422
501
|
clone() {
|
|
423
502
|
return new SqlColumnRawStatement_1(this.RawQuery);
|
|
424
503
|
}
|
|
@@ -433,7 +512,7 @@ exports.SqlColumnRawStatement = SqlColumnRawStatement;
|
|
|
433
512
|
exports.SqlColumnRawStatement = SqlColumnRawStatement = SqlColumnRawStatement_1 = __decorate([
|
|
434
513
|
(0, di_1.NewInstance)()
|
|
435
514
|
], SqlColumnRawStatement);
|
|
436
|
-
let SqlWhereQueryStatement = SqlWhereQueryStatement_1 = class SqlWhereQueryStatement extends
|
|
515
|
+
let SqlWhereQueryStatement = SqlWhereQueryStatement_1 = class SqlWhereQueryStatement extends orm_1.WhereQueryStatement {
|
|
437
516
|
clone(_parent) {
|
|
438
517
|
// TODO: fix this any cast !
|
|
439
518
|
return new SqlWhereQueryStatement_1(this._builder.clone(_parent));
|
|
@@ -451,7 +530,7 @@ exports.SqlWhereQueryStatement = SqlWhereQueryStatement;
|
|
|
451
530
|
exports.SqlWhereQueryStatement = SqlWhereQueryStatement = SqlWhereQueryStatement_1 = __decorate([
|
|
452
531
|
(0, di_1.NewInstance)()
|
|
453
532
|
], SqlWhereQueryStatement);
|
|
454
|
-
let SqlExistsQueryStatement = SqlExistsQueryStatement_1 = class SqlExistsQueryStatement extends
|
|
533
|
+
let SqlExistsQueryStatement = SqlExistsQueryStatement_1 = class SqlExistsQueryStatement extends orm_1.ExistsQueryStatement {
|
|
455
534
|
clone(_parent) {
|
|
456
535
|
// TODO: this look wrong to clone _builder,
|
|
457
536
|
// it could be shared between statements
|