ismx-nexo-node-app 0.4.153 → 0.4.155
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.
|
@@ -225,9 +225,12 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
225
225
|
return __awaiter(this, arguments, void 0, function* (tableName, select, filters = {}) {
|
|
226
226
|
if (!this.tables[tableName])
|
|
227
227
|
throw new Error(`table ${tableName} does not exist`);
|
|
228
|
-
let schema = this.tables[tableName][0].schema;
|
|
228
|
+
let [table, schema, column] = [this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils_1.default.camelToSnake(select)];
|
|
229
|
+
if (PostgresUtils_1.default.isReservedWord(column))
|
|
230
|
+
column = `"${column}"`;
|
|
231
|
+
if (!PostgresUtils_1.default.columns(table).includes(column))
|
|
232
|
+
throw new Error(`column ${column} does not exist in table ${tableName}`);
|
|
229
233
|
let { where, values } = this.toWhere(tableName, filters);
|
|
230
|
-
let column = PostgresUtils_1.default.snakeToCamel(select);
|
|
231
234
|
let query = `SELECT json_agg(u.${column}) as list FROM ${schema}.${tableName} u WHERE ${where}`;
|
|
232
235
|
return this.query(query, values).then((result) => { var _a, _b; return (_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : []; });
|
|
233
236
|
});
|
|
@@ -236,9 +239,12 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
236
239
|
return __awaiter(this, arguments, void 0, function* (tableName, select, filters = {}) {
|
|
237
240
|
if (!this.tables[tableName])
|
|
238
241
|
throw new Error(`table ${tableName} does not exist`);
|
|
239
|
-
let schema = this.tables[tableName][0].schema;
|
|
242
|
+
let [table, schema, column] = [this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils_1.default.camelToSnake(select)];
|
|
243
|
+
if (PostgresUtils_1.default.isReservedWord(column))
|
|
244
|
+
column = `"${column}"`;
|
|
245
|
+
if (!PostgresUtils_1.default.columns(table).includes(column))
|
|
246
|
+
throw new Error(`column ${column} does not exist in table ${tableName}`);
|
|
240
247
|
let { where, values } = this.toWhere(tableName, filters);
|
|
241
|
-
let column = PostgresUtils_1.default.snakeToCamel(select);
|
|
242
248
|
let query = `
|
|
243
249
|
SELECT json_object_agg(t.${column}, NULL) as list
|
|
244
250
|
FROM ( SELECT DISTINCT u.${column} FROM ${schema}.${tableName} u WHERE ${where} ) t`;
|
|
@@ -56,7 +56,9 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
|
|
|
56
56
|
select(tableName: string, select: string, filters?: {
|
|
57
57
|
[key: string]: Valuable | Array<Valuable>;
|
|
58
58
|
}): Promise<string[]>;
|
|
59
|
-
selectHash<T>(tableName: string, select: string, filters?:
|
|
59
|
+
selectHash<T>(tableName: string, select: string, filters?: {
|
|
60
|
+
[key: string]: Valuable | Array<Valuable>;
|
|
61
|
+
}): Promise<Hash<Primitive>>;
|
|
60
62
|
run<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<T[]>;
|
|
61
63
|
runTable<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<T[]>;
|
|
62
64
|
runValue<T>(name: string, params?: Valuable[], filters?: Partial<T>): Promise<Valuable | undefined>;
|
package/package.json
CHANGED
|
@@ -197,19 +197,25 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
197
197
|
async select(tableName: string, select: string, filters: { [key: string]: Valuable | Array<Valuable> }={}): Promise<string[]>
|
|
198
198
|
{
|
|
199
199
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
200
|
-
let schema = this.tables[tableName][0].schema;
|
|
200
|
+
let [ table, schema, column ] = [ this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils.camelToSnake(select) ];
|
|
201
|
+
if (PostgresUtils.isReservedWord(column)) column = `"${column}"`;
|
|
202
|
+
|
|
203
|
+
if (!PostgresUtils.columns(table).includes(column)) throw new Error(`column ${column} does not exist in table ${tableName}`);
|
|
201
204
|
let { where, values } = this.toWhere(tableName, filters);
|
|
202
|
-
|
|
205
|
+
|
|
203
206
|
let query = `SELECT json_agg(u.${column}) as list FROM ${schema}.${tableName} u WHERE ${where}`
|
|
204
207
|
return this.query<{list:string[]}>(query, values).then((result) => result[0]?.list ?? []);
|
|
205
208
|
}
|
|
206
209
|
|
|
207
|
-
async selectHash<T>(tableName: string, select: string, filters:
|
|
210
|
+
async selectHash<T>(tableName: string, select: string, filters: { [key: string]: Valuable | Array<Valuable> }={}): Promise<Hash<Primitive>>
|
|
208
211
|
{
|
|
209
212
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
210
|
-
let schema = this.tables[tableName][0].schema;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
+
let [ table, schema, column ] = [ this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils.camelToSnake(select) ];
|
|
214
|
+
if (PostgresUtils.isReservedWord(column)) column = `"${column}"`;
|
|
215
|
+
|
|
216
|
+
if (!PostgresUtils.columns(table).includes(column)) throw new Error(`column ${column} does not exist in table ${tableName}`);
|
|
217
|
+
let { where, values } = this.toWhere(tableName, filters);
|
|
218
|
+
|
|
213
219
|
let query = `
|
|
214
220
|
SELECT json_object_agg(t.${column}, NULL) as list
|
|
215
221
|
FROM ( SELECT DISTINCT u.${column} FROM ${schema}.${tableName} u WHERE ${where} ) t`;
|