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>> { private async performSearch(): Promise<SearchResponse<Row>> {
if (isInMemory) { if (isInMemory) {
return { rows: dataFilters.search(_.cloneDeep(rows), this.query) } return dataFilters.search(_.cloneDeep(rows), this.query)
} else { } else {
return config.api.row.search(table._id!, { return config.api.row.search(table._id!, {
...this.query, ...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 && !isLucene &&
!isInMemory &&
describe("row counting", () => { describe("row counting", () => {
beforeAll(async () => { beforeAll(async () => {
table = await createTable({ table = await createTable({

View File

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