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