@trenskow/pged 4.0.1 → 4.0.5

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 +2 -1
  2. package/query-builder.js +14 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/pged",
3
- "version": "4.0.1",
3
+ "version": "4.0.5",
4
4
  "description": "Just a silly little db management and query builder for PostgreSQL.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,6 +23,7 @@
23
23
  "homepage": "https://github.com/trenskow/pged#readme",
24
24
  "dependencies": {
25
25
  "@trenskow/caseit": "^1.1.0",
26
+ "@trenskow/custom-promise": "^0.10.1",
26
27
  "pg": "^8.7.1",
27
28
  "puqeue": "^1.0.5"
28
29
  }
package/query-builder.js CHANGED
@@ -1,12 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  const
4
- caseit = require('@trenskow/caseit');
4
+ caseit = require('@trenskow/caseit'),
5
+ CustomPromise = require('@trenskow/custom-promise');
5
6
 
6
- module.exports = exports = class QueryBuilder {
7
+ module.exports = exports = class QueryBuilder extends CustomPromise {
7
8
 
8
9
  constructor(table, options = {}, executor) {
9
10
 
11
+ super();
12
+
10
13
  this._options = options;
11
14
 
12
15
  options.casing = options.casing || {};
@@ -277,7 +280,8 @@ module.exports = exports = class QueryBuilder {
277
280
  $gte: '>=',
278
281
  $regexp: '~*',
279
282
  $jsonContains: '@>',
280
- $jsonNotContains: '@>'
283
+ $jsonNotContains: '@>',
284
+ $jsonArrayContains: '?'
281
285
  };
282
286
  }
283
287
 
@@ -318,6 +322,7 @@ module.exports = exports = class QueryBuilder {
318
322
  case '$regexp':
319
323
  case '$jsonContains':
320
324
  case '$jsonNotContains':
325
+ case '$jsonArrayContains':
321
326
  return this._buildConditions(condition[key], operator, key, true);
322
327
  default:
323
328
  throw new TypeError(`Unknown modifier ${caseit(key)}.`);
@@ -416,7 +421,7 @@ module.exports = exports = class QueryBuilder {
416
421
  }
417
422
 
418
423
  _buildLimit() {
419
- if ((this._limit || Infinity) == Infinity) return;
424
+ if (typeof this._limit === 'undefined') return;
420
425
  return `limit ${this._limit}`;
421
426
  }
422
427
 
@@ -546,8 +551,11 @@ module.exports = exports = class QueryBuilder {
546
551
  return rows;
547
552
  }
548
553
 
549
- async go() {
550
- return await this._exec();
554
+ then(resolve, reject) {
555
+ super.then(resolve, reject);
556
+ this._exec()
557
+ .then((...args) => this._resolve(...args))
558
+ .catch((error) => this._reject(error));
551
559
  }
552
560
 
553
561
  };