@trenskow/pged 5.1.115 → 5.1.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/query-builder.js +24 -3
- package/package.json +7 -7
package/lib/query-builder.js
CHANGED
|
@@ -283,23 +283,34 @@ export default class QueryBuilder extends CustomPromise {
|
|
|
283
283
|
...options
|
|
284
284
|
.filter((options) => options)
|
|
285
285
|
.map((options) => {
|
|
286
|
+
|
|
286
287
|
if (typeof options !== 'object') throw new TypeError('Option must be an object');
|
|
288
|
+
|
|
287
289
|
if (!options.table) throw new SyntaxError('Missing table.');
|
|
290
|
+
|
|
291
|
+
if (typeof options.table === 'string') options.table = Object.fromEntries([[options.table, options.table]]);
|
|
292
|
+
|
|
293
|
+
const [, alias] = Object.entries(options.table)[0];
|
|
294
|
+
|
|
288
295
|
if (!options.conditions) {
|
|
289
296
|
options.conditions = {};
|
|
290
297
|
options.local = options.local || this._defaultPrimaryKey;
|
|
291
298
|
options.foreign = options.foreign || this._defaultPrimaryKey;
|
|
292
299
|
let local = options.local.substring(0, 1) == ':' ? this._dbCase(options.local) : `:${this._table}.${this._dbCase(options.local)}`;
|
|
293
300
|
let direct = local.substring(0, 1) == ':' ? ':' : '';
|
|
294
|
-
let foreign = options.foreign.substring(0, 1) == ':' ? `${direct}${this._dbCase(options.foreign.substring(1))}` : `${direct}${this._dbCase(
|
|
301
|
+
let foreign = options.foreign.substring(0, 1) == ':' ? `${direct}${this._dbCase(options.foreign.substring(1))}` : `${direct}${this._dbCase(alias)}.${this._dbCase(options.foreign)}`;
|
|
295
302
|
options.conditions[local] = foreign;
|
|
296
303
|
}
|
|
304
|
+
|
|
297
305
|
options.conditions = this._formalizeConditions(options.conditions);
|
|
298
306
|
options.required = options.required || 'both';
|
|
307
|
+
|
|
299
308
|
if (!['none', 'local', 'foreign', 'both'].includes(options.required)) {
|
|
300
309
|
throw new TypeError('Only `none`, `local`, `foreign`, `both` are supported by `options.required`.');
|
|
301
310
|
}
|
|
311
|
+
|
|
302
312
|
return options;
|
|
313
|
+
|
|
303
314
|
}));
|
|
304
315
|
return this;
|
|
305
316
|
}
|
|
@@ -546,18 +557,28 @@ export default class QueryBuilder extends CustomPromise {
|
|
|
546
557
|
|
|
547
558
|
_buildJoins() {
|
|
548
559
|
return this._joins.map((join) => {
|
|
560
|
+
|
|
561
|
+
const [table, alias] = Object.entries(join.table)[0];
|
|
562
|
+
|
|
563
|
+
const target = table !== alias ? `${this._dbCase(table)} as ${this._dbCase(alias)}` : this._dbCase(table);
|
|
564
|
+
|
|
549
565
|
if (join.conditions) {
|
|
566
|
+
|
|
550
567
|
let type;
|
|
568
|
+
|
|
551
569
|
switch (join.required) {
|
|
552
570
|
case 'both': type = 'join'; break;
|
|
553
571
|
case 'local': type = 'left join'; break;
|
|
554
572
|
case 'foreign': type = 'right join'; break;
|
|
555
573
|
case 'none': type = 'outer join'; break;
|
|
556
574
|
}
|
|
557
|
-
|
|
575
|
+
|
|
576
|
+
return `${type} ${target} on ${this._buildConditions(join.conditions)}`;
|
|
577
|
+
|
|
558
578
|
} else {
|
|
559
|
-
return `cross join ${
|
|
579
|
+
return `cross join ${target}`;
|
|
560
580
|
}
|
|
581
|
+
|
|
561
582
|
}).join(' ');
|
|
562
583
|
}
|
|
563
584
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trenskow/pged",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.117",
|
|
4
4
|
"description": "Just a silly little db management and query builder for PostgreSQL.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"@trenskow/async-event-emitter": "^0.1.97",
|
|
27
27
|
"@trenskow/caseit": "^1.4.21",
|
|
28
28
|
"@trenskow/custom-promise": "^0.13.18",
|
|
29
|
-
"@trenskow/parse": "^0.1.
|
|
30
|
-
"@trenskow/wait": "^1.3.
|
|
31
|
-
"pg": "^8.
|
|
29
|
+
"@trenskow/parse": "^0.1.46",
|
|
30
|
+
"@trenskow/wait": "^1.3.93",
|
|
31
|
+
"pg": "^8.20.0",
|
|
32
32
|
"puqeue": "^1.1.29"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@eslint/eslintrc": "^3.3.
|
|
35
|
+
"@eslint/eslintrc": "^3.3.5",
|
|
36
36
|
"@eslint/js": "^10.0.1",
|
|
37
|
-
"eslint": "^10.
|
|
38
|
-
"globals": "^17.
|
|
37
|
+
"eslint": "^10.1.0",
|
|
38
|
+
"globals": "^17.4.0"
|
|
39
39
|
}
|
|
40
40
|
}
|