From 7a9e45173940eb376d46d0da6819046542369ce7 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Thu, 11 May 2023 11:09:28 +0200 Subject: [PATCH] add groupBy --- server/utils/baaPagination.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index e230763..4155145 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -22,6 +22,11 @@ export default class BaaPagination; return data; } case "after": { const [data] = await database.query( - `SELECT ${this.select}, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?`, + `SELECT ${this.select}, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ${sqlwhere} ORDER BY \`${this.key}\` DESC ${this.sqlGroupBy} LIMIT ?`, [queryType.id, ...bind, limit], ) as unknown as data; return data; @@ -86,9 +91,9 @@ export default class BaaPagination= ? ${sqlwhere} ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ${sqlwhere} ORDER BY \`${this.key}\` ${this.sqlGroupBy} ASC LIMIT ?)\n` + "UNION ALL\n" + - `(SELECT ${this.select} FROM \`${this.table}\` WHERE \`${this.key}\` < ? ${sqlwhere} ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + + `(SELECT ${this.select} FROM \`${this.table}\` WHERE \`${this.key}\` < ? ${sqlwhere} ORDER BY \`${this.key}\` DESC ${this.sqlGroupBy} LIMIT ?)\n` + `) as \`x\` ORDER BY \`${this.key}\` DESC`, [queryType.id, ...bind, Math.ceil(limit / 2), queryType.id, ...bind, Math.floor(limit / 2)], ) as unknown as data; @@ -96,7 +101,7 @@ export default class BaaPagination; return data; @@ -234,7 +239,7 @@ export default class BaaPagination; @@ -242,9 +247,15 @@ export default class BaaPagination