fix typos, fix logic of "around"

This commit is contained in:
Wroclaw 2023-05-11 10:27:24 +02:00
parent 42a1c9fe1a
commit 28f0d7992e

View file

@ -74,17 +74,18 @@ export default class BaaPagination<T extends {[k: string]: any}, keyType extends
}
case "after": {
const [data] = await database.query(
`SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM \`${this.table}\` WHERE \`$this.key\` > ? 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<T>;
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<T>;
return data;