1
0
Fork 0
mirror of synced 2024-09-09 22:16:26 +12:00

Return total rows

This commit is contained in:
adrinr 2023-03-15 17:39:20 +01:00
parent c763c6fae5
commit 1c828db694

View file

@ -7,7 +7,8 @@ const QUERY_START_REGEX = /\d[0-9]*:/g
interface SearchResponse<T> { interface SearchResponse<T> {
rows: T[] | any[] rows: T[] | any[]
bookmark: string bookmark?: string
totalRows: number
} }
interface PaginatedSearchResponse<T> extends SearchResponse<T> { interface PaginatedSearchResponse<T> extends SearchResponse<T> {
@ -503,8 +504,10 @@ async function runQuery<T>(
} }
const json = await response.json() const json = await response.json()
let output: any = { let output: SearchResponse<T> = {
rows: [], rows: [],
totalRows: 0,
} }
if (json.rows != null && json.rows.length > 0) { if (json.rows != null && json.rows.length > 0) {
output.rows = json.rows.map((row: any) => row.doc) output.rows = json.rows.map((row: any) => row.doc)
@ -512,6 +515,9 @@ async function runQuery<T>(
if (json.bookmark) { if (json.bookmark) {
output.bookmark = json.bookmark output.bookmark = json.bookmark
} }
if (json.total_rows) {
output.totalRows = json.total_rows
}
return output return output
} }