pg-mvc-service 2.0.11 → 2.0.13

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.
@@ -94,12 +94,6 @@ class TableModel {
94
94
  }
95
95
  return sql;
96
96
  }
97
- set OffsetPage(value) {
98
- if (value > 0) {
99
- this.Limit = this.PageCount;
100
- this.Offset = (value - 1) * this.PageCount;
101
- }
102
- }
103
97
  get Client() {
104
98
  return this.client;
105
99
  }
@@ -112,7 +106,6 @@ class TableModel {
112
106
  this.references = [];
113
107
  this.IsOutputLog = false;
114
108
  this.SortKeyword = 'asc';
115
- this.PageCount = 10;
116
109
  this.selectExpressions = [];
117
110
  this.joinConditions = [];
118
111
  this.whereExpressions = [];
@@ -315,17 +308,26 @@ class TableModel {
315
308
  return data.rows;
316
309
  });
317
310
  }
318
- executeSelectWithCount() {
311
+ executeSelectForPage(pageCount, currentPage) {
319
312
  return __awaiter(this, void 0, void 0, function* () {
320
313
  if (this.selectExpressions.length == 0) {
321
314
  this.select();
322
315
  }
316
+ this.Limit = pageCount;
317
+ this.Offset = (currentPage - 1) * pageCount;
323
318
  let sql = ` SELECT ${this.selectExpressions.join(",")} ${this.createSqlFromJoinWhereSortLimit}`;
324
319
  let countSql = ` SELECT COUNT(*) as "count" ${this.createSqlFromJoinWhere}`;
325
320
  let tempVars = [...this.vars];
326
321
  const data = yield this.executeQuery(sql, tempVars);
327
322
  const countData = yield this.executeQuery(countSql, tempVars);
328
- return { datas: data.rows, count: Number(countData.rows[0].count), lastPage: Math.ceil(Number(countData.rows[0].count) / this.PageCount) };
323
+ const totalCount = Number(countData.rows[0].count);
324
+ const lastPage = Math.ceil(Number(countData.rows[0].count) / pageCount);
325
+ return {
326
+ datas: data.rows,
327
+ totalCount: totalCount,
328
+ lastPage: lastPage,
329
+ isLastData: currentPage >= lastPage
330
+ };
329
331
  });
330
332
  }
331
333
  throwException(code, type, columnName, value) {
@@ -531,7 +533,6 @@ class TableModel {
531
533
  this.vars = [];
532
534
  this.Offset = undefined;
533
535
  this.Limit = undefined;
534
- this.PageCount = 10;
535
536
  let sql = '';
536
537
  if (typeof param1 === 'string') {
537
538
  sql = param1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -66,7 +66,6 @@ export class TableModel {
66
66
  public SortKeyword: TSortKeyword = 'asc';
67
67
  public Offset?: number;
68
68
  public Limit?: number;
69
- public PageCount: number = 10;
70
69
 
71
70
  private selectExpressions: Array<string> = [];
72
71
  private joinConditions: Array<{
@@ -122,12 +121,6 @@ export class TableModel {
122
121
  }
123
122
  return sql;
124
123
  }
125
- set OffsetPage(value: number) {
126
- if (value > 0) {
127
- this.Limit = this.PageCount;
128
- this.Offset = (value - 1) * this.PageCount;
129
- }
130
- }
131
124
 
132
125
  private client: PoolClient | Pool;
133
126
  get Client(): PoolClient | Pool {
@@ -369,18 +362,29 @@ export class TableModel {
369
362
  return data.rows as Array<T>;
370
363
  }
371
364
 
372
- public async executeSelectWithCount<T = any>(): Promise<{ datas: Array<T>, count: number, lastPage: number}> {
365
+ public async executeSelectForPage<T = any>(pageCount: number, currentPage: number): Promise<{ datas: Array<T>, totalCount: number, lastPage: number, isLastData: boolean}> {
373
366
  if (this.selectExpressions.length == 0) {
374
367
  this.select();
375
368
  }
376
369
 
370
+ this.Limit = pageCount;
371
+ this.Offset = (currentPage - 1) * pageCount;
372
+
377
373
  let sql = ` SELECT ${this.selectExpressions.join(",")} ${this.createSqlFromJoinWhereSortLimit}`;
378
374
  let countSql = ` SELECT COUNT(*) as "count" ${this.createSqlFromJoinWhere}`;
379
375
  let tempVars = [...this.vars];
380
376
  const data = await this.executeQuery(sql, tempVars);
381
377
 
382
378
  const countData = await this.executeQuery(countSql, tempVars);
383
- return { datas: data.rows as Array<T>, count: Number(countData.rows[0].count), lastPage: Math.ceil(Number(countData.rows[0].count) / this.PageCount)};
379
+
380
+ const totalCount = Number(countData.rows[0].count);
381
+ const lastPage = Math.ceil(Number(countData.rows[0].count) / pageCount);
382
+ return {
383
+ datas: data.rows as Array<T>,
384
+ totalCount: totalCount,
385
+ lastPage: lastPage,
386
+ isLastData: currentPage >= lastPage
387
+ };
384
388
  }
385
389
 
386
390
  protected readonly errorMessages: TOptionErrorMessage =
@@ -610,7 +614,6 @@ export class TableModel {
610
614
  this.vars = [];
611
615
  this.Offset = undefined;
612
616
  this.Limit = undefined;
613
- this.PageCount = 10;
614
617
 
615
618
  let sql = '';
616
619
  if (typeof param1 === 'string') {