@dwtechs/antity-pgsql 0.11.0 → 0.12.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, isIn, isString } from '@dwtechs/checkard';
27
+ import { isArray, isString, isIn } 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';
@@ -107,14 +107,6 @@ function quoteIfUppercase(word) {
107
107
  function index(index, matchMode) {
108
108
  const i = index.map((i) => `$${i}`);
109
109
  switch (matchMode) {
110
- case "startsWith":
111
- return `${i}%`;
112
- case "endsWith":
113
- return `%${i}`;
114
- case "contains":
115
- return `%${i}%`;
116
- case "notContains":
117
- return `%${i}%`;
118
110
  case "in":
119
111
  return `(${i})`;
120
112
  default:
@@ -159,6 +151,21 @@ function comparator(matchMode) {
159
151
  }
160
152
  }
161
153
 
154
+ function formatValue(value, matchMode) {
155
+ if (!isString(value))
156
+ return value;
157
+ switch (matchMode) {
158
+ case "startsWith":
159
+ return `${value}%`;
160
+ case "endsWith":
161
+ return `%${value}`;
162
+ case "contains":
163
+ case "notContains":
164
+ return `%${value}%`;
165
+ default:
166
+ return value;
167
+ }
168
+ }
162
169
  function add(filters) {
163
170
  var _a, _b;
164
171
  const conditions = [];
@@ -176,9 +183,9 @@ function add(filters) {
176
183
  if (cond) {
177
184
  groupConditions.push(cond);
178
185
  if (isArray(value))
179
- args.push(...value);
186
+ args.push(...value.map((v) => formatValue(v, matchMode)));
180
187
  else
181
- args.push(value);
188
+ args.push(formatValue(value, matchMode));
182
189
  }
183
190
  }
184
191
  if (groupConditions.length > 0) {
@@ -648,12 +655,12 @@ class SQLEntity extends Entity {
648
655
  });
649
656
  this.update = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
650
657
  const l = res.locals;
651
- const rows = req.body.rows;
658
+ const r = req.body.rows;
652
659
  const dbClient = l.dbClient || null;
653
660
  const cId = l.consumerId;
654
661
  const cName = l.consumerName;
655
- log.debug(`${LOGS_PREFIX}update(rows=${rows.length}, consumerId=${cId})`);
656
- const chunks = chunk(rows);
662
+ log.debug(`${LOGS_PREFIX}update(rows=${r.length}, consumerId=${cId})`);
663
+ const chunks = chunk(r);
657
664
  for (const c of chunks) {
658
665
  const { query, args } = this.upd.query(this._schema, this._table, c, cId, cName);
659
666
  try {
@@ -663,6 +670,7 @@ class SQLEntity extends Entity {
663
670
  return next(err);
664
671
  }
665
672
  }
673
+ l.rows = r;
666
674
  next();
667
675
  });
668
676
  this.archive = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwtechs/antity-pgsql",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Open source library to add PostgreSQL support to @dwtechs/Antity entities.",
5
5
  "keywords": [
6
6
  "entities"