From b14cf774ec8a557d2b9d3ce6b2e06e99e5dfe327 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Thu, 11 May 2023 10:51:41 +0200 Subject: [PATCH] allow select modification --- server/utils/baaPagination.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/utils/baaPagination.ts b/server/utils/baaPagination.ts index ea3cd0f..6978a6a 100644 --- a/server/utils/baaPagination.ts +++ b/server/utils/baaPagination.ts @@ -21,6 +21,7 @@ type queryType = { export default class BaaPagination { readonly table: string; readonly key: keyType; + readonly select: string; /** * Gets queryType for a given query with a value @@ -70,24 +71,24 @@ export default class BaaPagination; return data; } case "after": { const [data] = await database.query( - `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 LIMIT ?`, [queryType.id, ...bind, limit], ) as unknown as data; return data; } case "around": { const [data] = await database.query( - ` SELECT *, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM (\n` + + ` SELECT ${this.select}, CONVERT(\`${this.key}\`, CHAR) AS \`${this.key}\` FROM (\n` + `(SELECT * FROM \`${this.table}\` WHERE \`${this.key}\` >= ? ${sqlwhere} ORDER BY \`${this.key}\` ASC LIMIT ?)\n` + "UNION ALL\n" + - `(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 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; @@ -95,7 +96,7 @@ export default class BaaPagination; return data; @@ -167,7 +168,7 @@ export default class BaaPagination; @@ -206,7 +207,7 @@ export default class BaaPagination; @@ -241,8 +242,9 @@ export default class BaaPagination