1
0
Fork 0
mirror of synced 2024-10-04 03:54:37 +13:00

Implementing row counting for in-memory, also updating the in memory search function.

This commit is contained in:
mike12345567 2024-06-19 17:51:11 +01:00
parent d121633d8e
commit 58ec7a50b0
2 changed files with 13 additions and 5 deletions

View file

@ -95,7 +95,7 @@ describe.each([
private async performSearch(): Promise<SearchResponse<Row>> {
if (isInMemory) {
return { rows: dataFilters.search(_.cloneDeep(rows), this.query) }
return dataFilters.search(_.cloneDeep(rows), this.query)
} else {
return config.api.row.search(table._id!, {
...this.query,
@ -1822,9 +1822,8 @@ describe.each([
]))
})
// lucene can't count, and in memory there is no point
// lucene can't count the total rows
!isLucene &&
!isInMemory &&
describe("row counting", () => {
beforeAll(async () => {
table = await createTable({

View file

@ -12,6 +12,7 @@ import {
SortOrder,
RowSearchParams,
EmptyFilterOption,
SearchResponse,
} from "@budibase/types"
import dayjs from "dayjs"
import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants"
@ -262,15 +263,23 @@ export const buildQuery = (filter: SearchFilter[]) => {
return query
}
export const search = (docs: Record<string, any>[], query: RowSearchParams) => {
export const search = (
docs: Record<string, any>[],
query: RowSearchParams
): SearchResponse<Record<string, any>> => {
let result = runQuery(docs, query.query)
if (query.sort) {
result = sort(result, query.sort, query.sortOrder || SortOrder.ASCENDING)
}
let totalRows = result.length
if (query.limit) {
result = limit(result, query.limit.toString())
}
return result
const response: SearchResponse<Record<string, any>> = { rows: result }
if (query.countRows) {
response.totalRows = totalRows
}
return response
}
/**