@dwtechs/antity-pgsql 0.2.1 → 0.3.1

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
@@ -181,11 +181,11 @@ class SQLEntity {
181
181
  delete: () => string;
182
182
  return: (prop: string) => string;
183
183
  };
184
- get(req: Request, res: Response, next: NextFunction): void;
185
- add(req: Request, res: Response, next: NextFunction): Promise<void>;
186
- update(req: Request, res: Response, next: NextFunction): Promise<void>;
187
- archive(req: Request, res: Response, next: NextFunction): Promise<void>;
188
- delete(req: Request, res: Response, next: NextFunction): void;
184
+ get: (req: Request, res: Response, next: NextFunction) => void;
185
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
186
+ update: (req: Request, res: Response, next: NextFunction) => Promise<void>;
187
+ archive: (req: Request, res: Response, next: NextFunction) => Promise<void>;
188
+ delete: (req: Request, res: Response, next: NextFunction) => void;
189
189
 
190
190
  }
191
191
 
@@ -87,13 +87,11 @@ declare class SQLEntity extends Entity {
87
87
  delete: () => string;
88
88
  return: (prop: string) => string;
89
89
  };
90
- get(req: Request, res: Response, next: NextFunction): void;
91
- add(req: Request, res: Response, next: NextFunction): Promise<void>;
92
- update(req: Request, res: Response, next: NextFunction): Promise<void>;
93
- archive(req: Request, res: Response, next: NextFunction): Promise<void>;
94
- delete(req: Request, res: Response, next: NextFunction): void;
95
- private cleanFilters;
96
- private mapProps;
90
+ get: (req: Request, res: Response, next: NextFunction) => void;
91
+ add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
92
+ update: (req: Request, res: Response, next: NextFunction) => Promise<void>;
93
+ archive: (req: Request, res: Response, next: NextFunction) => Promise<void>;
94
+ delete: (req: Request, res: Response, next: NextFunction) => void;
97
95
  }
98
96
 
99
97
  declare function filter(
@@ -147,8 +147,22 @@ function deleteIdleProperties(res) {
147
147
  res._prebuiltEmptyResultObject = undefined;
148
148
  }
149
149
 
150
+ const reserved = [
151
+ 'all', 'analyse', 'analyze', 'and', 'any', 'array', 'as', 'asc', 'asymmetric',
152
+ 'authorization', 'between', 'binary', 'both', 'case', 'cast', 'check', 'collate',
153
+ 'column', 'constraint', 'create', 'cross', 'current_catalog', 'current_date',
154
+ 'current_role', 'current_schema', 'current_time', 'current_timestamp', 'current_user',
155
+ 'default', 'deferrable', 'desc', 'distinct', 'do', 'else', 'end', 'except', 'false',
156
+ 'fetch', 'for', 'foreign', 'from', 'full', 'grant', 'group', 'having', 'ilike', 'in',
157
+ 'initially', 'inner', 'intersect', 'into', 'is', 'isnull', 'join', 'lateral', 'leading',
158
+ 'left', 'like', 'limit', 'localtime', 'localtimestamp', 'natural', 'not', 'notnull',
159
+ 'null', 'offset', 'on', 'only', 'or', 'order', 'outer', 'overlaps', 'placing', 'primary',
160
+ 'references', 'returning', 'right', 'select', 'session_user', 'similar', 'some', 'symmetric',
161
+ 'table', 'tablesample', 'then', 'to', 'trailing', 'true', 'union', 'unique', 'user', 'using',
162
+ 'variadic', 'verbose', 'when', 'where', 'window', 'with'
163
+ ];
150
164
  function quoteIfUppercase(word) {
151
- if (/[A-Z]/.test(word))
165
+ if (/[A-Z]/.test(word) || reserved.includes(word.toLowerCase()))
152
166
  return `"${word}"`;
153
167
  return word;
154
168
  }
@@ -436,45 +450,31 @@ class SQLEntity extends Entity {
436
450
  return this.ins.rtn(prop);
437
451
  }
438
452
  };
