接口请求报错
This commit is contained in:
+6
-1
@@ -16,8 +16,13 @@ async function paginate(queryFn, sql, params, page = 1, pageSize = 20) {
|
||||
const p = Math.max(1, parseInt(page) || 1)
|
||||
const ps = Math.min(100, Math.max(1, parseInt(pageSize) || 20))
|
||||
|
||||
// 分离 ORDER BY,避免子查询中不允许 ORDER BY 导致报错
|
||||
const orderByMatch = sql.match(/\s+ORDER\s+BY\s+.+$/i)
|
||||
const orderBy = orderByMatch ? orderByMatch[0] : ''
|
||||
const countSql = orderBy ? sql.slice(0, orderByMatch.index) : sql
|
||||
|
||||
const countResult = await queryFn(
|
||||
`SELECT COUNT(*) as total FROM (${sql}) AS _paged`,
|
||||
`SELECT COUNT(*) as total FROM (${countSql}) AS _paged`,
|
||||
params
|
||||
)
|
||||
const total = countResult[0].total
|
||||
|
||||
Reference in New Issue
Block a user