@dwtechs/antity-pgsql 0.7.0 → 0.8.1

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/README.md CHANGED
@@ -174,7 +174,6 @@ class SQLEntity {
174
174
 
175
175
  query: {
176
176
  select: (
177
- paginate: boolean,
178
177
  first?: number,
179
178
  rows?: number | null,
180
179
  sortField?: string | null,
@@ -233,6 +232,7 @@ function execute(
233
232
  get(), add(), update(), archive(), delete() and deleteArchive() methods are made to be used as Express.js middlewares.
234
233
  Each method will look for data to work on in the **req.body.rows** parameter.
235
234
 
235
+ - **query.select()**: Generates a SELECT query. When the `rows` parameter is provided (not null), pagination is automatically enabled and the query includes `COUNT(*) OVER () AS total` to return the total number of rows. The total count is extracted from results and returned separately from the row data.
236
236
  - **delete()**: Deletes rows by their IDs. Expects `req.body.rows` to be an array of objects with `id` property: `[{id: 1}, {id: 2}]`
237
237
  - **deleteArchive()**: Deletes archived rows that were archived before a specific date. Expects `req.body.date` to be a Date object.
238
238
 
@@ -78,7 +78,6 @@ declare class SQLEntity extends Entity {
78
78
  set table(table: string);
79
79
  query: {
80
80
  select: (
81
- paginate: boolean,
82
81
  first?: number,
83
82
  rows?: number | null,
84
83
  sortField?: string | null,
@@ -222,8 +222,8 @@ class Select {
222
222
  get props() {
223
223
  return this._cols;
224
224
  }
225
- query(table, paginate, first = 0, rows = null, sortField = null, sortOrder = null, filters = null) {
226
- const p = paginate ? this._count : '';
225
+ query(table, first = 0, rows = null, sortField = null, sortOrder = null, filters = null) {
226
+ const p = rows ? this._count : '';
227
227
  const c = this._cols ? this._cols : '*';
228
228
  const baseQuery = `SELECT ${c}${p} FROM ${quoteIfUppercase(table)}`;
229
229
  const { filterClause, args } = filter(first, rows, sortField, sortOrder, filters);
@@ -336,7 +336,7 @@ class Update {
336
336
  query += `WHEN id = $${j + 1} THEN $${i++} `;
337
337
  args.push(row[p]);
338
338
  }
339
- query += `END, `;
339
+ query += `ELSE ${quoteIfUppercase(p)} END, `;
340
340
  }
341
341
  query = `${query.slice(0, -2)} WHERE id IN ${$i(l, 0)}`;
342
342
  return { query, args };
@@ -558,8 +558,8 @@ class SQLEntity extends Entity {
558
558
  this.ins = new Insert();
559
559
  this.upd = new Update();
560
560
  this.query = {
561
- select: (paginate, first = 0, rows = null, sortField = null, sortOrder = null, filters = null) => {
562
- return this.sel.query(this.table, paginate, first, rows, sortField, sortOrder, filters);
561
+ select: (first = 0, rows = null, sortField = null, sortOrder = null, filters = null) => {
562
+ return this.sel.query(this.table, first, rows, sortField, sortOrder, filters);
563
563
  },
564
564
  update: (rows, consumerId, consumerName) => {
565
565
  return this.upd.query(this.table, rows, consumerId, consumerName);
@@ -591,7 +591,7 @@ class SQLEntity extends Entity {
591
591
  log.debug(`get(first='${first}', rows='${rows}',
592
592
  sortOrder='${sortOrder}', sortField='${sortField}',
593
593
  pagination=${pagination}, filters=${JSON.stringify(filters)}`);
594
- const { query, args } = this.sel.query(this._table, pagination, first, rows, sortField, sortOrder, filters);
594
+ const { query, args } = this.sel.query(this._table, first, rows, sortField, sortOrder, filters);
595
595
  this.sel.execute(query, args, dbClient)
596
596
  .then((r) => {
597
597
  l.rows = r.rows;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwtechs/antity-pgsql",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "Open source library to add PostgreSQL support to @dwtechs/Antity entities.",
5
5
  "keywords": [
6
6
  "entities"