pg-mvc-service 2.0.12 → 2.0.14

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.
@@ -67,7 +67,9 @@ class TableModel {
67
67
  };
68
68
  sql += joins[join.type];
69
69
  sql += ` ${join.model.TableName} as "${join.model.TableAlias}" ON `;
70
+ console.log('createSqlFronJOin', this.vars);
70
71
  const query = WhereExpression_1.default.createCondition(join.conditions, this, this.vars.length + 1);
72
+ console.log('createSqlFronJoin end', this.vars, query.vars);
71
73
  sql += query.expression;
72
74
  if (query.vars !== undefined) {
73
75
  this.vars = [...this.vars, ...query.vars];
@@ -94,12 +96,6 @@ class TableModel {
94
96
  }
95
97
  return sql;
96
98
  }
97
- set OffsetPage(value) {
98
- if (value > 0) {
99
- this.Limit = this.PageCount;
100
- this.Offset = (value - 1) * this.PageCount;
101
- }
102
- }
103
99
  get Client() {
104
100
  return this.client;
105
101
  }
@@ -112,7 +108,6 @@ class TableModel {
112
108
  this.references = [];
113
109
  this.IsOutputLog = false;
114
110
  this.SortKeyword = 'asc';
115
- this.PageCount = 10;
116
111
  this.selectExpressions = [];
117
112
  this.joinConditions = [];
118
113
  this.whereExpressions = [];
@@ -315,17 +310,26 @@ class TableModel {
315
310
  return data.rows;
316
311
  });
317
312
  }
318
- executeSelectWithCount() {
313
+ executeSelectForPage(pageCount, currentPage) {
319
314
  return __awaiter(this, void 0, void 0, function* () {
320
315
  if (this.selectExpressions.length == 0) {
321
316
  this.select();
322
317
  }
318
+ this.Limit = pageCount;
319
+ this.Offset = (currentPage - 1) * pageCount;
323
320
  let sql = ` SELECT ${this.selectExpressions.join(",")} ${this.createSqlFromJoinWhereSortLimit}`;
324
321
  let countSql = ` SELECT COUNT(*) as "count" ${this.createSqlFromJoinWhere}`;
325
322
  let tempVars = [...this.vars];
326
323
  const data = yield this.executeQuery(sql, tempVars);
327
324
  const countData = yield this.executeQuery(countSql, tempVars);
328
- return { datas: data.rows, total_count: Number(countData.rows[0].count), last_page: Math.ceil(Number(countData.rows[0].count) / this.PageCount) };
325
+ const totalCount = Number(countData.rows[0].count);
326
+ const lastPage = Math.ceil(Number(countData.rows[0].count) / pageCount);
327
+ return {
328
+ datas: data.rows,
329
+ totalCount: totalCount,
330
+ lastPage: lastPage,
331
+ isLastData: currentPage >= lastPage
332
+ };
329
333
  });
330
334
  }
331
335
  throwException(code, type, columnName, value) {
@@ -531,7 +535,6 @@ class TableModel {
531
535
  this.vars = [];
532
536
  this.Offset = undefined;
533
537
  this.Limit = undefined;
534
- this.PageCount = 10;
535
538
  let sql = '';
536
539
  if (typeof param1 === 'string') {
537
540
  sql = param1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
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<{
@@ -90,7 +89,9 @@ export class TableModel {
90
89
  }
91
90
  sql += joins[join.type];
92
91
  sql += ` ${join.model.TableName} as "${join.model.TableAlias}" ON `;
92
+ console.log('createSqlFronJOin', this.vars);
93
93
  const query = WhereExpression.createCondition(join.conditions, this, this.vars.length + 1);
94
+ console.log('createSqlFronJoin end', this.vars, query.vars);
94
95
  sql += query.expression;
95
96
  if (query.vars !== undefined) {
96
97
  this.vars = [...this.vars, ...query.vars]
@@ -122,12 +123,6 @@ export class TableModel {
122
123
  }
123
124
  return sql;
124
125
  }
125
- set OffsetPage(value: number) {
126
- if (value > 0) {
127
- this.Limit = this.PageCount;
128
- this.Offset = (value - 1) * this.PageCount;
129
- }
130
- }
131
126
 
132
127
  private client: PoolClient | Pool;
133
128
  get Client(): PoolClient | Pool {
@@ -369,18 +364,29 @@ export class TableModel {
369
364
  return data.rows as Array<T>;
370
365
  }
371
366
 
372
- public async executeSelectWithCount<T = any>(): Promise<{ datas: Array<T>, total_count: number, last_page: number}> {
367
+ public async executeSelectForPage<T = any>(pageCount: number, currentPage: number): Promise<{ datas: Array<T>, totalCount: number, lastPage: number, isLastData: boolean}> {
373
368
  if (this.selectExpressions.length == 0) {
374
369
  this.select();
375
370
  }
376
371
 
372
+ this.Limit = pageCount;
373
+ this.Offset = (currentPage - 1) * pageCount;
374
+
377
375
  let sql = ` SELECT ${this.selectExpressions.join(",")} ${this.createSqlFromJoinWhereSortLimit}`;
378
376
  let countSql = ` SELECT COUNT(*) as "count" ${this.createSqlFromJoinWhere}`;
379
377
  let tempVars = [...this.vars];
380
378
  const data = await this.executeQuery(sql, tempVars);
381
379
 
382
380
  const countData = await this.executeQuery(countSql, tempVars);
383
- return { datas: data.rows as Array<T>, total_count: Number(countData.rows[0].count), last_page: Math.ceil(Number(countData.rows[0].count) / this.PageCount)};
381
+
382
+ const totalCount = Number(countData.rows[0].count);
383
+ const lastPage = Math.ceil(Number(countData.rows[0].count) / pageCount);
384
+ return {
385
+ datas: data.rows as Array<T>,
386
+ totalCount: totalCount,
387
+ lastPage: lastPage,
388
+ isLastData: currentPage >= lastPage
389
+ };
384
390
  }
385
391
 
386
392
  protected readonly errorMessages: TOptionErrorMessage =
@@ -610,7 +616,6 @@ export class TableModel {
610
616
  this.vars = [];
611
617
  this.Offset = undefined;
612
618
  this.Limit = undefined;
613
- this.PageCount = 10;
614
619
 
615
620
  let sql = '';
616
621
  if (typeof param1 === 'string') {