@jrrd/postgresjs 0.0.6 → 0.0.7
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/dist/index.d.ts +87 -87
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1510 -1552
- package/package.json +19 -18
package/dist/index.js
CHANGED
|
@@ -3,313 +3,315 @@
|
|
|
3
3
|
var pg = require('pg');
|
|
4
4
|
|
|
5
5
|
class ColumnLike {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
#alias
|
|
7
|
+
#cast
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
constructor () {
|
|
10
|
+
this.#alias = undefined;
|
|
11
|
+
this.#cast = undefined;
|
|
12
|
+
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
as (name) {
|
|
15
|
+
this.#alias = name;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
cast (type) {
|
|
21
|
+
this.#cast = type;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
return this
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
toString () {
|
|
27
|
+
return (this.#cast ? `::${this.#cast}` : '') + (this.#alias ? ` AS "${this.#alias}"` : '')
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
class SqlColumn extends ColumnLike {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
32
|
+
#name
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {string} name
|
|
36
|
+
*/
|
|
37
|
+
constructor (name) {
|
|
38
|
+
super();
|
|
39
|
+
this.#name = name;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
toString () {
|
|
43
|
+
return this.#name.split('.').map(token => `"${token}"`).join('.') + super.toString()
|
|
44
|
+
}
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
class SqlCase extends ColumnLike {
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
#caseWhen = []
|
|
49
|
+
#caseElse
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
/**
|
|
52
|
+
* @param {ConditionLike} condition
|
|
53
|
+
* @param {*} value
|
|
54
|
+
*/
|
|
55
|
+
when (condition, value) {
|
|
56
|
+
this.#caseWhen.push([condition, typeof value === 'string' ? new SqlColumn(value) : value]);
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
return this
|
|
59
|
+
}
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
else (value) {
|
|
62
|
+
this.#caseElse = typeof value === 'string' ? new SqlColumn(value) : value;
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
return this
|
|
65
|
+
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
toString () {
|
|
68
|
+
return `${this.#caseWhen.map(([condition, value]) => `WHEN ${condition} THEN ${value}`).join('\n')}` +
|
|
70
69
|
`\n${this.#caseElse}` +
|
|
71
70
|
`\nEND${super.toString()}`
|
|
72
|
-
|
|
71
|
+
}
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
class SqlCoalesce extends ColumnLike {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
75
|
+
#left
|
|
76
|
+
#right
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {ColumnLike} left
|
|
80
|
+
* @param {ColumnLike} right
|
|
81
|
+
*/
|
|
82
|
+
constructor (left, right) {
|
|
83
|
+
super();
|
|
84
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
85
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
toString () {
|
|
89
|
+
return `COALESCE(${this.#left}, ${this.#right})${super.toString()}`
|
|
90
|
+
}
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
class SqlConcat extends ColumnLike {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
94
|
+
#columns
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {...ColumnLike} columns
|
|
98
|
+
*/
|
|
99
|
+
constructor (...columns) {
|
|
100
|
+
super();
|
|
101
|
+
this.#columns = columns.map(column => typeof column === 'string' ? new SqlColumn(column) : column);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
toString () {
|
|
105
|
+
return `CONCAT(${this.#columns.join(', ')})${super.toString()}`
|
|
106
|
+
}
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
class SqlDateInterval extends ColumnLike {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
110
|
+
#unit
|
|
111
|
+
#value
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {number} value
|
|
115
|
+
* @param {string} unit
|
|
116
|
+
*/
|
|
117
|
+
constructor (value, unit) {
|
|
118
|
+
super();
|
|
119
|
+
this.#value = value;
|
|
120
|
+
this.#unit = unit;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
toString () {
|
|
124
|
+
return `${this.#value > 0 ? '+' : '-'} interval '${Math.abs(this.#value)} ${this.#unit}${Math.abs(this.#value) === 1 ? '' : 's'}'`
|
|
125
|
+
}
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
class SqlDatePart extends ColumnLike {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
129
|
+
#part
|
|
130
|
+
#column
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {string} part
|
|
134
|
+
* @param {ColumnLike} column
|
|
135
|
+
*/
|
|
136
|
+
constructor (part, column) {
|
|
137
|
+
super();
|
|
138
|
+
this.#part = part;
|
|
139
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
toString () {
|
|
143
|
+
return `date_part('${this.#part}', ${this.#column})${super.toString()}`
|
|
144
|
+
}
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
class SqlDateTrunc extends ColumnLike {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
148
|
+
#part
|
|
149
|
+
#column
|
|
150
|
+
|
|
151
|
+
constructor (part, column) {
|
|
152
|
+
super();
|
|
153
|
+
this.#part = part;
|
|
154
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
toString () {
|
|
158
|
+
return `date_trunc('${this.#part}', ${this.#column})${super.toString()}`
|
|
159
|
+
}
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
class SqlString extends ColumnLike {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
163
|
+
#value
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @param {string} value
|
|
167
|
+
*/
|
|
168
|
+
constructor (value) {
|
|
169
|
+
super();
|
|
170
|
+
this.#value = value;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
toString () {
|
|
174
|
+
return `'${this.#value}'${super.toString()}`
|
|
175
|
+
}
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
class SqlLPad extends ColumnLike {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
179
|
+
#column
|
|
180
|
+
#length
|
|
181
|
+
#fill
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {ColumnLike} column
|
|
185
|
+
* @param {number} length
|
|
186
|
+
* @param {string} fill
|
|
187
|
+
*/
|
|
188
|
+
constructor (column, length, fill) {
|
|
189
|
+
super();
|
|
190
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
191
|
+
this.#length = length;
|
|
192
|
+
this.#fill = typeof fill === 'string' ? new SqlString(fill) : fill;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
toString () {
|
|
196
|
+
return `lpad(${this.#column}, ${this.#length}, ${this.#fill})${super.toString()}`
|
|
197
|
+
}
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
class SqlMax extends ColumnLike {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
201
|
+
#column
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @param {ColumnLike} column
|
|
205
|
+
*/
|
|
206
|
+
constructor (column) {
|
|
207
|
+
super();
|
|
208
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
toString () {
|
|
212
|
+
return `max(${this.#column})${super.toString()}`
|
|
213
|
+
}
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
class SqlParameter extends ColumnLike {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
217
|
+
#number
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @param {number} number
|
|
221
|
+
*/
|
|
222
|
+
constructor (number) {
|
|
223
|
+
super();
|
|
224
|
+
this.#number = number;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
toString () {
|
|
228
|
+
return `$${this.#number}${super.toString()}`
|
|
229
|
+
}
|
|
229
230
|
}
|
|
230
231
|
|
|
231
232
|
class SqlRPad extends ColumnLike {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
233
|
+
#column
|
|
234
|
+
#length
|
|
235
|
+
#fill
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @param {ColumnLike} column
|
|
239
|
+
* @param {number} length
|
|
240
|
+
* @param {string} fill
|
|
241
|
+
*/
|
|
242
|
+
constructor (column, length, fill) {
|
|
243
|
+
super();
|
|
244
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
245
|
+
this.#length = length;
|
|
246
|
+
this.#fill = typeof fill === 'string' ? new SqlString(fill) : fill;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
toString () {
|
|
250
|
+
return `rpad(${this.#column}, ${this.#length}, ${this.#fill})${super.toString()}`
|
|
251
|
+
}
|
|
251
252
|
}
|
|
252
253
|
|
|
253
254
|
class SqlStringAgg extends ColumnLike {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
255
|
+
#column
|
|
256
|
+
#separator
|
|
257
|
+
#distinct
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* @param {ColumnLike} column
|
|
261
|
+
* @param {string} separator
|
|
262
|
+
* @param {boolean} distinct
|
|
263
|
+
*/
|
|
264
|
+
constructor (column, separator, distinct = true) {
|
|
265
|
+
super();
|
|
266
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
267
|
+
this.#separator = typeof separator === 'string' ? new SqlString(separator) : separator;
|
|
268
|
+
this.#distinct = distinct;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
toString () {
|
|
272
|
+
return `string_agg(${this.#distinct ? 'DISTINCT ' : ''}${this.#column}, ${this.#separator})${super.toString()}`
|
|
273
|
+
}
|
|
273
274
|
}
|
|
274
275
|
|
|
275
276
|
class SqlStringToArray extends ColumnLike {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
277
|
+
#column
|
|
278
|
+
#separator
|
|
279
|
+
#replace
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @param {ColumnLike} column
|
|
283
|
+
* @param {string} separator
|
|
284
|
+
* @param {string=} replace
|
|
285
|
+
*/
|
|
286
|
+
constructor (column, separator, replace) {
|
|
287
|
+
super();
|
|
288
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
289
|
+
this.#separator = typeof separator === 'string' ? new SqlString(separator) : separator;
|
|
290
|
+
this.#replace = replace;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
toString () {
|
|
294
|
+
return `string_to_array(${this.#column}, ${this.#separator}${this.#replace ? `, ${this.replace}` : ''})${super.toString()}`
|
|
295
|
+
}
|
|
294
296
|
}
|
|
295
297
|
|
|
296
298
|
class SqlSubString extends ColumnLike {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
299
|
+
#column
|
|
300
|
+
#pattern
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* @param {ColumnLike} column
|
|
304
|
+
* @param {string} pattern
|
|
305
|
+
*/
|
|
306
|
+
constructor (column, pattern) {
|
|
307
|
+
super();
|
|
308
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
309
|
+
this.#pattern = typeof pattern === 'string' ? new SqlString(pattern) : pattern;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
toString () {
|
|
313
|
+
return `substring(${this.#column}, ${this.#pattern})${super.toString()}`
|
|
314
|
+
}
|
|
313
315
|
}
|
|
314
316
|
|
|
315
317
|
class ConditionLike {
|
|
@@ -317,295 +319,295 @@ class ConditionLike {
|
|
|
317
319
|
}
|
|
318
320
|
|
|
319
321
|
class SqlAnd extends ConditionLike {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
322
|
+
#conditions
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* @param {...ConditionLike} conditions
|
|
326
|
+
*/
|
|
327
|
+
constructor (...conditions) {
|
|
328
|
+
super();
|
|
329
|
+
this.#conditions = conditions;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
toString () {
|
|
333
|
+
return this.#conditions.map(condition => `(${condition})`).join(' AND ')
|
|
334
|
+
}
|
|
333
335
|
}
|
|
334
336
|
|
|
335
337
|
class SqlEqual extends ConditionLike {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
338
|
+
#left
|
|
339
|
+
#right
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* @param {ColumnLike} left
|
|
343
|
+
* @param {ColumnLike} right
|
|
344
|
+
*/
|
|
345
|
+
constructor (left, right) {
|
|
346
|
+
super();
|
|
347
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
348
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
toString () {
|
|
352
|
+
return `${this.#left} = ${this.#right}`
|
|
353
|
+
}
|
|
352
354
|
}
|
|
353
355
|
|
|
354
356
|
class SqlGreaterThan extends ConditionLike {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
357
|
+
#left
|
|
358
|
+
#right
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* @param {ColumnLike} left
|
|
362
|
+
* @param {ColumnLike} right
|
|
363
|
+
*/
|
|
364
|
+
constructor (left, right) {
|
|
365
|
+
super();
|
|
366
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
367
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
toString () {
|
|
371
|
+
return `${this.#left} > ${this.#right}`
|
|
372
|
+
}
|
|
371
373
|
}
|
|
372
374
|
|
|
373
375
|
class SqlGreaterThanOrEqual extends ConditionLike {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
376
|
+
#left
|
|
377
|
+
#right
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* @param {ColumnLike} left
|
|
381
|
+
* @param {ColumnLike} right
|
|
382
|
+
*/
|
|
383
|
+
constructor (left, right) {
|
|
384
|
+
super();
|
|
385
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
386
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
toString () {
|
|
390
|
+
return `${this.#left} >= ${this.#right}`
|
|
391
|
+
}
|
|
390
392
|
}
|
|
391
393
|
|
|
392
394
|
class SqlILike extends ConditionLike {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
395
|
+
#left
|
|
396
|
+
#right
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @param {ColumnLike} left
|
|
400
|
+
* @param {ColumnLike} right
|
|
401
|
+
*/
|
|
402
|
+
constructor (left, right) {
|
|
403
|
+
super();
|
|
404
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
405
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
toString () {
|
|
409
|
+
return `${this.#left} ILIKE ${this.#right}`
|
|
410
|
+
}
|
|
409
411
|
}
|
|
410
412
|
|
|
411
413
|
class SqlIsNotNull extends ConditionLike {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
414
|
+
#column
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* @param {ColumnLike} column
|
|
418
|
+
*/
|
|
419
|
+
constructor (column) {
|
|
420
|
+
super();
|
|
421
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
toString () {
|
|
425
|
+
return `${this.#column} IS NOT NULL`
|
|
426
|
+
}
|
|
425
427
|
}
|
|
426
428
|
|
|
427
429
|
class SqlIsNull extends ConditionLike {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
430
|
+
#column
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* @param {ColumnLike} column
|
|
434
|
+
*/
|
|
435
|
+
constructor (column) {
|
|
436
|
+
super();
|
|
437
|
+
this.#column = typeof column === 'string' ? new SqlColumn(column) : column;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
toString () {
|
|
441
|
+
return `${this.#column} IS NULL`
|
|
442
|
+
}
|
|
441
443
|
}
|
|
442
444
|
|
|
443
445
|
class SqlLessThan extends ConditionLike {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
446
|
+
#left
|
|
447
|
+
#right
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* @param {ColumnLike} left
|
|
451
|
+
* @param {ColumnLike} right
|
|
452
|
+
*/
|
|
453
|
+
constructor (left, right) {
|
|
454
|
+
super();
|
|
455
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
456
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
toString () {
|
|
460
|
+
return `${this.#left} < ${this.#right}`
|
|
461
|
+
}
|
|
460
462
|
}
|
|
461
463
|
|
|
462
464
|
class SqlLessThanOrEqual extends ConditionLike {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
465
|
+
#left
|
|
466
|
+
#right
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @param {ColumnLike} left
|
|
470
|
+
* @param {ColumnLike} right
|
|
471
|
+
*/
|
|
472
|
+
constructor (left, right) {
|
|
473
|
+
super();
|
|
474
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
475
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
toString () {
|
|
479
|
+
return `${this.#left} <= ${this.#right}`
|
|
480
|
+
}
|
|
479
481
|
}
|
|
480
482
|
|
|
481
483
|
class SqlLike extends ConditionLike {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
484
|
+
#left
|
|
485
|
+
#right
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* @param {ColumnLike} left
|
|
489
|
+
* @param {ColumnLike} right
|
|
490
|
+
*/
|
|
491
|
+
constructor (left, right) {
|
|
492
|
+
super();
|
|
493
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
494
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
toString () {
|
|
498
|
+
return `${this.#left} LIKE ${this.#right}`
|
|
499
|
+
}
|
|
498
500
|
}
|
|
499
501
|
|
|
500
502
|
class SqlMatch extends ConditionLike {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
503
|
+
#left
|
|
504
|
+
#right
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* @param {ColumnLike} left
|
|
508
|
+
* @param {ColumnLike} right
|
|
509
|
+
*/
|
|
510
|
+
constructor (left, right) {
|
|
511
|
+
super();
|
|
512
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
513
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
toString () {
|
|
517
|
+
return `${this.#left} ~ ${this.#right}`
|
|
518
|
+
}
|
|
517
519
|
}
|
|
518
520
|
|
|
519
521
|
class SqlNotEqual extends ConditionLike {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
522
|
+
#left
|
|
523
|
+
#right
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* @param {ColumnLike} left
|
|
527
|
+
* @param {ColumnLike} right
|
|
528
|
+
*/
|
|
529
|
+
constructor (left, right) {
|
|
530
|
+
super();
|
|
531
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
532
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
toString () {
|
|
536
|
+
return `${this.#left} != ${this.#right}`
|
|
537
|
+
}
|
|
536
538
|
}
|
|
537
539
|
|
|
538
540
|
class SqlNotILike extends ConditionLike {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
541
|
+
#left
|
|
542
|
+
#right
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* @param {ColumnLike} left
|
|
546
|
+
* @param {ColumnLike} right
|
|
547
|
+
*/
|
|
548
|
+
constructor (left, right) {
|
|
549
|
+
super();
|
|
550
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
551
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
toString () {
|
|
555
|
+
return `${this.#left} NOT ILIKE ${this.#right}`
|
|
556
|
+
}
|
|
555
557
|
}
|
|
556
558
|
|
|
557
559
|
class SqlNotLike extends ConditionLike {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
560
|
+
#left
|
|
561
|
+
#right
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* @param {ColumnLike} left
|
|
565
|
+
* @param {ColumnLike} right
|
|
566
|
+
*/
|
|
567
|
+
constructor (left, right) {
|
|
568
|
+
super();
|
|
569
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
570
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
toString () {
|
|
574
|
+
return `${this.#left} NOT LIKE ${this.#right}`
|
|
575
|
+
}
|
|
574
576
|
}
|
|
575
577
|
|
|
576
578
|
class SqlNotMatch extends ConditionLike {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
579
|
+
#left
|
|
580
|
+
#right
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* @param {ColumnLike} left
|
|
584
|
+
* @param {ColumnLike} right
|
|
585
|
+
*/
|
|
586
|
+
constructor (left, right) {
|
|
587
|
+
super();
|
|
588
|
+
this.#left = typeof left === 'string' ? new SqlColumn(left) : left;
|
|
589
|
+
this.#right = typeof right === 'string' ? new SqlColumn(right) : right;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
toString () {
|
|
593
|
+
return `${this.#left} !~ ${this.#right}`
|
|
594
|
+
}
|
|
593
595
|
}
|
|
594
596
|
|
|
595
597
|
class SqlOr extends ConditionLike {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
598
|
+
#conditions
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* @param {...ConditionLike} conditions
|
|
602
|
+
*/
|
|
603
|
+
constructor (...conditions) {
|
|
604
|
+
super();
|
|
605
|
+
this.#conditions = conditions;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
toString () {
|
|
609
|
+
return this.#conditions.map(condition => `(${condition})`).join(' OR ')
|
|
610
|
+
}
|
|
609
611
|
}
|
|
610
612
|
|
|
611
613
|
class TableLike {
|
|
@@ -613,706 +615,707 @@ class TableLike {
|
|
|
613
615
|
}
|
|
614
616
|
|
|
615
617
|
class SqlTable extends TableLike {
|
|
616
|
-
|
|
618
|
+
#name
|
|
617
619
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
620
|
+
constructor (name) {
|
|
621
|
+
super();
|
|
622
|
+
this.#name = name;
|
|
623
|
+
}
|
|
622
624
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
625
|
+
toString () {
|
|
626
|
+
return `"${this.#name}"`
|
|
627
|
+
}
|
|
626
628
|
}
|
|
627
629
|
|
|
628
630
|
class SqlQuery {
|
|
631
|
+
/**
|
|
632
|
+
* @param {PostgreSQL} pgsql
|
|
633
|
+
*/
|
|
634
|
+
constructor (pgsql) {
|
|
629
635
|
/**
|
|
630
|
-
* @
|
|
636
|
+
* @type {PostgreSQL}
|
|
631
637
|
*/
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
* @type {PostgreSQL}
|
|
635
|
-
*/
|
|
636
|
-
this.pgsql = pgsql;
|
|
637
|
-
}
|
|
638
|
+
this.pgsql = pgsql;
|
|
639
|
+
}
|
|
638
640
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
641
|
+
async invoke (...values) {
|
|
642
|
+
const query = this.toString();
|
|
643
|
+
return await this.pgsql.pool.query(query, values)
|
|
644
|
+
}
|
|
643
645
|
}
|
|
644
646
|
|
|
645
647
|
class SqlInsert extends SqlQuery {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
648
|
+
#columns
|
|
649
|
+
#into
|
|
650
|
+
#values
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* @param {PostgreSQL} pgsql
|
|
654
|
+
* @param {...ColumnLike} columns
|
|
655
|
+
*/
|
|
656
|
+
constructor (pgsql, ...columns) {
|
|
657
|
+
super(pgsql);
|
|
658
|
+
|
|
659
|
+
this.#columns = columns.map(column => typeof column === 'string' ? new SqlColumn(column) : column);
|
|
660
|
+
this.#values = [];
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* @param {string} table
|
|
665
|
+
*/
|
|
666
|
+
into (table) {
|
|
667
|
+
this.#into = typeof table === 'string' ? new SqlTable(table) : table;
|
|
668
|
+
|
|
669
|
+
return this
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
values (...values) {
|
|
673
|
+
this.#values = values;
|
|
674
|
+
|
|
675
|
+
return this
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
toString () {
|
|
679
|
+
return `INSERT INTO ${this.#into} (${this.#columns.join(', ')}) VALUES (${this.#values.join(', ')})`
|
|
680
|
+
}
|
|
679
681
|
}
|
|
680
682
|
|
|
681
683
|
class SqlFrom {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
684
|
+
#table
|
|
685
|
+
#alias
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* @param {TableLike} table
|
|
689
|
+
* @param {string} alias
|
|
690
|
+
*/
|
|
691
|
+
constructor (table, alias) {
|
|
692
|
+
this.#table = typeof table === 'string' ? new SqlTable(table) : table;
|
|
693
|
+
this.#alias = alias;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
toString () {
|
|
697
|
+
return this.#alias ? `FROM (${this.#table}) AS ${this.#alias}` : `FROM ${this.#table}`
|
|
698
|
+
}
|
|
697
699
|
}
|
|
698
700
|
|
|
699
701
|
class SqlGroupBy {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
702
|
+
#columns
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* @param {...ColumnLike} columns
|
|
706
|
+
*/
|
|
707
|
+
constructor (...columns) {
|
|
708
|
+
this.#columns = columns.map(column => typeof column === 'string' ? new SqlColumn(column) : column);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
toString () {
|
|
712
|
+
return `GROUP BY ${this.#columns.join(', ')}`
|
|
713
|
+
}
|
|
712
714
|
}
|
|
713
715
|
|
|
714
716
|
class SqlJoin {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
717
|
+
#table
|
|
718
|
+
#condition
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* @param {TableLike} table
|
|
722
|
+
* @param {ConditionLike} condition
|
|
723
|
+
*/
|
|
724
|
+
constructor (table, condition) {
|
|
725
|
+
this.#table = typeof table === 'string' ? new SqlTable(table) : table;
|
|
726
|
+
this.#condition = condition;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
toString () {
|
|
730
|
+
return `JOIN ${this.#table} ON ${this.#condition}`
|
|
731
|
+
}
|
|
730
732
|
}
|
|
731
733
|
|
|
732
734
|
class SqlJoinInnerLateral {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
735
|
+
#table
|
|
736
|
+
#alias
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* @param {TableLike} table
|
|
740
|
+
* @param {string} alias
|
|
741
|
+
*/
|
|
742
|
+
constructor (table, alias) {
|
|
743
|
+
this.#table = typeof table === 'string' ? new SqlTable(table) : table;
|
|
744
|
+
this.#alias = alias;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
toString () {
|
|
748
|
+
return `INNER JOIN LATERAL (\n${this.#table}\n) ${this.#alias} ON TRUE`
|
|
749
|
+
}
|
|
748
750
|
}
|
|
749
751
|
|
|
750
752
|
class SqlJoinLeft {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
753
|
+
#table
|
|
754
|
+
#condition
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* @param {TableLike} table
|
|
758
|
+
* @param {ConditionLike} condition
|
|
759
|
+
*/
|
|
760
|
+
constructor (table, condition) {
|
|
761
|
+
this.#table = typeof table === 'string' ? new SqlTable(table) : table;
|
|
762
|
+
this.#condition = condition;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
toString () {
|
|
766
|
+
return `LEFT JOIN ${this.#table} ON ${this.#condition}`
|
|
767
|
+
}
|
|
766
768
|
}
|
|
767
769
|
|
|
768
770
|
class SqlJoinLeftLateral {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
771
|
+
#table
|
|
772
|
+
#alias
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* @param {TableLike} table
|
|
776
|
+
* @param {string} alias
|
|
777
|
+
*/
|
|
778
|
+
constructor (table, alias) {
|
|
779
|
+
this.#table = typeof table === 'string' ? new SqlTable(table) : table;
|
|
780
|
+
this.#alias = alias;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
toString () {
|
|
784
|
+
return `LEFT JOIN LATERAL (\n${this.#table}\n) ${this.#alias} ON TRUE`
|
|
785
|
+
}
|
|
784
786
|
}
|
|
785
787
|
|
|
786
788
|
class SqlLimit {
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
789
|
+
#count
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* @param {number} count
|
|
793
|
+
*/
|
|
794
|
+
constructor (count) {
|
|
795
|
+
this.count = count;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
toString () {
|
|
799
|
+
return `LIMIT ${this.#count}`
|
|
800
|
+
}
|
|
799
801
|
}
|
|
800
802
|
|
|
801
803
|
class SqlOrderBy {
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
804
|
+
#columns
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* @param {...ColumnLike} columns
|
|
808
|
+
*/
|
|
809
|
+
constructor (...columns) {
|
|
810
|
+
this.#columns = columns.map(column => typeof column === 'string' ? new SqlColumn(column) : column);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
toString () {
|
|
814
|
+
return `ORDER BY ${this.#columns.join(', ')}`
|
|
815
|
+
}
|
|
814
816
|
}
|
|
815
817
|
|
|
816
818
|
class SqlWhere {
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
819
|
+
#condition
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* @param {ConditionLike} condition
|
|
823
|
+
*/
|
|
824
|
+
constructor (condition) {
|
|
825
|
+
this.#condition = condition;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
toString () {
|
|
829
|
+
return `WHERE ${this.#condition}`
|
|
830
|
+
}
|
|
829
831
|
}
|
|
830
832
|
|
|
831
833
|
class SqlSelect extends SqlQuery {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
limit(count)
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
orderby(...columns)
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
where(condition)
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
}
|
|
834
|
+
/**
|
|
835
|
+
* @type {ColumnLike[]}
|
|
836
|
+
*/
|
|
837
|
+
#columns
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* @type {SqlFrom}
|
|
841
|
+
*/
|
|
842
|
+
#from
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* @type {SqlGroupBy}
|
|
846
|
+
*/
|
|
847
|
+
#groupby
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* @type {SqlJoin[]}
|
|
851
|
+
*/
|
|
852
|
+
#join
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* @type {SqlLimit}
|
|
856
|
+
*/
|
|
857
|
+
#limit
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* @type {SqlOrderBy}
|
|
861
|
+
*/
|
|
862
|
+
#orderby
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* @type {SqlWhere}
|
|
866
|
+
*/
|
|
867
|
+
#where
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* @param {PostgreSQL} pgsql
|
|
871
|
+
* @param {...ColumnLike} columns
|
|
872
|
+
*/
|
|
873
|
+
constructor (pgsql, ...columns) {
|
|
874
|
+
super(pgsql);
|
|
875
|
+
|
|
876
|
+
this.#columns = columns.map(column => typeof column === 'string' ? new SqlColumn(column) : column);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* @param {TableLike} table
|
|
881
|
+
* @param {string} alias
|
|
882
|
+
*/
|
|
883
|
+
from (table, alias) {
|
|
884
|
+
this.#from = new SqlFrom(table, alias);
|
|
885
|
+
|
|
886
|
+
return this
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* @param {...ColumnLike} columns
|
|
891
|
+
*/
|
|
892
|
+
groupby (...columns) {
|
|
893
|
+
this.#groupby = new SqlGroupBy(...columns);
|
|
894
|
+
|
|
895
|
+
return this
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* @param {TableLike} table
|
|
900
|
+
* @param {ConditionLike} condition
|
|
901
|
+
*/
|
|
902
|
+
join (table, condition) {
|
|
903
|
+
if (!this.#join) {
|
|
904
|
+
this.#join = [];
|
|
905
|
+
}
|
|
906
|
+
this.#join.push(new SqlJoin(table, condition));
|
|
907
|
+
|
|
908
|
+
return this
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* @param {TableLike} table
|
|
913
|
+
* @param {string} alias
|
|
914
|
+
*/
|
|
915
|
+
joinInnerLateral (table, alias) {
|
|
916
|
+
if (!this.#join) {
|
|
917
|
+
this.#join = [];
|
|
918
|
+
}
|
|
919
|
+
this.#join.push(new SqlJoinInnerLateral(table, alias));
|
|
920
|
+
|
|
921
|
+
return this
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* @param {TableLike} table
|
|
926
|
+
* @param {ConditionLike} condition
|
|
927
|
+
*/
|
|
928
|
+
joinLeft (table, condition) {
|
|
929
|
+
if (!this.#join) {
|
|
930
|
+
this.#join = [];
|
|
931
|
+
}
|
|
932
|
+
this.#join.push(new SqlJoinLeft(table, condition));
|
|
933
|
+
|
|
934
|
+
return this
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* @param {TableLike} table
|
|
939
|
+
* @param {string} alias
|
|
940
|
+
*/
|
|
941
|
+
joinLeftLateral (table, alias) {
|
|
942
|
+
if (!this.#join) {
|
|
943
|
+
this.#join = [];
|
|
944
|
+
}
|
|
945
|
+
this.#join.push(new SqlJoinLeftLateral(table, alias));
|
|
946
|
+
|
|
947
|
+
return this
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* @param {number} count
|
|
952
|
+
*/
|
|
953
|
+
limit (count) {
|
|
954
|
+
this.#limit = new SqlLimit(count);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* @param {...ColumnLike} columns
|
|
959
|
+
*/
|
|
960
|
+
orderby (...columns) {
|
|
961
|
+
this.orderby = new SqlOrderBy(...columns);
|
|
962
|
+
|
|
963
|
+
return this
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* @param {ConditionLike} condition
|
|
968
|
+
*/
|
|
969
|
+
where (condition) {
|
|
970
|
+
this.#where = new SqlWhere(condition);
|
|
971
|
+
|
|
972
|
+
return this
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
toString () {
|
|
976
|
+
return `SELECT ${this.#columns.length === 0 ? '*' : this.#columns.join(',\n')}` +
|
|
977
|
+
`\n${this.#from}` +
|
|
978
|
+
(this.#join ? `\n${this.#join.join('\n')}` : '') +
|
|
979
|
+
(this.#where ? `\n${this.#where}` : '') +
|
|
980
|
+
(this.#orderby ? `\n${this.#orderby}` : '') +
|
|
981
|
+
(this.#groupby ? `\n${this.#groupby}` : '') +
|
|
982
|
+
(this.#limit ? `\n${this.#limit}` : '')
|
|
983
|
+
}
|
|
983
984
|
}
|
|
984
985
|
|
|
985
986
|
class SqlSelectDistinct extends SqlQuery {
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
987
|
+
/**
|
|
988
|
+
* @type {ColumnLike[]}
|
|
989
|
+
*/
|
|
990
|
+
#distinct
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* @type {ColumnLike}
|
|
994
|
+
*/
|
|
995
|
+
#from
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* @type {SqlGroupBy}
|
|
999
|
+
*/
|
|
1000
|
+
#groupby
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* @type {SqlJoin[]}
|
|
1004
|
+
*/
|
|
1005
|
+
#join
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* @type {SqlLimit}
|
|
1009
|
+
*/
|
|
1010
|
+
#limit
|
|
1011
|
+
|
|
1012
|
+
/**
|
|
1013
|
+
* @type {SqlWhere}
|
|
1014
|
+
*/
|
|
1015
|
+
#where
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* @type {SqlOrderBy}
|
|
1019
|
+
*/
|
|
1020
|
+
#orderby
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* @param {PostgreSQL} pgsql
|
|
1024
|
+
* @param {...ColumnLike} columns
|
|
1025
|
+
*/
|
|
1026
|
+
constructor (pgsql, ...columns) {
|
|
1027
|
+
super(pgsql);
|
|
1028
|
+
|
|
1029
|
+
this.#distinct = columns.map(column => typeof column === 'string' ? new SqlColumn(column) : column);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* @param {TableLike} table
|
|
1034
|
+
* @param {string} alias
|
|
1035
|
+
*/
|
|
1036
|
+
from (table, alias) {
|
|
1037
|
+
this.#from = new SqlFrom(table, alias);
|
|
1038
|
+
|
|
1039
|
+
return this
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* @param {...ColumnLike} columns
|
|
1044
|
+
*/
|
|
1045
|
+
groupby (...columns) {
|
|
1046
|
+
this.#groupby = new SqlGroupBy(...columns);
|
|
1047
|
+
|
|
1048
|
+
return this
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* @param {TableLike} table
|
|
1053
|
+
* @param {ConditionLike} condition
|
|
1054
|
+
*/
|
|
1055
|
+
join (table, condition) {
|
|
1056
|
+
if (!this.#join) {
|
|
1057
|
+
this.#join = [];
|
|
1058
|
+
}
|
|
1059
|
+
this.#join.push(new SqlJoin(table, condition));
|
|
1060
|
+
|
|
1061
|
+
return this
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* @param {TableLike} table
|
|
1066
|
+
* @param {string} alias
|
|
1067
|
+
*/
|
|
1068
|
+
joinInnerLateral (table, alias) {
|
|
1069
|
+
if (!this.#join) {
|
|
1070
|
+
this.#join = [];
|
|
1071
|
+
}
|
|
1072
|
+
this.#join.push(new SqlJoinInnerLateral(table, alias));
|
|
1073
|
+
|
|
1074
|
+
return this
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* @param {TableLike} table
|
|
1079
|
+
* @param {ConditionLike} condition
|
|
1080
|
+
*/
|
|
1081
|
+
joinLeft (table, condition) {
|
|
1082
|
+
if (!this.#join) {
|
|
1083
|
+
this.#join = [];
|
|
1084
|
+
}
|
|
1085
|
+
this.#join.push(new SqlJoinLeft(table, condition));
|
|
1086
|
+
|
|
1087
|
+
return this
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* @param {TableLike} table
|
|
1092
|
+
* @param {string} alias
|
|
1093
|
+
*/
|
|
1094
|
+
joinLeftLateral (table, alias) {
|
|
1095
|
+
if (!this.#join) {
|
|
1096
|
+
this.#join = [];
|
|
1097
|
+
}
|
|
1098
|
+
this.#join.push(new SqlJoinLeftLateral(table, alias));
|
|
1099
|
+
|
|
1100
|
+
return this
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/**
|
|
1104
|
+
* @param {number} count
|
|
1105
|
+
*/
|
|
1106
|
+
limit (count) {
|
|
1107
|
+
this.#limit = new SqlLimit(count);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* @param {...ColumnLike} columns
|
|
1112
|
+
*/
|
|
1113
|
+
orderby (...columns) {
|
|
1114
|
+
this.orderby = new SqlOrderBy(...columns);
|
|
1115
|
+
|
|
1116
|
+
return this
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* @param {ConditionLike} condition
|
|
1121
|
+
*/
|
|
1122
|
+
where (condition) {
|
|
1123
|
+
this.#where = SqlWhere(condition);
|
|
1124
|
+
|
|
1125
|
+
return this
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
toString () {
|
|
1129
|
+
return `SELECT DISTINCT ${this.#distinct.length === 0 ? '*' : this.#distinct.join(',\n')}` +
|
|
1130
|
+
`\n${this.#from}` +
|
|
1131
|
+
(this.#join ? `\n${this.#join.join('\n')}` : '') +
|
|
1132
|
+
(this.#where ? `\n${this.#where}` : '') +
|
|
1133
|
+
(this.#orderby ? `\n${this.#orderby}` : '') +
|
|
1134
|
+
(this.#groupby ? `\n${this.#groupby}` : '') +
|
|
1135
|
+
(this.#limit ? `\n${this.#limit}` : '')
|
|
1136
|
+
}
|
|
1136
1137
|
}
|
|
1137
1138
|
|
|
1138
1139
|
class SqlSelectDistinctOn extends SqlQuery {
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1140
|
+
/**
|
|
1141
|
+
* @type {ColumnLike[]}
|
|
1142
|
+
*/
|
|
1143
|
+
#distinct;
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* @type {ColumnLike[]}
|
|
1147
|
+
*/
|
|
1148
|
+
#columns;
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* @type {SqlFrom}
|
|
1152
|
+
*/
|
|
1153
|
+
#from;
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* @type {SqlGroupBy}
|
|
1157
|
+
*/
|
|
1158
|
+
#groupby;
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* @type {SqlJoin[]}
|
|
1162
|
+
*/
|
|
1163
|
+
#join;
|
|
1164
|
+
|
|
1165
|
+
/**
|
|
1166
|
+
* @type {SqlLimit}
|
|
1167
|
+
*/
|
|
1168
|
+
#limit;
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* @type {SqlOrderBy}
|
|
1172
|
+
*/
|
|
1173
|
+
#orderby;
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* @type {SqlWhere}
|
|
1177
|
+
*/
|
|
1178
|
+
#where;
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* @param {PostgreSQL} pgsql
|
|
1182
|
+
* @param {...ColumnLike} columns
|
|
1183
|
+
*/
|
|
1184
|
+
constructor(pgsql, ...columns) {
|
|
1185
|
+
super(pgsql);
|
|
1186
|
+
|
|
1187
|
+
this.#distinct = columns.map(column => typeof column === 'string' ? new SqlColumn(column) : column);
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* @param {TableLike} table
|
|
1192
|
+
* @param {string} alias
|
|
1193
|
+
*/
|
|
1194
|
+
from(table, alias) {
|
|
1195
|
+
this.#from = new SqlFrom(table, alias);
|
|
1196
|
+
|
|
1197
|
+
return this;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* @param {...ColumnLike} columns
|
|
1202
|
+
*/
|
|
1203
|
+
groupby(...columns) {
|
|
1204
|
+
this.#groupby = new SqlGroupBy(...columns);
|
|
1205
|
+
|
|
1206
|
+
return this;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
/**
|
|
1210
|
+
* @param {TableLike} table
|
|
1211
|
+
* @param {ConditionLike} condition
|
|
1212
|
+
*/
|
|
1213
|
+
join(table, condition) {
|
|
1214
|
+
if (!this.#join) {
|
|
1215
|
+
this.#join = [];
|
|
1216
|
+
}
|
|
1217
|
+
this.#join.push(new SqlJoin(table, condition));
|
|
1218
|
+
|
|
1219
|
+
return this;
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
/**
|
|
1223
|
+
* @param {TableLike} table
|
|
1224
|
+
* @param {string} alias
|
|
1225
|
+
*/
|
|
1226
|
+
joinInnerLateral(table, alias) {
|
|
1227
|
+
if (!this.#join) {
|
|
1228
|
+
this.#join = [];
|
|
1229
|
+
}
|
|
1230
|
+
this.#join.push(new SqlJoinInnerLateral(table, alias));
|
|
1231
|
+
|
|
1232
|
+
return this;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
/**
|
|
1236
|
+
* @param {TableLike} table
|
|
1237
|
+
* @param {ConditionLike} condition
|
|
1238
|
+
*/
|
|
1239
|
+
joinLeft(table, condition) {
|
|
1240
|
+
if (!this.#join) {
|
|
1241
|
+
this.#join = [];
|
|
1242
|
+
}
|
|
1243
|
+
this.#join.push(new SqlJoinLeft(table, condition));
|
|
1244
|
+
|
|
1245
|
+
return this;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* @param {TableLike} table
|
|
1250
|
+
* @param {string} alias
|
|
1251
|
+
*/
|
|
1252
|
+
joinLeftLateral(table, alias) {
|
|
1253
|
+
if (!this.#join) {
|
|
1254
|
+
this.#join = [];
|
|
1255
|
+
}
|
|
1256
|
+
this.#join.push(new SqlJoinLeftLateral(table, alias));
|
|
1257
|
+
|
|
1258
|
+
return this;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* @param {number} count
|
|
1263
|
+
*/
|
|
1264
|
+
limit(count) {
|
|
1265
|
+
this.#limit = new SqlLimit(count);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* @param {...ColumnLike} columns
|
|
1270
|
+
*/
|
|
1271
|
+
orderby(...columns) {
|
|
1272
|
+
this.orderby = new SqlOrderBy(...columns);
|
|
1273
|
+
|
|
1274
|
+
return this;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* @param {...ColumnLike} columns
|
|
1279
|
+
*/
|
|
1280
|
+
select(...columns) {
|
|
1281
|
+
this.#columns = columns.map(column => typeof column === 'string' ? new SqlColumn(column) : column);
|
|
1282
|
+
|
|
1283
|
+
return this;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
/**
|
|
1287
|
+
* @param {ConditionLike} condition
|
|
1288
|
+
*/
|
|
1289
|
+
where(condition) {
|
|
1290
|
+
this.#where = new SqlWhere(condition);
|
|
1291
|
+
|
|
1292
|
+
return this;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
toString() {
|
|
1296
|
+
return `SELECT DISTINCT ON (${this.#distinct.join(',')})\n ${this.#columns.length === 0 ? '*' : this.#columns.join(',\n')}` +
|
|
1297
|
+
`\n${this.#from}` +
|
|
1298
|
+
(this.#join ? `\n${this.#join.join('\n')}` : '') +
|
|
1299
|
+
(this.#where ? `\n${this.#where}` : '') +
|
|
1300
|
+
(this.#orderby ? `\n${this.#orderby}` : '') +
|
|
1301
|
+
(this.#groupby ? `\n${this.#groupby}` : '') +
|
|
1302
|
+
(this.#limit ? `\n${this.#limit}` : '');
|
|
1303
|
+
}
|
|
1301
1304
|
}
|
|
1302
1305
|
|
|
1303
1306
|
class SqlUnion {
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1307
|
+
#statements
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* @param {...SqlQuery} statements
|
|
1311
|
+
*/
|
|
1312
|
+
constructor (...statements) {
|
|
1313
|
+
this.#statements = statements;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
toString () {
|
|
1317
|
+
return this.#statements.map(statement => `(\n${statement}\n)`).join('\nUNION\n')
|
|
1318
|
+
}
|
|
1316
1319
|
}
|
|
1317
1320
|
|
|
1318
1321
|
class ValueLike {
|
|
@@ -1320,424 +1323,379 @@ class ValueLike {
|
|
|
1320
1323
|
}
|
|
1321
1324
|
|
|
1322
1325
|
class SqlAll extends ValueLike {
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1326
|
+
#statement
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* @param {ColumnLike} statement
|
|
1330
|
+
*/
|
|
1331
|
+
constructor (statement) {
|
|
1332
|
+
super();
|
|
1333
|
+
this.#statement = statement;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
toString () {
|
|
1337
|
+
return `ALL(${this.#statement})`
|
|
1338
|
+
}
|
|
1336
1339
|
}
|
|
1337
1340
|
|
|
1338
1341
|
class SqlAny extends ValueLike {
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1342
|
+
#statement
|
|
1343
|
+
|
|
1344
|
+
/**
|
|
1345
|
+
* @param {ColumnLike} statement
|
|
1346
|
+
*/
|
|
1347
|
+
constructor (statement) {
|
|
1348
|
+
super();
|
|
1349
|
+
this.#statement = statement;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
toString () {
|
|
1353
|
+
return `ANY(${this.#statement})`
|
|
1354
|
+
}
|
|
1352
1355
|
}
|
|
1353
1356
|
|
|
1354
1357
|
class SqlConstant extends ValueLike {
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1358
|
+
#name
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* @param {string} name
|
|
1362
|
+
*/
|
|
1363
|
+
constructor (name) {
|
|
1364
|
+
super();
|
|
1365
|
+
this.#name = name;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
toString () {
|
|
1369
|
+
return this.#name
|
|
1370
|
+
}
|
|
1368
1371
|
}
|
|
1369
1372
|
|
|
1370
1373
|
class PostgreSQL {
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
*/
|
|
1697
|
-
notLike(left, right) {
|
|
1698
|
-
return new SqlNotLike(left, right)
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
/**
|
|
1703
|
-
* @param {ColumnLike} left
|
|
1704
|
-
* @param {ColumnLike} right
|
|
1705
|
-
*/
|
|
1706
|
-
notMatch(left, right) {
|
|
1707
|
-
return new SqlNotMatch(left, right)
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
/**
|
|
1712
|
-
* @param {...ConditionLike} conditions
|
|
1713
|
-
*/
|
|
1714
|
-
or(...conditions) {
|
|
1715
|
-
return new SqlOr(...conditions)
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
// #endregion
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
// #region Value-like
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
/**
|
|
1725
|
-
* @param {ColumnLike} statement
|
|
1726
|
-
*/
|
|
1727
|
-
all(statement) {
|
|
1728
|
-
return new SqlAll(statement)
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
/**
|
|
1733
|
-
* @param {ColumnLike} statement
|
|
1734
|
-
*/
|
|
1735
|
-
any(statement) {
|
|
1736
|
-
return new SqlAny(statement)
|
|
1737
|
-
}
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
// #endregion
|
|
1374
|
+
/**
|
|
1375
|
+
* @param {pg.PoolConfig} options
|
|
1376
|
+
*/
|
|
1377
|
+
constructor (options) {
|
|
1378
|
+
/**
|
|
1379
|
+
* @type {pg.Pool}
|
|
1380
|
+
*/
|
|
1381
|
+
this.pool = new pg.Pool(options);
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
// #region Queries
|
|
1385
|
+
|
|
1386
|
+
/**
|
|
1387
|
+
* @param {...ColumnLike} columns
|
|
1388
|
+
*/
|
|
1389
|
+
insert (...columns) {
|
|
1390
|
+
return new SqlInsert(this, ...columns)
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* @param {...ColumnLike} columns
|
|
1395
|
+
*/
|
|
1396
|
+
select (...columns) {
|
|
1397
|
+
return new SqlSelect(this, ...columns)
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* @param {...ColumnLike} columns
|
|
1402
|
+
*/
|
|
1403
|
+
selectDistinct (...columns) {
|
|
1404
|
+
return new SqlSelectDistinct(this, ...columns)
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
/**
|
|
1408
|
+
* @param {...ColumnLike} columns
|
|
1409
|
+
*/
|
|
1410
|
+
selectDistinctOn (...columns) {
|
|
1411
|
+
return new SqlSelectDistinctOn(this, ...columns)
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
/**
|
|
1415
|
+
* @param {...SqlQuery} statements
|
|
1416
|
+
*/
|
|
1417
|
+
union (...statements) {
|
|
1418
|
+
return new SqlUnion(...statements)
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
// #endregion
|
|
1422
|
+
|
|
1423
|
+
// #region Constants
|
|
1424
|
+
|
|
1425
|
+
CURRENT_DATE = new SqlConstant('CURRENT_DATE')
|
|
1426
|
+
|
|
1427
|
+
FALSE = new SqlConstant('FALSE')
|
|
1428
|
+
|
|
1429
|
+
NULL = new SqlConstant('NULL')
|
|
1430
|
+
|
|
1431
|
+
TRUE = new SqlConstant('TRUE')
|
|
1432
|
+
|
|
1433
|
+
// #endregion
|
|
1434
|
+
|
|
1435
|
+
// #region Column-like
|
|
1436
|
+
|
|
1437
|
+
case () {
|
|
1438
|
+
return new SqlCase()
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* @param {ColumnLike} left
|
|
1443
|
+
* @param {ColumnLike} right
|
|
1444
|
+
*/
|
|
1445
|
+
coalese (left, right) {
|
|
1446
|
+
return new SqlCoalesce(left, right)
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
/**
|
|
1450
|
+
* @param {string} name
|
|
1451
|
+
*/
|
|
1452
|
+
column (name) {
|
|
1453
|
+
return new SqlColumn(name)
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* @param {...ColumnLike} columns
|
|
1458
|
+
*/
|
|
1459
|
+
concat (...columns) {
|
|
1460
|
+
return new SqlConcat(...columns)
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
/**
|
|
1464
|
+
* @param {number} value
|
|
1465
|
+
* @param {string} unit
|
|
1466
|
+
*/
|
|
1467
|
+
dateinterval (value, unit) {
|
|
1468
|
+
return new SqlDateInterval(value, unit)
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
/**
|
|
1472
|
+
* @param {string} part
|
|
1473
|
+
* @param {ColumnLike} column
|
|
1474
|
+
*/
|
|
1475
|
+
datepart (part, column) {
|
|
1476
|
+
return new SqlDatePart(part, column)
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
/**
|
|
1480
|
+
* @param {string} part
|
|
1481
|
+
* @param {ColumnLike} column
|
|
1482
|
+
*/
|
|
1483
|
+
datetrunc (part, column) {
|
|
1484
|
+
return new SqlDateTrunc(part, column)
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
/**
|
|
1488
|
+
* @param {ColumnLike} column
|
|
1489
|
+
* @param {number} length
|
|
1490
|
+
* @param {string} fill
|
|
1491
|
+
*/
|
|
1492
|
+
lpad (column, length, fill) {
|
|
1493
|
+
return new SqlLPad(column, length, fill)
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* @param {ColumnLike} column
|
|
1498
|
+
*/
|
|
1499
|
+
max (column) {
|
|
1500
|
+
return new SqlMax(column)
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
/**
|
|
1504
|
+
* @param {number} number
|
|
1505
|
+
*/
|
|
1506
|
+
param (number) {
|
|
1507
|
+
return new SqlParameter(number)
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
/**
|
|
1511
|
+
* @param {ColumnLike} column
|
|
1512
|
+
* @param {number} length
|
|
1513
|
+
* @param {string} fill
|
|
1514
|
+
*/
|
|
1515
|
+
rpad (column, length, fill) {
|
|
1516
|
+
return new SqlRPad(column, length, fill)
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
/**
|
|
1520
|
+
* @param {string} value
|
|
1521
|
+
*/
|
|
1522
|
+
string (value) {
|
|
1523
|
+
return new SqlString(value)
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
/**
|
|
1527
|
+
* @param {ColumnLike} column
|
|
1528
|
+
* @param {string} separator
|
|
1529
|
+
* @param {boolean} distinct
|
|
1530
|
+
*/
|
|
1531
|
+
stringagg (column, separator, distinct = true) {
|
|
1532
|
+
return new SqlStringAgg(column, separator, distinct)
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
/**
|
|
1536
|
+
* @param {ColumnLike} column
|
|
1537
|
+
* @param {string} separator
|
|
1538
|
+
* @param {string=} replace
|
|
1539
|
+
*/
|
|
1540
|
+
stringtoarray (column, separator, replace) {
|
|
1541
|
+
return new SqlStringToArray(column, separator, replace)
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
/**
|
|
1545
|
+
* @param {ColumnLike} column
|
|
1546
|
+
* @param {string} pattern
|
|
1547
|
+
*/
|
|
1548
|
+
substring (column, pattern) {
|
|
1549
|
+
return new SqlSubString(column, pattern)
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
// #endregion
|
|
1553
|
+
|
|
1554
|
+
// #region Condition-like
|
|
1555
|
+
|
|
1556
|
+
/**
|
|
1557
|
+
* @param {...ConditionLike} conditions
|
|
1558
|
+
*/
|
|
1559
|
+
and (...conditions) {
|
|
1560
|
+
return new SqlAnd(...conditions)
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
/**
|
|
1564
|
+
* @param {ColumnLike} left
|
|
1565
|
+
* @param {ColumnLike} right
|
|
1566
|
+
*/
|
|
1567
|
+
equal (left, right) {
|
|
1568
|
+
return new SqlEqual(left, right)
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
/**
|
|
1572
|
+
* @param {ColumnLike} left
|
|
1573
|
+
* @param {ColumnLike} right
|
|
1574
|
+
*/
|
|
1575
|
+
greaterThan (left, right) {
|
|
1576
|
+
return new SqlGreaterThan(left, right)
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
/**
|
|
1580
|
+
* @param {ColumnLike} left
|
|
1581
|
+
* @param {ColumnLike} right
|
|
1582
|
+
*/
|
|
1583
|
+
greaterThanOrEqual (left, right) {
|
|
1584
|
+
return new SqlGreaterThanOrEqual(left, right)
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
/**
|
|
1588
|
+
* @param {ColumnLike} left
|
|
1589
|
+
* @param {ColumnLike} right
|
|
1590
|
+
*/
|
|
1591
|
+
ilike (left, right) {
|
|
1592
|
+
return new SqlILike(left, right)
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
/**
|
|
1596
|
+
* @param {ColumnLike} column
|
|
1597
|
+
*/
|
|
1598
|
+
isNotNull (column) {
|
|
1599
|
+
return new SqlIsNotNull(column)
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* @param {ColumnLike} column
|
|
1604
|
+
*/
|
|
1605
|
+
isNull (column) {
|
|
1606
|
+
return new SqlIsNull(column)
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* @param {ColumnLike} left
|
|
1611
|
+
* @param {ColumnLike} right
|
|
1612
|
+
*/
|
|
1613
|
+
lessThan (left, right) {
|
|
1614
|
+
return new SqlLessThan(left, right)
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
/**
|
|
1618
|
+
* @param {ColumnLike} left
|
|
1619
|
+
* @param {ColumnLike} right
|
|
1620
|
+
*/
|
|
1621
|
+
lessThanOrEqual (left, right) {
|
|
1622
|
+
return new SqlLessThanOrEqual(left, right)
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
/**
|
|
1626
|
+
* @param {ColumnLike} left
|
|
1627
|
+
* @param {ColumnLike} right
|
|
1628
|
+
*/
|
|
1629
|
+
like (left, right) {
|
|
1630
|
+
return new SqlLike(left, right)
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
/**
|
|
1634
|
+
* @param {ColumnLike} left
|
|
1635
|
+
* @param {ColumnLike} right
|
|
1636
|
+
*/
|
|
1637
|
+
match (left, right) {
|
|
1638
|
+
return new SqlMatch(left, right)
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
/**
|
|
1642
|
+
* @param {ColumnLike} left
|
|
1643
|
+
* @param {ColumnLike} right
|
|
1644
|
+
*/
|
|
1645
|
+
notEqual (left, right) {
|
|
1646
|
+
return new SqlNotEqual(left, right)
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
/**
|
|
1650
|
+
* @param {ColumnLike} left
|
|
1651
|
+
* @param {ColumnLike} right
|
|
1652
|
+
*/
|
|
1653
|
+
notILike (left, right) {
|
|
1654
|
+
return new SqlNotILike(left, right)
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
/**
|
|
1658
|
+
* @param {ColumnLike} left
|
|
1659
|
+
* @param {ColumnLike} right
|
|
1660
|
+
*/
|
|
1661
|
+
notLike (left, right) {
|
|
1662
|
+
return new SqlNotLike(left, right)
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
/**
|
|
1666
|
+
* @param {ColumnLike} left
|
|
1667
|
+
* @param {ColumnLike} right
|
|
1668
|
+
*/
|
|
1669
|
+
notMatch (left, right) {
|
|
1670
|
+
return new SqlNotMatch(left, right)
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/**
|
|
1674
|
+
* @param {...ConditionLike} conditions
|
|
1675
|
+
*/
|
|
1676
|
+
or (...conditions) {
|
|
1677
|
+
return new SqlOr(...conditions)
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
// #endregion
|
|
1681
|
+
|
|
1682
|
+
// #region Value-like
|
|
1683
|
+
|
|
1684
|
+
/**
|
|
1685
|
+
* @param {ColumnLike} statement
|
|
1686
|
+
*/
|
|
1687
|
+
all (statement) {
|
|
1688
|
+
return new SqlAll(statement)
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
/**
|
|
1692
|
+
* @param {ColumnLike} statement
|
|
1693
|
+
*/
|
|
1694
|
+
any (statement) {
|
|
1695
|
+
return new SqlAny(statement)
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
// #endregion
|
|
1741
1699
|
}
|
|
1742
1700
|
|
|
1743
1701
|
exports.PostgreSQL = PostgreSQL;
|