ismx-nexo-node-app 0.3.39 → 0.3.41
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/js/repository/RepositoryDatabasePostgres.js +7 -2
- package/dist/types/repository/RepositoryDatabase.d.ts +3 -0
- package/dist/types/repository/RepositoryDatabasePostgres.d.ts +3 -0
- package/package.json +1 -1
- package/src/main/node/repository/RepositoryDatabase.ts +2 -0
- package/src/main/node/repository/RepositoryDatabasePostgres.ts +6 -2
|
@@ -134,6 +134,11 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
134
134
|
return Promise.all([total, elements]).then(([total, elements]) => ({ total, elements }));
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
+
exist(tableName_1) {
|
|
138
|
+
return __awaiter(this, arguments, void 0, function* (tableName, filters = {}) {
|
|
139
|
+
return (yield this.count(tableName, filters)) > 0;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
137
142
|
count(tableName_1) {
|
|
138
143
|
return __awaiter(this, arguments, void 0, function* (tableName, filters = {}) {
|
|
139
144
|
if (!this.tables[tableName])
|
|
@@ -141,7 +146,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
141
146
|
let schema = this.tables[tableName][0].schema;
|
|
142
147
|
let { where, values } = this.toWhere(tableName, filters);
|
|
143
148
|
let query = `SELECT count(*) as count FROM ${schema}.${tableName} WHERE ${where}`;
|
|
144
|
-
return this.query(query, values).then((result) => result[0].count);
|
|
149
|
+
return this.query(query, values).then((result) => { var _a, _b; return (_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0; });
|
|
145
150
|
});
|
|
146
151
|
}
|
|
147
152
|
select(tableName_1, select_1) {
|
|
@@ -151,7 +156,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
151
156
|
let schema = this.tables[tableName][0].schema;
|
|
152
157
|
let { where, values } = this.toWhere(tableName, filters);
|
|
153
158
|
let query = `SELECT json_agg(u.${select}) as list FROM ${schema}.${tableName} u WHERE ${where}`;
|
|
154
|
-
return this.query(query, values).then((result) => result[0].list);
|
|
159
|
+
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 : []; });
|
|
155
160
|
});
|
|
156
161
|
}
|
|
157
162
|
del(tableName, id) {
|
|
@@ -49,6 +49,9 @@ export default abstract class RepositoryDatabase extends Repository {
|
|
|
49
49
|
abstract page<T>(tableName: string, sortKey: string, maxResults: number, pageNumber: number, filters?: {
|
|
50
50
|
[key: string]: Primitive | Array<Primitive>;
|
|
51
51
|
}): Promise<Pagination<T>>;
|
|
52
|
+
abstract exist(tableName: string, filters?: {
|
|
53
|
+
[key: string]: Primitive | Array<Primitive>;
|
|
54
|
+
}): Promise<boolean>;
|
|
52
55
|
abstract count(tableName: string, filters?: {
|
|
53
56
|
[key: string]: Primitive | Array<Primitive>;
|
|
54
57
|
}): Promise<number>;
|
|
@@ -37,6 +37,9 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
|
|
|
37
37
|
page<T>(tableName: string, sortKey: string, maxResults?: number, pageNumber?: number, filters?: {
|
|
38
38
|
[key: string]: Primitive | Array<Primitive>;
|
|
39
39
|
}): Promise<Pagination<T>>;
|
|
40
|
+
exist(tableName: string, filters?: {
|
|
41
|
+
[p: string]: Primitive | Array<Primitive>;
|
|
42
|
+
}): Promise<boolean>;
|
|
40
43
|
count(tableName: string, filters?: {
|
|
41
44
|
[key: string]: Primitive | Array<Primitive>;
|
|
42
45
|
}): Promise<number>;
|
package/package.json
CHANGED
|
@@ -70,6 +70,8 @@ export default abstract class RepositoryDatabase extends Repository
|
|
|
70
70
|
|
|
71
71
|
abstract page<T>(tableName: string, sortKey: string, maxResults: number, pageNumber: number, filters?: {[key:string]:Primitive|Array<Primitive>}): Promise<Pagination<T>>;
|
|
72
72
|
|
|
73
|
+
abstract exist(tableName: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<boolean>;
|
|
74
|
+
|
|
73
75
|
abstract count(tableName: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<number>;
|
|
74
76
|
|
|
75
77
|
abstract select(tableName: string, select: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<string[]>;
|
|
@@ -137,13 +137,17 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
async exist(tableName: string, filters: { [p: string]: Primitive | Array<Primitive> }={}): Promise<boolean> {
|
|
141
|
+
return (await this.count(tableName, filters)) > 0;
|
|
142
|
+
}
|
|
143
|
+
|
|
140
144
|
async count(tableName: string, filters: { [key: string]: Primitive | Array<Primitive> }={}): Promise<number>
|
|
141
145
|
{
|
|
142
146
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
143
147
|
let schema = this.tables[tableName][0].schema;
|
|
144
148
|
let { where, values } = this.toWhere(tableName, filters);
|
|
145
149
|
let query = `SELECT count(*) as count FROM ${schema}.${tableName} WHERE ${where}`
|
|
146
|
-
return this.query<{count:number}>(query, values).then((result) => result[0]
|
|
150
|
+
return this.query<{count:number}>(query, values).then((result) => result[0]?.count ?? 0);
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
async select(tableName: string, select: string, filters: { [key: string]: Primitive | Array<Primitive> }={}): Promise<string[]>
|
|
@@ -152,7 +156,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
152
156
|
let schema = this.tables[tableName][0].schema;
|
|
153
157
|
let { where, values } = this.toWhere(tableName, filters);
|
|
154
158
|
let query = `SELECT json_agg(u.${select}) as list FROM ${schema}.${tableName} u WHERE ${where}`
|
|
155
|
-
return this.query<{list:string[]}>(query, values).then((result) => result[0]
|
|
159
|
+
return this.query<{list:string[]}>(query, values).then((result) => result[0]?.list ?? []);
|
|
156
160
|
}
|
|
157
161
|
|
|
158
162
|
async del<T>(tableName: string, id: string): Promise<T>
|