@trenskow/pged 3.0.2 → 4.0.3

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/README.md CHANGED
@@ -15,7 +15,8 @@ const updatedUser = await db.transaction(async () => {
15
15
  await db
16
16
  .from('users')
17
17
  .where({ id: 12 })
18
- .update({ username: 'myusername' });
18
+ .update({ username: 'myusername' })
19
+ .go();
19
20
 
20
21
  return await db
21
22
  .from('users')
@@ -26,7 +27,8 @@ const updatedUser = await db.transaction(async () => {
26
27
  id: 12,
27
28
  username: 'myusername'
28
29
  }
29
- });
30
+ })
31
+ .go();
30
32
 
31
33
  });
32
34
  ````
@@ -39,11 +41,11 @@ Transactions can be inside transactions - the library will figure out when to co
39
41
 
40
42
  These options are supported when creating a new `PGed` instance.
41
43
 
42
- | Name | Type | Description | Values | Default |
43
- |:------------|:------------:|:------------|:-------|:-----------|
44
- | `casing` | `Object` | See below
45
- | `casing.db` | `String` | The casing to use in the db. | Any supported by the [caseit](https://www.npmjs.com/package/@trenskow/caseit) package. | `snake` |
46
- | `casing.js` | `String` | The casing to use in js. | Same as above | `camel`
44
+ | Name | Type | Description | Values | Default |
45
+ | :---------- | :------: | :--------------------------- | :------------------------------------------------------------------------------------- | :------ |
46
+ | `casing` | `Object` | See below |
47
+ | `casing.db` | `String` | The casing to use in the db. | Any supported by the [caseit](https://www.npmjs.com/package/@trenskow/caseit) package. | `snake` |
48
+ | `casing.js` | `String` | The casing to use in js. | Same as above | `camel` |
47
49
 
48
50
  ### PostgreSQL Connection
49
51
 
package/index.js CHANGED
@@ -3,8 +3,7 @@
3
3
  const
4
4
  Puqeue = require('puqeue'),
5
5
  caseit = require('@trenskow/caseit'),
6
- { Pool } = require('pg'),
7
- from = require('@trenskow/from');
6
+ { Pool } = require('pg');
8
7
 
9
8
  const
10
9
  QueryBuilder = require('./query-builder');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/pged",
3
- "version": "3.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Just a silly little db management and query builder for PostgreSQL.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,8 +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.9.1",
27
- "@trenskow/from": "^1.1.11",
26
+ "@trenskow/custom-promise": "^0.10.1",
28
27
  "pg": "^8.7.1",
29
28
  "puqeue": "^1.0.5"
30
29
  }
package/query-builder.js CHANGED
@@ -39,16 +39,6 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
39
39
 
40
40
  this._executor = executor;
41
41
 
42
- this._immediate = setImmediate(() => {
43
- this._exec()
44
- .then((result) => {
45
- this._resolve(result);
46
- })
47
- .catch((error) => {
48
- this._reject(error);
49
- });
50
- });
51
-
52
42
  }
53
43
 
54
44
  _dbCase(input, quote) {
@@ -78,7 +68,7 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
78
68
 
79
69
  select(keys = ['*']) {
80
70
  if (!Array.isArray(keys)) {
81
- keys = [].concat(...keys.split('\"').map((key, idx) => {
71
+ keys = [].concat(...keys.split('"').map((key, idx) => {
82
72
  if (idx % 2 == 0) return key.split(/, ?/);
83
73
  return [key];
84
74
  })).filter((key) => key);
@@ -290,7 +280,8 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
290
280
  $gte: '>=',
291
281
  $regexp: '~*',
292
282
  $jsonContains: '@>',
293
- $jsonNotContains: '@>'
283
+ $jsonNotContains: '@>',
284
+ $jsonArrayContains: '?'
294
285
  };
295
286
  }
296
287
 
@@ -301,7 +292,7 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
301
292
  }
302
293
 
303
294
  _buildCondition(lhs, comparer, rhs) {
304
- const casedComparer = caseit(comparer)
295
+ const casedComparer = caseit(comparer);
305
296
  const condition = `${lhs} ${this._comparerMap[casedComparer]} ${rhs}`;
306
297
  const prefix = this._comparerPrefixMap[casedComparer];
307
298
  if (!prefix) return condition;
@@ -331,6 +322,7 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
331
322
  case '$regexp':
332
323
  case '$jsonContains':
333
324
  case '$jsonNotContains':
325
+ case 'jsonArrayContains':
334
326
  return this._buildConditions(condition[key], operator, key, true);
335
327
  default:
336
328
  throw new TypeError(`Unknown modifier ${caseit(key)}.`);
@@ -475,6 +467,7 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
475
467
  switch (Object.keys(this._onConflict.action || {})[0] || 'nothing') {
476
468
  case 'nothing':
477
469
  result += 'nothing';
470
+ break;
478
471
  case 'update':
479
472
  result += `update ${this._buildUpdateKeysAndValues(this._onConflict.action.update.keys, this._onConflict.action.update.values)}`;
480
473
  break;
@@ -558,8 +551,11 @@ module.exports = exports = class QueryBuilder extends CustomPromise {
558
551
  return rows;
559
552
  }
560
553
 
561
- exec() {
562
- return this;
554
+ then(resolve, reject) {
555
+ super.then(resolve, reject);
556
+ this._exec()
557
+ .then((...args) => this._resolve(...args))
558
+ .catch((error) => this._reject(error));
563
559
  }
564
560
 
565
561
  };