@dwtechs/antity-pgsql 0.2.0 → 0.3.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/dist/antity-pgsql.js +19 -5
- package/package.json +1 -1
package/dist/antity-pgsql.js
CHANGED
|
@@ -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
|
}
|
|
@@ -169,7 +183,7 @@ class Select {
|
|
|
169
183
|
query(table, paginate) {
|
|
170
184
|
const p = paginate ? this._count : '';
|
|
171
185
|
const c = this._cols ? this._cols : '*';
|
|
172
|
-
return `SELECT ${c}${p} FROM
|
|
186
|
+
return `SELECT ${c}${p} FROM ${quoteIfUppercase(table)}`;
|
|
173
187
|
}
|
|
174
188
|
execute(query, args, client) {
|
|
175
189
|
return execute$1(query, args, client)
|
|
@@ -202,7 +216,7 @@ class Insert {
|
|
|
202
216
|
this._nbProps++;
|
|
203
217
|
}
|
|
204
218
|
query(table, rows, consumerId, consumerName, rtn = "") {
|
|
205
|
-
let query = `INSERT INTO
|
|
219
|
+
let query = `INSERT INTO ${quoteIfUppercase(table)} (${this._cols}) VALUES `;
|
|
206
220
|
const args = [];
|
|
207
221
|
let i = 0;
|
|
208
222
|
for (const row of rows) {
|
|
@@ -247,7 +261,7 @@ class Update {
|
|
|
247
261
|
rows = this.addConsumer(rows, consumerId, consumerName);
|
|
248
262
|
const l = rows.length;
|
|
249
263
|
const args = rows.map(row => row.id);
|
|
250
|
-
let query = `UPDATE "${table}" SET `;
|
|
264
|
+
let query = `UPDATE "${quoteIfUppercase(table)}" SET `;
|
|
251
265
|
let i = args.length + 1;
|
|
252
266
|
for (const p of this._props) {
|
|
253
267
|
if (rows[0][p] === undefined)
|
|
@@ -284,7 +298,7 @@ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
284
298
|
});
|
|
285
299
|
};
|
|
286
300
|
function query(table) {
|
|
287
|
-
return `DELETE FROM
|
|
301
|
+
return `DELETE FROM ${quoteIfUppercase(table)} WHERE "archivedAt" < $1`;
|
|
288
302
|
}
|
|
289
303
|
function execute(date, query, client) {
|
|
290
304
|
return __awaiter$1(this, void 0, void 0, function* () {
|