@dwtechs/antity-pgsql 0.3.0 → 0.3.2
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 +6 -5
- package/dist/antity-pgsql.d.ts +7 -8
- package/dist/antity-pgsql.js +47 -51
- package/package.json +2 -2
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)
|
|
185
|
-
add(req: Request, res: Response, next: NextFunction)
|
|
186
|
-
update(req: Request, res: Response, next: NextFunction)
|
|
187
|
-
archive(req: Request, res: Response, next: NextFunction)
|
|
188
|
-
delete(req: Request, res: Response, next: NextFunction)
|
|
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
|
|
|
@@ -265,6 +265,7 @@ List of secondary types :
|
|
|
265
265
|
| jwt | string |
|
|
266
266
|
| symbol | string |
|
|
267
267
|
| email | string |
|
|
268
|
+
| password | string |
|
|
268
269
|
| regex | string |
|
|
269
270
|
| ipAddress | string |
|
|
270
271
|
| slug | string |
|
package/dist/antity-pgsql.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ https://github.com/DWTechs/Antity-pgsql.js
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { Entity, Property } from "@dwtechs/antity";
|
|
28
|
+
import { Type } from "@dwtechs/antity";
|
|
28
29
|
import type { Request, Response, NextFunction } from 'express';
|
|
29
30
|
|
|
30
31
|
export type Operation = "SELECT" | "INSERT" | "UPDATE" | "DELETE";
|
|
@@ -37,11 +38,11 @@ export type Filter = {
|
|
|
37
38
|
subProps?: string[];
|
|
38
39
|
matchMode?: MatchMode;
|
|
39
40
|
};
|
|
41
|
+
export { Type };
|
|
40
42
|
export type LogicalOperator = "AND" | "OR";
|
|
41
43
|
export type Comparator = "=" | "<" | ">" | "<=" | ">=" | "<>" | "IS" | "IS NOT" | "IN" | "LIKE" | "NOT LIKE";
|
|
42
44
|
export type MatchMode = "startsWith" | "endsWith" | "contains" | "notContains" | "equals" | "notEquals" | "between" | "in" | "lt" | "lte" | "gt" | "gte" | "is" | "isNot" | "before" | "after" | "st_contains" | "st_dwithin";
|
|
43
45
|
export type MappedType = "string" | "number" | "date";
|
|
44
|
-
export type Type = "boolean" | "string" | "number" | "integer" | "float" | "even" | "odd" | "positive" | "negative" | "powerOfTwo" | "ascii" | "array" | "jwt" | "symbol" | "email" | "regex" | "json" | "ipAddress" | "slug" | "hexadecimal" | "date" | "timestamp" | "function" | "htmlElement" | "htmlEventAttribute" | "node" | "object" | "geometry";
|
|
45
46
|
export type Geometry = {
|
|
46
47
|
lng: number;
|
|
47
48
|
lat: number;
|
|
@@ -87,13 +88,11 @@ declare class SQLEntity extends Entity {
|
|
|
87
88
|
delete: () => string;
|
|
88
89
|
return: (prop: string) => string;
|
|
89
90
|
};
|
|
90
|
-
get(req: Request, res: Response, next: NextFunction)
|
|
91
|
-
add(req: Request, res: Response, next: NextFunction)
|
|
92
|
-
update(req: Request, res: Response, next: NextFunction)
|
|
93
|
-
archive(req: Request, res: Response, next: NextFunction)
|
|
94
|
-
delete(req: Request, res: Response, next: NextFunction)
|
|
95
|
-
private cleanFilters;
|
|
96
|
-
private mapProps;
|
|
91
|
+
get: (req: Request, res: Response, next: NextFunction) => void;
|
|
92
|
+
add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
93
|
+
update: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
94
|
+
archive: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
95
|
+
delete: (req: Request, res: Response, next: NextFunction) => void;
|
|
97
96
|
}
|
|
98
97
|
|
|
99
98
|
declare function filter(
|
package/dist/antity-pgsql.js
CHANGED
|
@@ -55,6 +55,8 @@ function type(type) {
|
|
|
55
55
|
return s;
|
|
56
56
|
case "symbol":
|
|
57
57
|
return s;
|
|
58
|
+
case "password":
|
|
59
|
+
return s;
|
|
58
60
|
case "email":
|
|
59
61
|
return s;
|
|
60
62
|
case "regex":
|
|
@@ -450,45 +452,31 @@ class SQLEntity extends Entity {
|
|
|
450
452
|
return this.ins.rtn(prop);
|
|
451
453
|
}
|
|
452
454
|
};
|
|
453
|
-
this.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}
|
|
466
|
-
get(req, res, next) {
|
|
467
|
-
var _a;
|
|
468
|
-
const l = res.locals;
|
|
469
|
-
const b = req.body;
|
|
470
|
-
const first = (_a = b === null || b === void 0 ? void 0 : b.first) !== null && _a !== void 0 ? _a : 0;
|
|
471
|
-
const rows = b.rows || null;
|
|
472
|
-
const sortField = b.sortField || null;
|
|
473
|
-
const sortOrder = b.sortOrder === -1 || b.sortOrder === "DESC" ? "DESC" : "ASC";
|
|
474
|
-
const filters = this.cleanFilters(b.filters) || null;
|
|
475
|
-
const pagination = b.pagination || false;
|
|
476
|
-
const dbClient = l.dbClient || null;
|
|
477
|
-
log.debug(`get(first='${first}', rows='${rows}',
|
|
455
|
+
this.get = (req, res, next) => {
|
|
456
|
+
var _a;
|
|
457
|
+
const l = res.locals;
|
|
458
|
+
const b = req.body;
|
|
459
|
+
const first = (_a = b === null || b === void 0 ? void 0 : b.first) !== null && _a !== void 0 ? _a : 0;
|
|
460
|
+
const rows = b.rows || null;
|
|
461
|
+
const sortField = b.sortField || null;
|
|
462
|
+
const sortOrder = b.sortOrder === -1 || b.sortOrder === "DESC" ? "DESC" : "ASC";
|
|
463
|
+
const filters = this.cleanFilters(b.filters) || null;
|
|
464
|
+
const pagination = b.pagination || false;
|
|
465
|
+
const dbClient = l.dbClient || null;
|
|
466
|
+
log.debug(`get(first='${first}', rows='${rows}',
|
|
478
467
|
sortOrder='${sortOrder}', sortField='${sortField}',
|
|
479
468
|
pagination=${pagination}, filters=${JSON.stringify(filters)}`);
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
469
|
+
const { filterClause, args } = filter(first, rows, sortField, sortOrder, filters);
|
|
470
|
+
const q = this.sel.query(this._table, pagination) + filterClause;
|
|
471
|
+
this.sel.execute(q, args, dbClient)
|
|
472
|
+
.then((r) => {
|
|
473
|
+
l.rows = r.rows;
|
|
474
|
+
l.total = r.total;
|
|
475
|
+
next();
|
|
476
|
+
})
|
|
477
|
+
.catch((err) => next(err));
|
|
478
|
+
};
|
|
479
|
+
this.add = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
492
480
|
const l = res.locals;
|
|
493
481
|
const rows = req.body.rows;
|
|
494
482
|
const dbClient = l.dbClient || null;
|
|
@@ -514,9 +502,7 @@ class SQLEntity extends Entity {
|
|
|
514
502
|
l.rows = flatten(chunks);
|
|
515
503
|
next();
|
|
516
504
|
});
|
|
517
|
-
|
|
518
|
-
update(req, res, next) {
|
|
519
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
505
|
+
this.update = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
520
506
|
const l = res.locals;
|
|
521
507
|
const rows = req.body.rows;
|
|
522
508
|
const dbClient = l.dbClient || null;
|
|
@@ -535,9 +521,7 @@ class SQLEntity extends Entity {
|
|
|
535
521
|
}
|
|
536
522
|
next();
|
|
537
523
|
});
|
|
538
|
-
|
|
539
|
-
archive(req, res, next) {
|
|
540
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
524
|
+
this.archive = (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
541
525
|
const l = res.locals;
|
|
542
526
|
let rows = req.body.rows;
|
|
543
527
|
const dbClient = l.dbClient || null;
|
|
@@ -557,15 +541,27 @@ class SQLEntity extends Entity {
|
|
|
557
541
|
}
|
|
558
542
|
next();
|
|
559
543
|
});
|
|
544
|
+
this.delete = (req, res, next) => {
|
|
545
|
+
const date = req.body.date;
|
|
546
|
+
const dbClient = res.locals.dbClient || null;
|
|
547
|
+
log.debug(`delete archived`);
|
|
548
|
+
const q = query(this._table);
|
|
549
|
+
execute(date, q, dbClient)
|
|
550
|
+
.then(() => next())
|
|
551
|
+
.catch((err) => next(err));
|
|
552
|
+
};
|
|
553
|
+
this._table = name;
|
|
554
|
+
for (const p of properties) {
|
|
555
|
+
this.mapProps(p.methods, p.key);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
get table() {
|
|
559
|
+
return this._table;
|
|
560
560
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const q = query(this._table);
|
|
566
|
-
execute(date, q, dbClient)
|
|
567
|
-
.then(() => next())
|
|
568
|
-
.catch((err) => next(err));
|
|
561
|
+
set table(table) {
|
|
562
|
+
if (!isString(table, "!0"))
|
|
563
|
+
throw new Error('table must be a string of length > 0');
|
|
564
|
+
this._table = table;
|
|
569
565
|
}
|
|
570
566
|
cleanFilters(filters) {
|
|
571
567
|
for (const k in filters) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dwtechs/antity-pgsql",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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.
|
|
41
|
+
"@dwtechs/antity": "0.10.0",
|
|
42
42
|
"@dwtechs/sparray": "0.2.0",
|
|
43
43
|
"pg": "8.13.1"
|
|
44
44
|
},
|