439
- this._table = name;
440
- for (const p of properties) {
441
- this.mapProps(p.methods, p.key);
442
- }
443
- }
444
- get table() {
445
- return this._table;
446
- }
447
- set table(table) {
448
- if (!isString(table, "!0"))
449
- throw new Error('table must be a string of length > 0');
450
- this._table = table;
451
- }
452
- get(req, res, next) {
453
- var _a;
454
- const l = res.locals;
455
- const b = req.body;
456
- const first = (_a = b === null || b === void 0 ? void 0 : b.first) !== null && _a !== void 0 ? _a : 0;
457
- const rows = b.rows || null;
458
- const sortField = b.sortField || null;
459
- const sortOrder = b.sortOrder === -1 || b.sortOrder === "DESC" ? "DESC" : "ASC";
460
- const filters = this.cleanFilters(b.filters) || null;
461
- const pagination = b.pagination || false;
462
- const dbClient = l.dbClient || null;
463
- log.debug(`get(first='${first}', rows='${rows}',
453
+ this.get = (req, res, next) => {
454
+ var _a;
455
+ const l = res.locals;
456
+ const b = req.body;
457
+ const first = (_a = b === null || b === void 0 ? void 0 : b.first) !== null && _a !== void 0 ? _a : 0;
458
+ const rows = b.rows || null;
459
+ const sortField = b.sortField || null;
460
+ const sortOrder = b.sortOrder === -1 || b.sortOrder === "DESC" ? "DESC" : "ASC";
461
+ const filters = this.cleanFilters(b.filters) || null;
462
+ const pagination = b.pagination || false;
463
+ const dbClient = l.dbClient || null;
464
+ log.debug(`get(first='${first}', rows='${rows}',
464
465
  sortOrder='${sortOrder}', sortField='${sortField}',
465
466
  pagination=${pagination}, filters=${JSON.stringify(filters)}`);
466
- const { filterClause, args } = filter(first, rows, sortField, sortOrder, filters);
467
- const q = this.sel.query(this._table, pagination) + filterClause;
468
- this.sel.execute(q, args, dbClient)
469
- .then((r) => {
470
- l.rows = r.rows;
471
- l.total = r.total;
472
- next();
473
- })
474
- .catch((err) => next(err));
475
- }
476
- add(req, res, next) {
477
- return __awaiter(this, void 0, void 0, function* () {
467
+ const { filterClause, args } = filter(first, rows, sortField, sortOrder, filters);
468
+ const q = this.sel.query(this._table, pagination) + filterClause;
469
+ this.sel.execute(q, args, dbClient)
470
+ .then((r) => {
471
+ l.rows = r.rows;
472
+ l.total = r.total;
473
+ next();
474
+ })
475
+ .catch((err) => next(err));
476
+ };
477
+ this.add = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
478
478
  const l = res.locals;
479
479
  const rows = req.body.rows;
480
480
  const dbClient = l.dbClient || null;
@@ -500,9 +500,7 @@ class SQLEntity extends Entity {
500
500
  l.rows = flatten(chunks);
501
501
  next();
502
502
  });
503
- }
504
- update(req, res, next) {
505
- return __awaiter(this, void 0, void 0, function* () {
503
+ this.update = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
506
504
  const l = res.locals;
507
505
  const rows = req.body.rows;
508
506
  const dbClient = l.dbClient || null;
@@ -521,9 +519,7 @@ class SQLEntity extends Entity {
521
519
  }
522
520
  next();
523
521
  });
524
- }
525
- archive(req, res, next) {
526
- return __awaiter(this, void 0, void 0, function* () {
522
+ this.archive = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
527
523
  const l = res.locals;
528
524
  let rows = req.body.rows;
529
525
  const dbClient = l.dbClient || null;
@@ -543,15 +539,27 @@ class SQLEntity extends Entity {
543
539
  }
544
540
  next();
545
541
  });
542
+ this.delete = (req, res, next) => {
543
+ const date = req.body.date;
544
+ const dbClient = res.locals.dbClient || null;
545
+ log.debug(`delete archived`);
546
+ const q = query(this._table);
547
+ execute(date, q, dbClient)
548
+ .then(() => next())
549
+ .catch((err) => next(err));
550
+ };
551
+ this._table = name;
552
+ for (const p of properties) {
553
+ this.mapProps(p.methods, p.key);
554
+ }
555
+ }
556
+ get table() {
557
+ return this._table;
546
558
  }
547
- delete(req, res, next) {
548
- const date = req.body.date;
549
- const dbClient = res.locals.dbClient || null;
550
- log.debug(`delete archived`);
551
- const q = query(this._table);
552
- execute(date, q, dbClient)
553
- .then(() => next())
554
- .catch((err) => next(err));
559
+ set table(table) {
560
+ if (!isString(table, "!0"))
561
+ throw new Error('table must be a string of length > 0');
562
+ this._table = table;
555
563
  }
556
564
  cleanFilters(filters) {
557
565
  for (const k in filters) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwtechs/antity-pgsql",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "Open source library for easy entity management",
5
5
  "keywords": [
6
6
  "entities"
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@dwtechs/checkard": "3.2.3",
40
40
  "@dwtechs/winstan": "0.4.0",
41
- "@dwtechs/antity": "0.9.0",
41
+ "@dwtechs/antity": "0.9.2",
42
42
  "@dwtechs/sparray": "0.2.0",
43
43
  "pg": "8.13.1"
44
44
  },