Fixing some issues with using offsets.
This commit is contained in:
parent
e402f9c571
commit
908b77fd9b
|
@ -33,9 +33,9 @@ export async function search(
|
||||||
let bookmark =
|
let bookmark =
|
||||||
(params.bookmark && parseInt(params.bookmark as string)) || undefined
|
(params.bookmark && parseInt(params.bookmark as string)) || undefined
|
||||||
if (paginate && !bookmark) {
|
if (paginate && !bookmark) {
|
||||||
bookmark = 1
|
bookmark = 0
|
||||||
}
|
}
|
||||||
let paginateObj = {}
|
let paginateObj: PaginationJson | undefined
|
||||||
|
|
||||||
if (paginate && !limit) {
|
if (paginate && !limit) {
|
||||||
throw new Error("Cannot paginate query without a limit")
|
throw new Error("Cannot paginate query without a limit")
|
||||||
|
@ -45,7 +45,9 @@ export async function search(
|
||||||
paginateObj = {
|
paginateObj = {
|
||||||
// add one so we can track if there is another page
|
// add one so we can track if there is another page
|
||||||
limit: limit + 1,
|
limit: limit + 1,
|
||||||
page: bookmark,
|
}
|
||||||
|
if (bookmark) {
|
||||||
|
paginateObj.offset = limit * bookmark
|
||||||
}
|
}
|
||||||
} else if (params && limit) {
|
} else if (params && limit) {
|
||||||
paginateObj = {
|
paginateObj = {
|
||||||
|
@ -97,7 +99,11 @@ export async function search(
|
||||||
})
|
})
|
||||||
|
|
||||||
// need wrapper object for bookmarks etc when paginating
|
// need wrapper object for bookmarks etc when paginating
|
||||||
return { rows, hasNextPage, bookmark: bookmark && bookmark + 1 }
|
const response: SearchResponse<Row> = { rows, hasNextPage }
|
||||||
|
if (hasNextPage && bookmark != null) {
|
||||||
|
response.bookmark = bookmark + 1
|
||||||
|
}
|
||||||
|
return response
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.message && err.message.includes("does not exist")) {
|
if (err.message && err.message.includes("does not exist")) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
Loading…
Reference in New Issue