ismx-nexo-node-app 0.3.34 → 0.3.36

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.
@@ -23,6 +23,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
23
23
  this.schema = "public";
24
24
  this.onIntrospectedListeners = [];
25
25
  this.native = this.native.bind(this);
26
+ this.introspect = this.introspect.bind(this);
26
27
  }
27
28
  init(chain) {
28
29
  super.init(chain);
@@ -72,7 +73,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
72
73
  return __awaiter(this, void 0, void 0, function* () {
73
74
  if (!this.tables[tableName])
74
75
  throw new Error(`table ${tableName} does not exist`);
75
- let { where, values } = this.toQuery(tableName, filters);
76
+ let { where, values } = this.toWhere(tableName, filters);
76
77
  let query = `SELECT * FROM ${this.schema}.${tableName} WHERE ${where}`;
77
78
  return this.query(query, values);
78
79
  });
@@ -137,7 +138,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
137
138
  let table = this.tables[tableName];
138
139
  let columns = PostgresUtils_1.default.columns(table);
139
140
  let offset = maxResults * pageNumber;
140
- let { where, values } = this.toQuery(tableName, filters, "", 4);
141
+ let { where, values } = this.toWhere(tableName, filters, "", 4);
141
142
  let query = `SELECT * FROM ${this.schema}.${tableName} WHERE ${where} ORDER BY $1 LIMIT $2 OFFSET $3`;
142
143
  let elements = this.query(query, [sortKey, maxResults, offset, ...values]);
143
144
  let total = this.count(tableName, filters);
@@ -148,7 +149,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
148
149
  return __awaiter(this, void 0, void 0, function* () {
149
150
  if (!this.tables[tableName])
150
151
  throw new Error(`table ${tableName} does not exist`);
151
- let { where, values } = this.toQuery(tableName, filters);
152
+ let { where, values } = this.toWhere(tableName, filters);
152
153
  let query = `SELECT count(*) as count FROM ${this.schema}.${tableName} WHERE ${where}`;
153
154
  return this.query(query, values).then((result) => result[0].count);
154
155
  });
@@ -157,7 +158,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
157
158
  return __awaiter(this, void 0, void 0, function* () {
158
159
  if (!this.tables[tableName])
159
160
  throw new Error(`table ${tableName} does not exist`);
160
- let { where, values } = this.toQuery(tableName, filters);
161
+ let { where, values } = this.toWhere(tableName, filters);
161
162
  let query = `SELECT json_agg(u.${select}) as list FROM ${this.schema}.${tableName} u WHERE ${where}`;
162
163
  return this.query(query, values).then((result) => result[0].list);
163
164
  });
@@ -167,7 +168,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
167
168
  throw new Error(`not implemented yet`);
168
169
  });
169
170
  }
170
- toQuery(tableName, filters, alias = "", index = 1) {
171
+ toWhere(tableName, filters, alias = "", index = 1) {
171
172
  let table = this.tables[tableName];
172
173
  let columns = PostgresUtils_1.default.columns(table);
173
174
  let elements = Object.entries(filters !== null && filters !== void 0 ? filters : []);
@@ -45,6 +45,11 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
45
45
  [key: string]: Primitive | Array<Primitive>;
46
46
  }): Promise<string[]>;
47
47
  del<T>(tableName: string, id: string): Promise<T>;
48
- private toQuery;
48
+ toWhere(tableName: string, filters?: {
49
+ [key: string]: Primitive | Array<Primitive>;
50
+ }, alias?: string, index?: number): {
51
+ where: string;
52
+ values: (string | number | Date | Primitive[] | null | undefined)[];
53
+ };
49
54
  private introspect;
50
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.3.34",
3
+ "version": "0.3.36",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -20,6 +20,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
20
20
  constructor() {
21
21
  super();
22
22
  this.native = this.native.bind(this);
23
+ this.introspect = this.introspect.bind(this);
23
24
  }
24
25
 
25
26
  init(chain: Chain)
@@ -72,7 +73,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
72
73
  async find<T>(tableName: string, filters: { [key: string]: Primitive | Array<any> }): Promise<T[]>
73
74
  {
74
75
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
75
- let { where, values } = this.toQuery(tableName, filters);
76
+ let { where, values } = this.toWhere(tableName, filters);
76
77
  let query = `SELECT * FROM ${this.schema}.${tableName} WHERE ${where}`
77
78
  return this.query<T>(query, values);
78
79
  }
@@ -136,7 +137,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
136
137
  let columns = PostgresUtils.columns(table);
137
138
  let offset = maxResults * pageNumber;
138
139
 
139
- let { where, values } = this.toQuery(tableName, filters, "", 4);
140
+ let { where, values } = this.toWhere(tableName, filters, "", 4);
140
141
  let query = `SELECT * FROM ${this.schema}.${tableName} WHERE ${ where } ORDER BY $1 LIMIT $2 OFFSET $3`;
141
142
  let elements = this.query<T>(query, [sortKey, maxResults, offset, ...values])
142
143
 
@@ -149,7 +150,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
149
150
  async count(tableName: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<number>
150
151
  {
151
152
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
152
- let { where, values } = this.toQuery(tableName, filters);
153
+ let { where, values } = this.toWhere(tableName, filters);
153
154
  let query = `SELECT count(*) as count FROM ${this.schema}.${tableName} WHERE ${where}`
154
155
  return this.query<{count:number}>(query, values).then((result) => result[0].count);
155
156
  }
@@ -157,7 +158,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
157
158
  async select(tableName: string, select: string, filters?: { [key: string]: Primitive | Array<Primitive> }): Promise<string[]>
158
159
  {
159
160
  if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
160
- let { where, values } = this.toQuery(tableName, filters);
161
+ let { where, values } = this.toWhere(tableName, filters);
161
162
  let query = `SELECT json_agg(u.${select}) as list FROM ${this.schema}.${tableName} u WHERE ${where}`
162
163
  return this.query<{list:string[]}>(query, values).then((result) => result[0].list);
163
164
  }
@@ -167,7 +168,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
167
168
  throw new Error(`not implemented yet`);
168
169
  }
169
170
 
170
- private toQuery(tableName: string, filters?: { [key: string]: Primitive | Array<Primitive> }, alias:string = "", index=1)
171
+ toWhere(tableName: string, filters?: { [key: string]: Primitive | Array<Primitive> }, alias:string = "", index=1)
171
172
  {
172
173
  let table = this.tables[tableName];
173
174
  let columns = PostgresUtils.columns(table);