pg-mvc-service 2.0.17 → 2.0.19
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.
|
@@ -59,7 +59,6 @@ class TableModel {
|
|
|
59
59
|
}
|
|
60
60
|
get createSqlFromJoinWhere() {
|
|
61
61
|
let sql = ` FROM ${this.TableName} as "${this.TableAlias}"`;
|
|
62
|
-
console.log('createSqlFromJoinWhere', this.joinConditions.length);
|
|
63
62
|
for (const join of this.joinConditions) {
|
|
64
63
|
const joins = {
|
|
65
64
|
inner: ' INNER JOIN',
|
|
@@ -68,9 +67,7 @@ class TableModel {
|
|
|
68
67
|
};
|
|
69
68
|
sql += joins[join.type];
|
|
70
69
|
sql += ` ${join.model.TableName} as "${join.model.TableAlias}" ON `;
|
|
71
|
-
console.log(join.conditions, 'createSqlFronJOin', this.vars);
|
|
72
70
|
const query = WhereExpression_1.default.createCondition(join.conditions, this, this.vars.length + 1);
|
|
73
|
-
console.log('createSqlFronJoin end', this.vars, query.vars);
|
|
74
71
|
sql += query.expression;
|
|
75
72
|
if (query.vars !== undefined) {
|
|
76
73
|
this.vars = [...this.vars, ...query.vars];
|
|
@@ -210,7 +207,6 @@ class TableModel {
|
|
|
210
207
|
* @param conditions 結合条件を指定します。条件はオブジェクトまたは文字列で指定できます。
|
|
211
208
|
*/
|
|
212
209
|
join(joinType, joinModel, conditions) {
|
|
213
|
-
console.log({ type: joinType, conditions: conditions }, this.joinConditions);
|
|
214
210
|
this.joinConditions.push({ type: joinType, model: joinModel, conditions: conditions });
|
|
215
211
|
}
|
|
216
212
|
where(left, operator, right) {
|
|
@@ -320,8 +316,8 @@ class TableModel {
|
|
|
320
316
|
this.Limit = pageCount;
|
|
321
317
|
this.Offset = (currentPage - 1) * pageCount;
|
|
322
318
|
let sql = ` SELECT ${this.selectExpressions.join(",")} ${this.createSqlFromJoinWhereSortLimit}`;
|
|
319
|
+
let tempVars = [...this.vars]; // 後のthis.createSqlFromJoinWhereでvarの追加をしてしまうので、上の時点でvarを決定する
|
|
323
320
|
let countSql = ` SELECT COUNT(*) as "count" ${this.createSqlFromJoinWhere}`;
|
|
324
|
-
let tempVars = [...this.vars];
|
|
325
321
|
const data = yield this.executeQuery(sql, tempVars);
|
|
326
322
|
const countData = yield this.executeQuery(countSql, tempVars);
|
|
327
323
|
const totalCount = Number(countData.rows[0].count);
|
package/package.json
CHANGED
package/src/models/TableModel.ts
CHANGED
|
@@ -81,7 +81,6 @@ export class TableModel {
|
|
|
81
81
|
private get createSqlFromJoinWhere(): string {
|
|
82
82
|
let sql = ` FROM ${this.TableName} as "${this.TableAlias}"`;
|
|
83
83
|
|
|
84
|
-
console.log('createSqlFromJoinWhere', this.joinConditions.length);
|
|
85
84
|
for (const join of this.joinConditions) {
|
|
86
85
|
const joins = {
|
|
87
86
|
inner: ' INNER JOIN',
|
|
@@ -90,9 +89,7 @@ export class TableModel {
|
|
|
90
89
|
}
|
|
91
90
|
sql += joins[join.type];
|
|
92
91
|
sql += ` ${join.model.TableName} as "${join.model.TableAlias}" ON `;
|
|
93
|
-
console.log(join.conditions, 'createSqlFronJOin', this.vars);
|
|
94
92
|
const query = WhereExpression.createCondition(join.conditions, this, this.vars.length + 1);
|
|
95
|
-
console.log('createSqlFronJoin end', this.vars, query.vars);
|
|
96
93
|
sql += query.expression;
|
|
97
94
|
if (query.vars !== undefined) {
|
|
98
95
|
this.vars = [...this.vars, ...query.vars]
|
|
@@ -250,7 +247,6 @@ export class TableModel {
|
|
|
250
247
|
* @param conditions 結合条件を指定します。条件はオブジェクトまたは文字列で指定できます。
|
|
251
248
|
*/
|
|
252
249
|
public join(joinType: 'left' | 'inner' | 'full', joinModel: TableModel, conditions: Array<TNestedCondition>): void {
|
|
253
|
-
console.log({type: joinType, conditions: conditions}, this.joinConditions);
|
|
254
250
|
this.joinConditions.push({type: joinType, model: joinModel, conditions: conditions});
|
|
255
251
|
}
|
|
256
252
|
|
|
@@ -375,8 +371,10 @@ export class TableModel {
|
|
|
375
371
|
this.Offset = (currentPage - 1) * pageCount;
|
|
376
372
|
|
|
377
373
|
let sql = ` SELECT ${this.selectExpressions.join(",")} ${this.createSqlFromJoinWhereSortLimit}`;
|
|
374
|
+
let tempVars = [...this.vars]; // 後のthis.createSqlFromJoinWhereでvarの追加をしてしまうので、上の時点でvarを決定する
|
|
375
|
+
|
|
378
376
|
let countSql = ` SELECT COUNT(*) as "count" ${this.createSqlFromJoinWhere}`;
|
|
379
|
-
|
|
377
|
+
|
|
380
378
|
const data = await this.executeQuery(sql, tempVars);
|
|
381
379
|
|
|
382
380
|
const countData = await this.executeQuery(countSql, tempVars);
|