@dwtechs/antity-pgsql 0.17.6 → 0.18.0

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.
@@ -24,7 +24,7 @@ SOFTWARE.
24
24
  https://github.com/DWTechs/Antity-pgsql.js
25
25
  */
26
26
 
27
- import { isArray, isString } from '@dwtechs/checkard';
27
+ import { isArray, isInteger, isString } from '@dwtechs/checkard';
28
28
  import { deleteProps, chunk, flatten } from '@dwtechs/sparray';
29
29
  import { log } from '@dwtechs/winstan';
30
30
  import { Entity } from '@dwtechs/antity';
@@ -69,7 +69,7 @@ function execute(query, args, clt) {
69
69
  return res;
70
70
  })
71
71
  .catch((err) => {
72
- err.msg = `Postgre error: ${err.message}`;
72
+ err.message = `Postgre error: ${err.message}`;
73
73
  throw err;
74
74
  });
75
75
  }
@@ -104,7 +104,7 @@ function quoteIfUppercase(word) {
104
104
  return word;
105
105
  }
106
106
 
107
- function index(index, matchMode) {
107
+ function index(index, matchMode, value) {
108
108
  const i = index.map((i) => `$${i}`);
109
109
  switch (matchMode) {
110
110
  case "in":
@@ -112,8 +112,10 @@ function index(index, matchMode) {
112
112
  case "IN":
113
113
  case "NOT IN":
114
114
  return `(${i})`;
115
- case "&&":
116
- return `ARRAY[${i}]`;
115
+ case "&&": {
116
+ const cast = isArray(value, ">", 0) && isInteger(value[0]) ? '::integer[]' : '';
117
+ return `ARRAY[${i}]${cast}`;
118
+ }
117
119
  default:
118
120
  return `${i}`;
119
121
  }
@@ -201,7 +203,7 @@ function add(filters) {
201
203
  if (shouldSkipValue(value, matchMode))
202
204
  continue;
203
205
  const indexes = isArray(value) ? value.map(() => i++) : [i++];
204
- const cond = addOne(k, indexes, matchMode);
206
+ const cond = addOne(k, indexes, matchMode, value);
205
207
  if (cond) {
206
208
  groupConditions.push(cond);
207
209
  if (isArray(value))
@@ -221,10 +223,10 @@ function add(filters) {
221
223
  }
222
224
  return { conditions, args };
223
225
  }
224
- function addOne(key, indexes, matchMode) {
226
+ function addOne(key, indexes, matchMode, value) {
225
227
  const sqlKey = `${quoteIfUppercase(key)}`;
226
228
  const comparator$1 = comparator(matchMode);
227
- const index$1 = index(indexes, matchMode);
229
+ const index$1 = index(indexes, matchMode, value);
228
230
  return comparator$1 ? `${sqlKey} ${comparator$1} ${index$1}` : "";
229
231
  }
230
232
 
@@ -276,7 +278,7 @@ class Select {
276
278
  return execute(query, args, client)
277
279
  .then((r) => {
278
280
  if (!r.rowCount)
279
- throw { status: 404, msg: "Resource not found" };
281
+ throw { status: 404, message: "Resource not found" };
280
282
  const f = r.rows[0];
281
283
  if (f.total) {
282
284
  r.total = Number(f.total);
@@ -809,10 +811,10 @@ class SQLEntity extends Entity {
809
811
  const cId = l.consumer?.id;
810
812
  const cName = l.consumer?.nickname;
811
813
  if (!conflictTarget) {
812
- return next({ status: 400, msg: "Missing conflictTarget for upsert operation" });
814
+ return next({ status: 400, message: "Missing conflictTarget for upsert operation" });
813
815
  }
814
816
  if (!rows || !Array.isArray(rows) || rows.length === 0) {
815
- return next({ status: 400, msg: "Missing or empty rows array for upsert operation" });
817
+ return next({ status: 400, message: "Missing or empty rows array for upsert operation" });
816
818
  }
817
819
  log.debug(() => `${LOGS_PREFIX}upsert(rows=${rows.length}, conflictTarget=${conflictTarget}, consumerId=${cId})`);
818
820
  const rtn = this.ups.rtn("id");
@@ -879,7 +881,7 @@ class SQLEntity extends Entity {
879
881
  const id = req.params.id;
880
882
  const dbClient = res.locals.dbClient || null;
881
883
  if (!id) {
882
- next({ status: 400, msg: "Missing id" });
884
+ next({ status: 400, message: "Missing id" });
883
885
  return;
884
886
  }
885
887
  log.debug(() => `${LOGS_PREFIX}getHistory(schema=${this._schema}, table=${this._table}, id=${id})`);
@@ -895,7 +897,7 @@ class SQLEntity extends Entity {
895
897
  .then((r) => {
896
898
  const { rowCount, rows } = r;
897
899
  if (!rowCount) {
898
- return next({ status: 404, msg: "History not found" });
900
+ return next({ status: 404, message: "History not found" });
899
901
  }
900
902
  res.locals.history = rows;
901
903
  res.locals.total = rowCount;
@@ -910,7 +912,7 @@ class SQLEntity extends Entity {
910
912
  const cId = l.consumer?.id;
911
913
  const cName = l.consumer?.nickname;
912
914
  if (!rows || !Array.isArray(rows)) {
913
- return next({ status: 400, msg: "Missing or invalid rows array for sync operation" });
915
+ return next({ status: 400, message: "Missing or invalid rows array for sync operation" });
914
916
  }
915
917
  log.debug(() => `${LOGS_PREFIX}sync(rows=${rows.length}, idField=${idField}, consumerId=${cId})`);
916
918
  const cleanedFilters = cleanFilters(req.body.filters, this.properties) || null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwtechs/antity-pgsql",
3
- "version": "0.17.6",
3
+ "version": "0.18.0",
4
4
  "description": "Open source library to add PostgreSQL support to @dwtechs/Antity entities.",
5
5
  "keywords": [
6
6
  "entities"