@trenskow/pged 4.0.8 → 4.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/query-builder.js +13 -13
package/package.json
CHANGED
package/query-builder.js
CHANGED
|
@@ -49,8 +49,8 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
|
|
|
49
49
|
.split('.')
|
|
50
50
|
.map((part) => {
|
|
51
51
|
let doQuote = quote;
|
|
52
|
-
if (part.
|
|
53
|
-
part = part.
|
|
52
|
+
if (part.substring(0, 1) === '!' && quote) {
|
|
53
|
+
part = part.substring(1);
|
|
54
54
|
doQuote = false;
|
|
55
55
|
}
|
|
56
56
|
part = part
|
|
@@ -189,8 +189,8 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
|
|
|
189
189
|
options.conditions = {};
|
|
190
190
|
options.local = options.local || this._defaultPrimaryKey;
|
|
191
191
|
options.foreign = options.foreign || this._defaultPrimaryKey;
|
|
192
|
-
let local = options.local.
|
|
193
|
-
let foreign = options.foreign.
|
|
192
|
+
let local = options.local.substring(0, 1) == ':' ? this._dbCase(options.local) : `:${this._table}.${this._dbCase(options.local)}`;
|
|
193
|
+
let foreign = options.foreign.substring(0, 1) == ':' ? this._dbCase(options.foreign.substring(1)) : `${this._dbCase(options.table)}.${this._dbCase(options.foreign)}`;
|
|
194
194
|
options.conditions[local] = foreign;
|
|
195
195
|
}
|
|
196
196
|
options.conditions = this._formalizeConditions(options.conditions);
|
|
@@ -270,7 +270,7 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
|
|
|
270
270
|
|
|
271
271
|
_buildKeys(keys = ['*'], quote) {
|
|
272
272
|
return keys.map((key) => {
|
|
273
|
-
if (key.
|
|
273
|
+
if (key.substring(0, 1) == ':') return key.substring(1);
|
|
274
274
|
let as = key.split(':');
|
|
275
275
|
if (as.length == 1) return this._dbCase(as[0], quote && this._canQuote(key));
|
|
276
276
|
return `${this._dbCase(as[0], quote)} as ${this._dbCase(as[1])}`;
|
|
@@ -322,7 +322,7 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
|
|
|
322
322
|
|
|
323
323
|
let key = Object.keys(condition)[0];
|
|
324
324
|
|
|
325
|
-
if (key.
|
|
325
|
+
if (key.substring(0, 1) == '$') {
|
|
326
326
|
switch (caseit(key)) {
|
|
327
327
|
case '$or':
|
|
328
328
|
case '$and':
|
|
@@ -344,15 +344,15 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
-
if (key.
|
|
348
|
-
return this._buildCondition(key.
|
|
347
|
+
if (key.substring(0, 1) == ':') {
|
|
348
|
+
return this._buildCondition(key.substring(1), comparer, this._dbCase(condition[key]));
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
let dbKey = key;
|
|
352
352
|
|
|
353
353
|
if (dbKey.indexOf('.') == -1) {
|
|
354
|
-
if (dbKey.
|
|
355
|
-
dbKey = dbKey.
|
|
354
|
+
if (dbKey.substring(0, 1) === '!') {
|
|
355
|
+
dbKey = dbKey.substring(1);
|
|
356
356
|
} else {
|
|
357
357
|
dbKey = dbKey
|
|
358
358
|
.split('->')
|
|
@@ -421,11 +421,11 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
|
|
|
421
421
|
_buildSorting() {
|
|
422
422
|
if (!this._sortingKeys.length) return;
|
|
423
423
|
const escapeIfNeeded = (value) => {
|
|
424
|
-
if (value.
|
|
424
|
+
if (value.substring(0, 1) == ':') return value.substring(1);
|
|
425
425
|
return this._dbCase(value, true);
|
|
426
426
|
};
|
|
427
427
|
return `order by ${this._sortingKeys.map((key) => {
|
|
428
|
-
if (key.
|
|
428
|
+
if (key.substring(0, 1) == '-') return `${escapeIfNeeded(key.substring(1))} desc`;
|
|
429
429
|
return escapeIfNeeded(key);
|
|
430
430
|
}).join(', ')}`;
|
|
431
431
|
}
|
|
@@ -446,7 +446,7 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
|
|
|
446
446
|
if (value == null) {
|
|
447
447
|
value = 'null';
|
|
448
448
|
} else if (/^:/.test(value)) {
|
|
449
|
-
value = value.
|
|
449
|
+
value = value.substring(1);
|
|
450
450
|
} else {
|
|
451
451
|
this._queryParameters.push(value);
|
|
452
452
|
value = `$${this._queryParameters.length}`;
|