@trenskow/pged 5.0.21 → 5.0.22

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/query-builder.js +10 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/pged",
3
- "version": "5.0.21",
3
+ "version": "5.0.22",
4
4
  "description": "Just a silly little db management and query builder for PostgreSQL.",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/query-builder.js CHANGED
@@ -201,7 +201,8 @@ export default class QueryBuilder extends CustomPromise {
201
201
  options.local = options.local || this._defaultPrimaryKey;
202
202
  options.foreign = options.foreign || this._defaultPrimaryKey;
203
203
  let local = options.local.substring(0, 1) == ':' ? this._dbCase(options.local) : `:${this._table}.${this._dbCase(options.local)}`;
204
- let foreign = options.foreign.substring(0, 1) == ':' ? this._dbCase(options.foreign.substring(1)) : `${this._dbCase(options.table)}.${this._dbCase(options.foreign)}`;
204
+ let direct = local.substring(0, 1) == ':' ? ':' : '';
205
+ let foreign = options.foreign.substring(0, 1) == ':' ? `${direct}${this._dbCase(options.foreign.substring(1))}` : `${direct}${this._dbCase(options.table)}.${this._dbCase(options.foreign)}`;
205
206
  options.conditions[local] = foreign;
206
207
  }
207
208
  options.conditions = this._formalizeConditions(options.conditions);
@@ -367,8 +368,14 @@ export default class QueryBuilder extends CustomPromise {
367
368
  }
368
369
 
369
370
  if (key.substring(0, 1) == ':') {
370
- this._queryParameters.push(this._formatParameter(key, condition[key]));
371
- return this._buildCondition(key.substring(1), comparer, `$${this._queryParameters.length}`);
371
+ let value = condition[key];
372
+ if (typeof value === 'string' && value.substring(0, 1) == ':') {
373
+ value = this._dbCase(condition[key].substring(1));
374
+ } else {
375
+ this._queryParameters.push(this._formatParameter(key, condition[key]));
376
+ value = `$${this._queryParameters.length}`;
377
+ }
378
+ return this._buildCondition(key.substring(1), comparer, value);
372
379
  }
373
380
 
374
381
  let dbKey = key;