@simplysm/orm-common 13.0.75 → 13.0.76
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/package.json +2 -2
- package/tests/db-context/create-db-context.spec.ts +0 -31
- package/tests/db-context/define-db-context.spec.ts +0 -51
- package/tests/ddl/basic.spec.ts +0 -157
- package/tests/ddl/column-builder.spec.ts +0 -112
- package/tests/ddl/index-builder.spec.ts +0 -54
- package/tests/ddl/procedure-builder.spec.ts +0 -106
- package/tests/ddl/relation-builder.spec.ts +0 -201
- package/tests/ddl/table-builder.spec.ts +0 -34
- package/tests/ddl/view-builder.spec.ts +0 -60
- package/tests/dml/delete.spec.ts +0 -33
- package/tests/dml/insert.spec.ts +0 -78
- package/tests/dml/update.spec.ts +0 -96
- package/tests/dml/upsert.spec.ts +0 -52
- package/tests/errors/queryable-errors.spec.ts +0 -51
- package/tests/escape.spec.ts +0 -41
- package/tests/examples/pivot.spec.ts +0 -333
- package/tests/examples/sampling.spec.ts +0 -63
- package/tests/examples/unpivot.spec.ts +0 -65
- package/tests/exec/search-parser.spec.ts +0 -16
- package/tests/expr/comparison.spec.ts +0 -66
- package/tests/expr/conditional.spec.ts +0 -27
- package/tests/expr/date.spec.ts +0 -67
- package/tests/expr/math.spec.ts +0 -47
- package/tests/expr/string.spec.ts +0 -56
- package/tests/expr/utility.spec.ts +0 -27
- package/tests/select/basic.spec.ts +0 -69
- package/tests/select/filter.spec.ts +0 -114
- package/tests/select/group.spec.ts +0 -85
- package/tests/select/join.spec.ts +0 -113
- package/tests/select/order.spec.ts +0 -49
- package/tests/select/subquery.spec.ts +0 -96
- package/tests/select/window.spec.ts +0 -185
- package/tests/types/nullable-queryable-record.spec.ts +0 -48
- package/tests/utils/result-parser-perf.spec.ts +0 -67
- package/tests/utils/result-parser.spec.ts +0 -34
|
@@ -190,33 +190,6 @@ describe("Expr - Conditional functions", () => {
|
|
|
190
190
|
});
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
describe("least - minimum value", () => {
|
|
194
|
-
const db = createTestDb();
|
|
195
|
-
const def = db
|
|
196
|
-
.user()
|
|
197
|
-
.select((item) => ({
|
|
198
|
-
minVal: expr.least(item.age, 100),
|
|
199
|
-
}))
|
|
200
|
-
.getSelectQueryDef();
|
|
201
|
-
|
|
202
|
-
it("Verify QueryDef", () => {
|
|
203
|
-
expect(def.select).toMatchObject({
|
|
204
|
-
minVal: {
|
|
205
|
-
type: "least",
|
|
206
|
-
args: expect.arrayContaining([
|
|
207
|
-
{ type: "column", path: ["T1", "age"] },
|
|
208
|
-
{ type: "value", value: 100 },
|
|
209
|
-
]),
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
215
|
-
const builder = createQueryBuilder(dialect);
|
|
216
|
-
expect(builder.build(def)).toMatchSql(expected.least[dialect]);
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
193
|
describe("switch - all case/default are undefined", () => {
|
|
221
194
|
it("throws an error", () => {
|
|
222
195
|
const db = createTestDb();
|
package/tests/expr/date.spec.ts
CHANGED
|
@@ -41,15 +41,6 @@ describe("Expr - Date/Time functions", () => {
|
|
|
41
41
|
}))
|
|
42
42
|
.getSelectQueryDef();
|
|
43
43
|
|
|
44
|
-
it("Verify QueryDef", () => {
|
|
45
|
-
expect(def.select).toMatchObject({
|
|
46
|
-
monthPart: {
|
|
47
|
-
type: "month",
|
|
48
|
-
arg: { type: "column", path: ["T1", "createdAt"] },
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
44
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
54
45
|
const builder = createQueryBuilder(dialect);
|
|
55
46
|
expect(builder.build(def)).toMatchSql(expected.month[dialect]);
|
|
@@ -65,15 +56,6 @@ describe("Expr - Date/Time functions", () => {
|
|
|
65
56
|
}))
|
|
66
57
|
.getSelectQueryDef();
|
|
67
58
|
|
|
68
|
-
it("Verify QueryDef", () => {
|
|
69
|
-
expect(def.select).toMatchObject({
|
|
70
|
-
dayPart: {
|
|
71
|
-
type: "day",
|
|
72
|
-
arg: { type: "column", path: ["T1", "createdAt"] },
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
59
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
78
60
|
const builder = createQueryBuilder(dialect);
|
|
79
61
|
expect(builder.build(def)).toMatchSql(expected.day[dialect]);
|
|
@@ -89,15 +71,6 @@ describe("Expr - Date/Time functions", () => {
|
|
|
89
71
|
}))
|
|
90
72
|
.getSelectQueryDef();
|
|
91
73
|
|
|
92
|
-
it("Verify QueryDef", () => {
|
|
93
|
-
expect(def.select).toMatchObject({
|
|
94
|
-
hourPart: {
|
|
95
|
-
type: "hour",
|
|
96
|
-
arg: { type: "column", path: ["T1", "createdAt"] },
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
74
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
102
75
|
const builder = createQueryBuilder(dialect);
|
|
103
76
|
expect(builder.build(def)).toMatchSql(expected.hour[dialect]);
|
|
@@ -113,15 +86,6 @@ describe("Expr - Date/Time functions", () => {
|
|
|
113
86
|
}))
|
|
114
87
|
.getSelectQueryDef();
|
|
115
88
|
|
|
116
|
-
it("Verify QueryDef", () => {
|
|
117
|
-
expect(def.select).toMatchObject({
|
|
118
|
-
minutePart: {
|
|
119
|
-
type: "minute",
|
|
120
|
-
arg: { type: "column", path: ["T1", "createdAt"] },
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
89
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
126
90
|
const builder = createQueryBuilder(dialect);
|
|
127
91
|
expect(builder.build(def)).toMatchSql(expected.minute[dialect]);
|
|
@@ -137,15 +101,6 @@ describe("Expr - Date/Time functions", () => {
|
|
|
137
101
|
}))
|
|
138
102
|
.getSelectQueryDef();
|
|
139
103
|
|
|
140
|
-
it("Verify QueryDef", () => {
|
|
141
|
-
expect(def.select).toMatchObject({
|
|
142
|
-
secondPart: {
|
|
143
|
-
type: "second",
|
|
144
|
-
arg: { type: "column", path: ["T1", "createdAt"] },
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
104
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
150
105
|
const builder = createQueryBuilder(dialect);
|
|
151
106
|
expect(builder.build(def)).toMatchSql(expected.second[dialect]);
|
|
@@ -189,17 +144,6 @@ describe("Expr - Date/Time functions", () => {
|
|
|
189
144
|
}))
|
|
190
145
|
.getSelectQueryDef();
|
|
191
146
|
|
|
192
|
-
it("Verify QueryDef", () => {
|
|
193
|
-
expect(def.select).toMatchObject({
|
|
194
|
-
yearsDiff: {
|
|
195
|
-
type: "dateDiff",
|
|
196
|
-
separator: "year",
|
|
197
|
-
from: { type: "column", path: ["T1", "createdAt"] },
|
|
198
|
-
to: { type: "value", value: targetDate },
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
147
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
204
148
|
const builder = createQueryBuilder(dialect);
|
|
205
149
|
expect(builder.build(def)).toMatchSql(expected.dateDiffYear[dialect]);
|
|
@@ -216,17 +160,6 @@ describe("Expr - Date/Time functions", () => {
|
|
|
216
160
|
}))
|
|
217
161
|
.getSelectQueryDef();
|
|
218
162
|
|
|
219
|
-
it("Verify QueryDef", () => {
|
|
220
|
-
expect(def.select).toMatchObject({
|
|
221
|
-
monthsDiff: {
|
|
222
|
-
type: "dateDiff",
|
|
223
|
-
separator: "month",
|
|
224
|
-
from: { type: "column", path: ["T1", "createdAt"] },
|
|
225
|
-
to: { type: "value", value: targetDate },
|
|
226
|
-
},
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
163
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
231
164
|
const builder = createQueryBuilder(dialect);
|
|
232
165
|
expect(builder.build(def)).toMatchSql(expected.dateDiffMonth[dialect]);
|
package/tests/expr/math.spec.ts
CHANGED
|
@@ -56,51 +56,4 @@ describe("Expr - Math functions", () => {
|
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
describe("ceil - ceiling", () => {
|
|
60
|
-
const db = createTestDb();
|
|
61
|
-
const def = db
|
|
62
|
-
.user()
|
|
63
|
-
.select((item) => ({
|
|
64
|
-
ceiled: expr.ceil(item.age),
|
|
65
|
-
}))
|
|
66
|
-
.getSelectQueryDef();
|
|
67
|
-
|
|
68
|
-
it("Verify QueryDef", () => {
|
|
69
|
-
expect(def.select).toMatchObject({
|
|
70
|
-
ceiled: {
|
|
71
|
-
type: "ceil",
|
|
72
|
-
arg: { type: "column", path: ["T1", "age"] },
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
78
|
-
const builder = createQueryBuilder(dialect);
|
|
79
|
-
expect(builder.build(def)).toMatchSql(expected.ceil[dialect]);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe("floor - flooring", () => {
|
|
84
|
-
const db = createTestDb();
|
|
85
|
-
const def = db
|
|
86
|
-
.user()
|
|
87
|
-
.select((item) => ({
|
|
88
|
-
floored: expr.floor(item.age),
|
|
89
|
-
}))
|
|
90
|
-
.getSelectQueryDef();
|
|
91
|
-
|
|
92
|
-
it("Verify QueryDef", () => {
|
|
93
|
-
expect(def.select).toMatchObject({
|
|
94
|
-
floored: {
|
|
95
|
-
type: "floor",
|
|
96
|
-
arg: { type: "column", path: ["T1", "age"] },
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
102
|
-
const builder = createQueryBuilder(dialect);
|
|
103
|
-
expect(builder.build(def)).toMatchSql(expected.floor[dialect]);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
59
|
});
|
|
@@ -68,15 +68,6 @@ describe("Expr - String functions", () => {
|
|
|
68
68
|
}))
|
|
69
69
|
.getSelectQueryDef();
|
|
70
70
|
|
|
71
|
-
it("Verify QueryDef", () => {
|
|
72
|
-
expect(def.select).toMatchObject({
|
|
73
|
-
byteLen: {
|
|
74
|
-
type: "byteLength",
|
|
75
|
-
arg: { type: "column", path: ["T1", "name"] },
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
71
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
81
72
|
const builder = createQueryBuilder(dialect);
|
|
82
73
|
expect(builder.build(def)).toMatchSql(expected.byteLength[dialect]);
|
|
@@ -117,16 +108,6 @@ describe("Expr - String functions", () => {
|
|
|
117
108
|
}))
|
|
118
109
|
.getSelectQueryDef();
|
|
119
110
|
|
|
120
|
-
it("Verify QueryDef", () => {
|
|
121
|
-
expect(def.select).toMatchObject({
|
|
122
|
-
suffix: {
|
|
123
|
-
type: "right",
|
|
124
|
-
source: { type: "column", path: ["T1", "name"] },
|
|
125
|
-
length: { type: "value", value: 3 },
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
111
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
131
112
|
const builder = createQueryBuilder(dialect);
|
|
132
113
|
expect(builder.build(def)).toMatchSql(expected.right[dialect]);
|
|
@@ -142,15 +123,6 @@ describe("Expr - String functions", () => {
|
|
|
142
123
|
}))
|
|
143
124
|
.getSelectQueryDef();
|
|
144
125
|
|
|
145
|
-
it("Verify QueryDef", () => {
|
|
146
|
-
expect(def.select).toMatchObject({
|
|
147
|
-
trimmed: {
|
|
148
|
-
type: "trim",
|
|
149
|
-
arg: { type: "column", path: ["T1", "name"] },
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
126
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
155
127
|
const builder = createQueryBuilder(dialect);
|
|
156
128
|
expect(builder.build(def)).toMatchSql(expected.trim[dialect]);
|
|
@@ -218,15 +190,6 @@ describe("Expr - String functions", () => {
|
|
|
218
190
|
}))
|
|
219
191
|
.getSelectQueryDef();
|
|
220
192
|
|
|
221
|
-
it("Verify QueryDef", () => {
|
|
222
|
-
expect(def.select).toMatchObject({
|
|
223
|
-
upper: {
|
|
224
|
-
type: "upper",
|
|
225
|
-
arg: { type: "column", path: ["T1", "name"] },
|
|
226
|
-
},
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
193
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
231
194
|
const builder = createQueryBuilder(dialect);
|
|
232
195
|
expect(builder.build(def)).toMatchSql(expected.upper[dialect]);
|
|
@@ -242,15 +205,6 @@ describe("Expr - String functions", () => {
|
|
|
242
205
|
}))
|
|
243
206
|
.getSelectQueryDef();
|
|
244
207
|
|
|
245
|
-
it("Verify QueryDef", () => {
|
|
246
|
-
expect(def.select).toMatchObject({
|
|
247
|
-
lower: {
|
|
248
|
-
type: "lower",
|
|
249
|
-
arg: { type: "column", path: ["T1", "name"] },
|
|
250
|
-
},
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
208
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
255
209
|
const builder = createQueryBuilder(dialect);
|
|
256
210
|
expect(builder.build(def)).toMatchSql(expected.lower[dialect]);
|
|
@@ -338,16 +292,6 @@ describe("Expr - String functions", () => {
|
|
|
338
292
|
.where((item) => [expr.like(item.name, "%\\%%")])
|
|
339
293
|
.getSelectQueryDef();
|
|
340
294
|
|
|
341
|
-
it("Verify QueryDef", () => {
|
|
342
|
-
expect(def.where).toEqual([
|
|
343
|
-
{
|
|
344
|
-
type: "like",
|
|
345
|
-
source: { type: "column", path: ["T1", "name"] },
|
|
346
|
-
pattern: { type: "value", value: "%\\%%" },
|
|
347
|
-
},
|
|
348
|
-
]);
|
|
349
|
-
});
|
|
350
|
-
|
|
351
295
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
352
296
|
const builder = createQueryBuilder(dialect);
|
|
353
297
|
expect(builder.build(def)).toMatchSql(expected.likeEscape[dialect]);
|
|
@@ -90,33 +90,6 @@ describe("Expr - Utility functions", () => {
|
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
describe("cast - type conversion to VARCHAR", () => {
|
|
94
|
-
const db = createTestDb();
|
|
95
|
-
const def = db
|
|
96
|
-
.user()
|
|
97
|
-
.select((item) => ({
|
|
98
|
-
id: item.id,
|
|
99
|
-
ageStr: expr.cast(item.age, { type: "varchar", length: 50 }),
|
|
100
|
-
}))
|
|
101
|
-
.getSelectQueryDef();
|
|
102
|
-
|
|
103
|
-
it("Verify QueryDef", () => {
|
|
104
|
-
expect(def.select).toMatchObject({
|
|
105
|
-
id: { type: "column", path: ["T1", "id"] },
|
|
106
|
-
ageStr: {
|
|
107
|
-
type: "cast",
|
|
108
|
-
source: { type: "column", path: ["T1", "age"] },
|
|
109
|
-
targetType: { type: "varchar", length: 50 },
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
115
|
-
const builder = createQueryBuilder(dialect);
|
|
116
|
-
expect(builder.build(def)).toMatchSql(expected.castToVarchar[dialect]);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
93
|
//#endregion
|
|
121
94
|
|
|
122
95
|
//#region ========== RAW ==========
|
|
@@ -160,24 +160,6 @@ describe("SELECT - Basic", () => {
|
|
|
160
160
|
}))
|
|
161
161
|
.getSelectQueryDef();
|
|
162
162
|
|
|
163
|
-
it("Verify QueryDef", () => {
|
|
164
|
-
expect(def).toEqual({
|
|
165
|
-
type: "select",
|
|
166
|
-
as: "T1",
|
|
167
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
168
|
-
select: {
|
|
169
|
-
contact: {
|
|
170
|
-
type: "ifNull",
|
|
171
|
-
args: [
|
|
172
|
-
{ type: "column", path: ["T1", "email"] },
|
|
173
|
-
{ type: "column", path: ["T1", "name"] },
|
|
174
|
-
{ type: "value", value: "N/A" },
|
|
175
|
-
],
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
163
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
182
164
|
const builder = createQueryBuilder(dialect);
|
|
183
165
|
expect(builder.build(def)).toMatchSql(expected.selectIfNull3[dialect]);
|
|
@@ -254,21 +236,6 @@ describe("SELECT - Basic", () => {
|
|
|
254
236
|
}))
|
|
255
237
|
.getSelectQueryDef();
|
|
256
238
|
|
|
257
|
-
it("Verify QueryDef", () => {
|
|
258
|
-
expect(def).toEqual({
|
|
259
|
-
type: "select",
|
|
260
|
-
as: "T1",
|
|
261
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
262
|
-
select: {
|
|
263
|
-
suffix: {
|
|
264
|
-
type: "substring",
|
|
265
|
-
source: { type: "column", path: ["T1", "name"] },
|
|
266
|
-
start: { type: "value", value: 3 },
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
239
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
273
240
|
const builder = createQueryBuilder(dialect);
|
|
274
241
|
expect(builder.build(def)).toMatchSql(expected.selectSubstringNoLength[dialect]);
|
|
@@ -346,23 +313,6 @@ describe("SELECT - Basic", () => {
|
|
|
346
313
|
}))
|
|
347
314
|
.getSelectQueryDef();
|
|
348
315
|
|
|
349
|
-
it("Verify QueryDef", () => {
|
|
350
|
-
expect(def).toEqual({
|
|
351
|
-
type: "select",
|
|
352
|
-
as: "T1",
|
|
353
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
354
|
-
select: {
|
|
355
|
-
maxAge: {
|
|
356
|
-
type: "greatest",
|
|
357
|
-
args: [
|
|
358
|
-
{ type: "column", path: ["T1", "age"] },
|
|
359
|
-
{ type: "value", value: 18 },
|
|
360
|
-
],
|
|
361
|
-
},
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
|
|
366
316
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
367
317
|
const builder = createQueryBuilder(dialect);
|
|
368
318
|
expect(builder.build(def)).toMatchSql(expected.selectGreatest[dialect]);
|
|
@@ -394,15 +344,6 @@ describe("SELECT - Options", () => {
|
|
|
394
344
|
const db = createTestDb();
|
|
395
345
|
const def = db.user().lock().getSelectQueryDef();
|
|
396
346
|
|
|
397
|
-
it("Verify QueryDef", () => {
|
|
398
|
-
expect(def).toEqual({
|
|
399
|
-
type: "select",
|
|
400
|
-
as: "T1",
|
|
401
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
402
|
-
lock: true,
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
|
|
406
347
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
407
348
|
const builder = createQueryBuilder(dialect);
|
|
408
349
|
expect(builder.build(def)).toMatchSql(expected.selectLock[dialect]);
|
|
@@ -413,16 +354,6 @@ describe("SELECT - Options", () => {
|
|
|
413
354
|
const db = createTestDb();
|
|
414
355
|
const def = db.user().distinct().lock().getSelectQueryDef();
|
|
415
356
|
|
|
416
|
-
it("Verify QueryDef", () => {
|
|
417
|
-
expect(def).toEqual({
|
|
418
|
-
type: "select",
|
|
419
|
-
as: "T1",
|
|
420
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
421
|
-
distinct: true,
|
|
422
|
-
lock: true,
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
|
|
426
357
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
427
358
|
const builder = createQueryBuilder(dialect);
|
|
428
359
|
expect(builder.build(def)).toMatchSql(expected.selectDistinctLock[dialect]);
|
|
@@ -75,21 +75,6 @@ describe("SELECT - WHERE - comparison operations", () => {
|
|
|
75
75
|
.where((item) => [expr.gt(item.age, 20)])
|
|
76
76
|
.getSelectQueryDef();
|
|
77
77
|
|
|
78
|
-
it("Verify QueryDef", () => {
|
|
79
|
-
expect(def).toEqual({
|
|
80
|
-
type: "select",
|
|
81
|
-
as: "T1",
|
|
82
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
83
|
-
where: [
|
|
84
|
-
{
|
|
85
|
-
type: "gt",
|
|
86
|
-
source: { type: "column", path: ["T1", "age"] },
|
|
87
|
-
target: { type: "value", value: 20 },
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
78
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
94
79
|
const builder = createQueryBuilder(dialect);
|
|
95
80
|
expect(builder.build(def)).toMatchSql(expected.whereGt[dialect]);
|
|
@@ -103,21 +88,6 @@ describe("SELECT - WHERE - comparison operations", () => {
|
|
|
103
88
|
.where((item) => [expr.gte(item.age, 20)])
|
|
104
89
|
.getSelectQueryDef();
|
|
105
90
|
|
|
106
|
-
it("Verify QueryDef", () => {
|
|
107
|
-
expect(def).toEqual({
|
|
108
|
-
type: "select",
|
|
109
|
-
as: "T1",
|
|
110
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
111
|
-
where: [
|
|
112
|
-
{
|
|
113
|
-
type: "gte",
|
|
114
|
-
source: { type: "column", path: ["T1", "age"] },
|
|
115
|
-
target: { type: "value", value: 20 },
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
91
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
122
92
|
const builder = createQueryBuilder(dialect);
|
|
123
93
|
expect(builder.build(def)).toMatchSql(expected.whereGte[dialect]);
|
|
@@ -131,21 +101,6 @@ describe("SELECT - WHERE - comparison operations", () => {
|
|
|
131
101
|
.where((item) => [expr.lt(item.age, 30)])
|
|
132
102
|
.getSelectQueryDef();
|
|
133
103
|
|
|
134
|
-
it("Verify QueryDef", () => {
|
|
135
|
-
expect(def).toEqual({
|
|
136
|
-
type: "select",
|
|
137
|
-
as: "T1",
|
|
138
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
139
|
-
where: [
|
|
140
|
-
{
|
|
141
|
-
type: "lt",
|
|
142
|
-
source: { type: "column", path: ["T1", "age"] },
|
|
143
|
-
target: { type: "value", value: 30 },
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
104
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
150
105
|
const builder = createQueryBuilder(dialect);
|
|
151
106
|
expect(builder.build(def)).toMatchSql(expected.whereLt[dialect]);
|
|
@@ -159,21 +114,6 @@ describe("SELECT - WHERE - comparison operations", () => {
|
|
|
159
114
|
.where((item) => [expr.lte(item.age, 30)])
|
|
160
115
|
.getSelectQueryDef();
|
|
161
116
|
|
|
162
|
-
it("Verify QueryDef", () => {
|
|
163
|
-
expect(def).toEqual({
|
|
164
|
-
type: "select",
|
|
165
|
-
as: "T1",
|
|
166
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
167
|
-
where: [
|
|
168
|
-
{
|
|
169
|
-
type: "lte",
|
|
170
|
-
source: { type: "column", path: ["T1", "age"] },
|
|
171
|
-
target: { type: "value", value: 30 },
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
117
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
178
118
|
const builder = createQueryBuilder(dialect);
|
|
179
119
|
expect(builder.build(def)).toMatchSql(expected.whereLte[dialect]);
|
|
@@ -356,24 +296,6 @@ describe("SELECT - WHERE - LIKE", () => {
|
|
|
356
296
|
.where((item) => [expr.not(expr.like(item.name, "%Test%"))])
|
|
357
297
|
.getSelectQueryDef();
|
|
358
298
|
|
|
359
|
-
it("Verify QueryDef", () => {
|
|
360
|
-
expect(def).toEqual({
|
|
361
|
-
type: "select",
|
|
362
|
-
as: "T1",
|
|
363
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
364
|
-
where: [
|
|
365
|
-
{
|
|
366
|
-
type: "not",
|
|
367
|
-
arg: {
|
|
368
|
-
type: "like",
|
|
369
|
-
source: { type: "column", path: ["T1", "name"] },
|
|
370
|
-
pattern: { type: "value", value: "%Test%" },
|
|
371
|
-
},
|
|
372
|
-
},
|
|
373
|
-
],
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
|
|
377
299
|
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
378
300
|
const builder = createQueryBuilder(dialect);
|
|
379
301
|
expect(builder.build(def)).toMatchSql(expected.whereNotLike[dialect]);
|
|
@@ -601,42 +523,6 @@ describe("SELECT - WHERE - EXISTS / IN subquery", () => {
|
|
|
601
523
|
});
|
|
602
524
|
});
|
|
603
525
|
|
|
604
|
-
it("not exists - verifies QueryDef", () => {
|
|
605
|
-
const db = createTestDb();
|
|
606
|
-
const def = db
|
|
607
|
-
.user()
|
|
608
|
-
.where((item) => [
|
|
609
|
-
expr.not(expr.exists(db.post().where((p) => [expr.eq(p.userId, item.id)]))),
|
|
610
|
-
])
|
|
611
|
-
.getSelectQueryDef();
|
|
612
|
-
|
|
613
|
-
expect(def).toEqual({
|
|
614
|
-
type: "select",
|
|
615
|
-
as: "T1",
|
|
616
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
617
|
-
where: [
|
|
618
|
-
{
|
|
619
|
-
type: "not",
|
|
620
|
-
arg: {
|
|
621
|
-
type: "exists",
|
|
622
|
-
query: {
|
|
623
|
-
type: "select",
|
|
624
|
-
as: "T2",
|
|
625
|
-
from: { database: "TestDb", schema: "TestSchema", name: "Post" },
|
|
626
|
-
where: [
|
|
627
|
-
{
|
|
628
|
-
type: "eq",
|
|
629
|
-
source: { type: "column", path: ["T2", "userId"] },
|
|
630
|
-
target: { type: "column", path: ["T1", "id"] },
|
|
631
|
-
},
|
|
632
|
-
],
|
|
633
|
-
},
|
|
634
|
-
},
|
|
635
|
-
},
|
|
636
|
-
],
|
|
637
|
-
});
|
|
638
|
-
});
|
|
639
|
-
|
|
640
526
|
describe("inQuery (IN subquery)", () => {
|
|
641
527
|
const db = createTestDb();
|
|
642
528
|
const def = db
|
|
@@ -155,90 +155,5 @@ describe("SELECT - HAVING", () => {
|
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
describe("multiple conditions", () => {
|
|
159
|
-
const db = createTestDb();
|
|
160
|
-
const def = db
|
|
161
|
-
.user()
|
|
162
|
-
.select((item) => ({
|
|
163
|
-
name: item.name,
|
|
164
|
-
cnt: expr.count(item.id),
|
|
165
|
-
avgAge: expr.avg(item.age),
|
|
166
|
-
}))
|
|
167
|
-
.groupBy((item) => [item.name])
|
|
168
|
-
.having((item) => [expr.gt(item.cnt, 5), expr.gte(item.avgAge, 25)])
|
|
169
|
-
.getSelectQueryDef();
|
|
170
|
-
|
|
171
|
-
it("Verify QueryDef", () => {
|
|
172
|
-
expect(def).toEqual({
|
|
173
|
-
type: "select",
|
|
174
|
-
as: "T1",
|
|
175
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
176
|
-
select: {
|
|
177
|
-
name: { type: "column", path: ["T1", "name"] },
|
|
178
|
-
cnt: { type: "count", arg: { type: "column", path: ["T1", "id"] } },
|
|
179
|
-
avgAge: { type: "avg", arg: { type: "column", path: ["T1", "age"] } },
|
|
180
|
-
},
|
|
181
|
-
groupBy: [{ type: "column", path: ["T1", "name"] }],
|
|
182
|
-
having: [
|
|
183
|
-
{
|
|
184
|
-
type: "gt",
|
|
185
|
-
source: { type: "count", arg: { type: "column", path: ["T1", "id"] } },
|
|
186
|
-
target: { type: "value", value: 5 },
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
type: "gte",
|
|
190
|
-
source: { type: "avg", arg: { type: "column", path: ["T1", "age"] } },
|
|
191
|
-
target: { type: "value", value: 25 },
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
198
|
-
const builder = createQueryBuilder(dialect);
|
|
199
|
-
expect(builder.build(def)).toMatchSql(expected.havingMultiple[dialect]);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe("GROUP BY + HAVING + ORDER BY combination", () => {
|
|
204
|
-
const db = createTestDb();
|
|
205
|
-
const def = db
|
|
206
|
-
.user()
|
|
207
|
-
.select((item) => ({
|
|
208
|
-
name: item.name,
|
|
209
|
-
cnt: expr.count(item.id),
|
|
210
|
-
}))
|
|
211
|
-
.groupBy((item) => [item.name])
|
|
212
|
-
.having((item) => [expr.gt(item.cnt, 1)])
|
|
213
|
-
.orderBy((item) => item.cnt, "DESC")
|
|
214
|
-
.getSelectQueryDef();
|
|
215
|
-
|
|
216
|
-
it("Verify QueryDef", () => {
|
|
217
|
-
expect(def).toEqual({
|
|
218
|
-
type: "select",
|
|
219
|
-
as: "T1",
|
|
220
|
-
from: { database: "TestDb", schema: "TestSchema", name: "User" },
|
|
221
|
-
select: {
|
|
222
|
-
name: { type: "column", path: ["T1", "name"] },
|
|
223
|
-
cnt: { type: "count", arg: { type: "column", path: ["T1", "id"] } },
|
|
224
|
-
},
|
|
225
|
-
groupBy: [{ type: "column", path: ["T1", "name"] }],
|
|
226
|
-
having: [
|
|
227
|
-
{
|
|
228
|
-
type: "gt",
|
|
229
|
-
source: { type: "count", arg: { type: "column", path: ["T1", "id"] } },
|
|
230
|
-
target: { type: "value", value: 1 },
|
|
231
|
-
},
|
|
232
|
-
],
|
|
233
|
-
orderBy: [[{ type: "count", arg: { type: "column", path: ["T1", "id"] } }, "DESC"]],
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it.each(dialects)("[%s] Verify SQL", (dialect) => {
|
|
238
|
-
const builder = createQueryBuilder(dialect);
|
|
239
|
-
expect(builder.build(def)).toMatchSql(expected.havingOrderCombo[dialect]);
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
158
|
//#endregion
|
|
244
159
|
});
|