Return total rows
This commit is contained in:
parent
c763c6fae5
commit
1c828db694
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue