forked from Wroclaw/WorkshopTasker
fix typos, fix logic of "around"
This commit is contained in:
parent
42a1c9fe1a
commit
28f0d7992e
1 changed files with 5 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue