@dwtechs/antity-pgsql 0.1.1 → 0.2.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.
- package/README.md +10 -4
- package/dist/antity-pgsql.d.ts +63 -61
- package/dist/antity-pgsql.js +15 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -189,13 +189,19 @@ class SQLEntity {
|
|
|
189
189
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
filter(
|
|
192
|
+
function filter(
|
|
193
193
|
first: number,
|
|
194
|
-
rows: number
|
|
194
|
+
rows: number,
|
|
195
195
|
sortField: string | null,
|
|
196
|
-
sortOrder: Sort,
|
|
196
|
+
sortOrder: Sort = "ASC",
|
|
197
197
|
filters: Filters | null,
|
|
198
|
-
): { filterClause: string, args: (Filter["value"])[] }
|
|
198
|
+
): { filterClause: string, args: (Filter["value"])[] };
|
|
199
|
+
|
|
200
|
+
function execute(
|
|
201
|
+
query: string,
|
|
202
|
+
args: (string | number | boolean | Date | number[])[],
|
|
203
|
+
client: any,
|
|
204
|
+
): Promise<PGResponse>;
|
|
199
205
|
|
|
200
206
|
|
|
201
207
|
```
|
package/dist/antity-pgsql.d.ts
CHANGED
|
@@ -25,17 +25,17 @@ https://github.com/DWTechs/Antity-pgsql.js
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { Entity, Property } from "@dwtechs/antity";
|
|
28
|
-
import type { Request, NextFunction } from 'express';
|
|
28
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
29
29
|
|
|
30
30
|
export type Operation = "SELECT" | "INSERT" | "UPDATE" | "DELETE";
|
|
31
31
|
export type Sort = "ASC" | "DESC";
|
|
32
32
|
export type Filters = {
|
|
33
|
-
|
|
33
|
+
[key: string]: Filter;
|
|
34
34
|
};
|
|
35
35
|
export type Filter = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
value: string | number | boolean | Date | number[];
|
|
37
|
+
subProps?: string[];
|
|
38
|
+
matchMode?: MatchMode;
|
|
39
39
|
};
|
|
40
40
|
export type LogicalOperator = "AND" | "OR";
|
|
41
41
|
export type Comparator = "=" | "<" | ">" | "<=" | ">=" | "<>" | "IS" | "IS NOT" | "IN" | "LIKE" | "NOT LIKE";
|
|
@@ -43,75 +43,77 @@ export type MatchMode = "startsWith" | "endsWith" | "contains" | "notContains" |
|
|
|
43
43
|
export type MappedType = "string" | "number" | "date";
|
|
44
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
45
|
export type Geometry = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
lng: number;
|
|
47
|
+
lat: number;
|
|
48
|
+
radius: number;
|
|
49
|
+
bounds: {
|
|
50
|
+
minLng: number;
|
|
51
|
+
minLat: number;
|
|
52
|
+
maxLng: number;
|
|
53
|
+
maxLat: number;
|
|
54
|
+
};
|
|
55
55
|
};
|
|
56
56
|
export type PGResponse = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
export type Response = {
|
|
69
|
-
rows: Record<string, unknown>[];
|
|
70
|
-
total?: number;
|
|
57
|
+
rows: Record<string, unknown>[];
|
|
58
|
+
rowCount: number;
|
|
59
|
+
total?: number;
|
|
60
|
+
command?: string;
|
|
61
|
+
oid?: number;
|
|
62
|
+
fields?: unknown[];
|
|
63
|
+
_parsers?: unknown[];
|
|
64
|
+
_types?: unknown;
|
|
65
|
+
RowCtor?: unknown;
|
|
66
|
+
rowAsArray?: boolean;
|
|
71
67
|
};
|
|
72
68
|
|
|
73
69
|
declare class SQLEntity extends Entity {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
};
|
|
91
|
-
delete: () => string;
|
|
92
|
-
return: (prop: string) => string;
|
|
70
|
+
private _table;
|
|
71
|
+
private sel;
|
|
72
|
+
private ins;
|
|
73
|
+
private upd;
|
|
74
|
+
constructor(name: string, properties: Property[]);
|
|
75
|
+
get table(): string;
|
|
76
|
+
set table(table: string);
|
|
77
|
+
query: {
|
|
78
|
+
select: (paginate: boolean) => string;
|
|
79
|
+
update: (rows: Record<string, unknown>[], consumerId: number | string, consumerName: string) => {
|
|
80
|
+
query: string;
|
|
81
|
+
args: unknown[];
|
|
82
|
+
};
|
|
83
|
+
insert: (rows: Record<string, unknown>[], consumerId: number | string, consumerName: string, rtn?: string) => {
|
|
84
|
+
query: string;
|
|
85
|
+
args: unknown[];
|
|
93
86
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
87
|
+
delete: () => string;
|
|
88
|
+
return: (prop: string) => string;
|
|
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;
|
|
101
97
|
}
|
|
102
98
|
|
|
103
|
-
declare filter(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
99
|
+
declare function filter(
|
|
100
|
+
first: number,
|
|
101
|
+
rows: number | null,
|
|
102
|
+
sortField: string | null,
|
|
103
|
+
sortOrder: Sort | null,
|
|
104
|
+
filters: Filters | null,
|
|
105
|
+
): { filterClause: string, args: (Filter["value"])[] };
|
|
110
106
|
|
|
107
|
+
declare function execute(
|
|
108
|
+
query: string,
|
|
109
|
+
args: (string | number | boolean | Date | number[])[],
|
|
110
|
+
client: any
|
|
111
|
+
): Promise<PGResponse>;
|
|
111
112
|
|
|
112
113
|
export {
|
|
113
114
|
SQLEntity,
|
|
114
115
|
Property,
|
|
115
116
|
filter,
|
|
117
|
+
execute,
|
|
116
118
|
};
|
|
117
119
|
|
package/dist/antity-pgsql.js
CHANGED
|
@@ -127,8 +127,8 @@ function execute$1(query, args, clt) {
|
|
|
127
127
|
return client
|
|
128
128
|
.query(query, args)
|
|
129
129
|
.then((res) => {
|
|
130
|
-
perf.end(res, time);
|
|
131
130
|
deleteIdleProperties(res);
|
|
131
|
+
perf.end(res, time);
|
|
132
132
|
return res;
|
|
133
133
|
})
|
|
134
134
|
.catch((err) => {
|
|
@@ -144,6 +144,13 @@ function deleteIdleProperties(res) {
|
|
|
144
144
|
res._types = undefined;
|
|
145
145
|
res.RowCtor = undefined;
|
|
146
146
|
res.rowAsArray = undefined;
|
|
147
|
+
res._prebuiltEmptyResultObject = undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function quoteIfUppercase(word) {
|
|
151
|
+
if (/[A-Z]/.test(word))
|
|
152
|
+
return `"${word}"`;
|
|
153
|
+
return word;
|
|
147
154
|
}
|
|
148
155
|
|
|
149
156
|
class Select {
|
|
@@ -153,7 +160,7 @@ class Select {
|
|
|
153
160
|
this._count = ", COUNT(*) OVER () AS total";
|
|
154
161
|
}
|
|
155
162
|
addProp(prop) {
|
|
156
|
-
this._props.push(prop);
|
|
163
|
+
this._props.push(quoteIfUppercase(prop));
|
|
157
164
|
this._cols = this._props.join(", ");
|
|
158
165
|
}
|
|
159
166
|
get props() {
|
|
@@ -190,7 +197,7 @@ class Insert {
|
|
|
190
197
|
this._nbProps = 2;
|
|
191
198
|
}
|
|
192
199
|
addProp(prop) {
|
|
193
|
-
this._props = add$1(this._props, prop, this._props.length - 2);
|
|
200
|
+
this._props = add$1(this._props, quoteIfUppercase(prop), this._props.length - 2);
|
|
194
201
|
this._cols = this._props.join(", ");
|
|
195
202
|
this._nbProps++;
|
|
196
203
|
}
|
|
@@ -234,7 +241,7 @@ class Update {
|
|
|
234
241
|
this._props = ["consumerId", "consumerName"];
|
|
235
242
|
}
|
|
236
243
|
addProp(prop) {
|
|
237
|
-
this._props = add$1(this._props, prop, this._props.length - 2);
|
|
244
|
+
this._props = add$1(this._props, quoteIfUppercase(prop), this._props.length - 2);
|
|
238
245
|
}
|
|
239
246
|
query(table, rows, consumerId, consumerName) {
|
|
240
247
|
rows = this.addConsumer(rows, consumerId, consumerName);
|
|
@@ -368,7 +375,7 @@ function add(filters) {
|
|
|
368
375
|
return { conditions, args };
|
|
369
376
|
}
|
|
370
377
|
function addOne(key, indexes, matchMode) {
|
|
371
|
-
const sqlKey =
|
|
378
|
+
const sqlKey = `${quoteIfUppercase(key)}`;
|
|
372
379
|
const comparator$1 = comparator(matchMode);
|
|
373
380
|
const index$1 = index(indexes, matchMode);
|
|
374
381
|
return comparator$1 ? `${sqlKey} ${comparator$1} ${index$1}` : "";
|
|
@@ -390,7 +397,8 @@ function where(conditions, operator = "AND") {
|
|
|
390
397
|
function orderBy(sortField, sortOrder) {
|
|
391
398
|
if (!sortField)
|
|
392
399
|
return "";
|
|
393
|
-
|
|
400
|
+
const o = sortOrder || "ASC";
|
|
401
|
+
return ` ORDER BY ${quoteIfUppercase(sortField)} ${o}`;
|
|
394
402
|
}
|
|
395
403
|
function limit(rows, first) {
|
|
396
404
|
return rows ? ` LIMIT ${rows} OFFSET ${first}` : "";
|
|
@@ -585,4 +593,4 @@ class SQLEntity extends Entity {
|
|
|
585
593
|
}
|
|
586
594
|
}
|
|
587
595
|
|
|
588
|
-
export { SQLEntity, filter };
|
|
596
|
+
export { SQLEntity, execute$1 as execute, filter };
|