ismx-nexo-node-app 0.4.151 → 0.4.154
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,11 @@ 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.columns(table).includes(column))
|
|
230
|
+
throw new Error(`column ${column} does not exist in table ${tableName}`);
|
|
229
231
|
let { where, values } = this.toWhere(tableName, filters);
|
|
230
|
-
let query = `SELECT json_agg(u.${
|
|
232
|
+
let query = `SELECT json_agg(u.${column}) as list FROM ${schema}.${tableName} u WHERE ${where}`;
|
|
231
233
|
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 : []; });
|
|
232
234
|
});
|
|
233
235
|
}
|
|
@@ -235,11 +237,13 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
235
237
|
return __awaiter(this, arguments, void 0, function* (tableName, select, filters = {}) {
|
|
236
238
|
if (!this.tables[tableName])
|
|
237
239
|
throw new Error(`table ${tableName} does not exist`);
|
|
238
|
-
let schema = this.tables[tableName][0].schema;
|
|
240
|
+
let [table, schema, column] = [this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils_1.default.camelToSnake(select)];
|
|
241
|
+
if (!PostgresUtils_1.default.columns(table).includes(column))
|
|
242
|
+
throw new Error(`column ${column} does not exist in table ${tableName}`);
|
|
239
243
|
let { where, values } = this.toWhere(tableName, filters);
|
|
240
244
|
let query = `
|
|
241
|
-
SELECT json_object_agg(t.${
|
|
242
|
-
FROM ( SELECT DISTINCT u.${
|
|
245
|
+
SELECT json_object_agg(t.${column}, NULL) as list
|
|
246
|
+
FROM ( SELECT DISTINCT u.${column} FROM ${schema}.${tableName} u WHERE ${where} ) t`;
|
|
243
247
|
return this.query(query, values).then((result) => { var _a, _b; return new Repository_1.Hash((_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : {}); });
|
|
244
248
|
});
|
|
245
249
|
}
|
|
@@ -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,20 +197,26 @@ 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
|
+
|
|
202
|
+
if (!PostgresUtils.columns(table).includes(column)) throw new Error(`column ${column} does not exist in table ${tableName}`);
|
|
201
203
|
let { where, values } = this.toWhere(tableName, filters);
|
|
202
|
-
|
|
204
|
+
|
|
205
|
+
let query = `SELECT json_agg(u.${column}) as list FROM ${schema}.${tableName} u WHERE ${where}`
|
|
203
206
|
return this.query<{list:string[]}>(query, values).then((result) => result[0]?.list ?? []);
|
|
204
207
|
}
|
|
205
208
|
|
|
206
|
-
async selectHash<T>(tableName: string, select: string, filters:
|
|
209
|
+
async selectHash<T>(tableName: string, select: string, filters: { [key: string]: Valuable | Array<Valuable> }={}): Promise<Hash<Primitive>>
|
|
207
210
|
{
|
|
208
211
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
209
|
-
let schema = this.tables[tableName][0].schema;
|
|
210
|
-
|
|
212
|
+
let [ table, schema, column ] = [ this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils.camelToSnake(select) ];
|
|
213
|
+
|
|
214
|
+
if (!PostgresUtils.columns(table).includes(column)) throw new Error(`column ${column} does not exist in table ${tableName}`);
|
|
215
|
+
let { where, values } = this.toWhere(tableName, filters);
|
|
216
|
+
|
|
211
217
|
let query = `
|
|
212
|
-
SELECT json_object_agg(t.${
|
|
213
|
-
FROM ( SELECT DISTINCT u.${
|
|
218
|
+
SELECT json_object_agg(t.${column}, NULL) as list
|
|
219
|
+
FROM ( SELECT DISTINCT u.${column} FROM ${schema}.${tableName} u WHERE ${where} ) t`;
|
|
214
220
|
return this.query<{list:Record<Primitive, null>}>(query, values).then((result) => new Hash(result[0]?.list ?? {}));
|
|
215
221
|
}
|
|
216
222
|
|
|
@@ -230,7 +236,8 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
230
236
|
return this.query<any>(query, [ ...values, ...params ]);
|
|
231
237
|
}
|
|
232
238
|
|
|
233
|
-
async runValue<T>(name: string, params: Valuable[] = [], filters: Partial<T> = {}): Promise<Valuable | undefined>
|
|
239
|
+
async runValue<T>(name: string, params: Valuable[] = [], filters: Partial<T> = {}): Promise<Valuable | undefined>
|
|
240
|
+
{
|
|
234
241
|
return this.run<T>(name, params, filters).then((result) => Object.values(result[0] ?? {})[0] as Valuable)
|
|
235
242
|
}
|
|
236
243
|
|