From 28f0d7992ee107fcb4ca60e4af7248d49010da81 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Thu, 11 May 2023 10:27:24 +0200 Subject: [PATCH] fix typos, fix logic of "around" --- server/utils/baaPagination.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index 810eff4..dc80ff5 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -74,17 +74,18 @@ export default class BaaPagination ? ORDER BY \`${this.key}\` DESC LIMIT ?`, + `SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` > ? ORDER BY \`${this.key}\` DESC LIMIT ?`, [queryType.id, limit], ) as unknown as data; return data; } case "around": { const [data] = await database.query( - `(SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + + ` SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM (\n` + + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + "UNION ALL\n" + - `(SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`${this.key}\` < ? ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + - "ORDER BY `id` DESC", + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` < ? ORDER BY \`${this.key}\` DESC LIMIT ?)\n` + + `) as \`x\` ORDER BY \`${this.key}\` DESC`, [queryType.id, Math.ceil(limit / 2), queryType.id, Math.floor(limit / 2)], ) as unknown as data; return data;