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;