Down to 0 failures.

This commit is contained in:
Sam Rose 2024-06-13 17:46:03 +01:00
parent f909cdee43
commit 1161c185e2
No known key found for this signature in database
2 changed files with 27 additions and 18 deletions

View File

@ -26,12 +26,12 @@ import { dataFilters } from "@budibase/shared-core"
describe.each([ describe.each([
["in-memory", undefined], ["in-memory", undefined],
// ["lucene", undefined], ["lucene", undefined],
// ["sqs", undefined], ["sqs", undefined],
// [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
// [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
// [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
// [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
])("search (%s)", (name, dsProvider) => { ])("search (%s)", (name, dsProvider) => {
const isSqs = name === "sqs" const isSqs = name === "sqs"
const isLucene = name === "lucene" const isLucene = name === "lucene"
@ -94,18 +94,7 @@ describe.each([
private async performSearch(): Promise<Row[]> { private async performSearch(): Promise<Row[]> {
if (isInMemory) { if (isInMemory) {
let result = dataFilters.runQuery(_.cloneDeep(rows), this.query.query) return dataFilters.search(_.cloneDeep(rows), this.query)
if (this.query.sort) {
result = dataFilters.sort(
result,
this.query.sort,
this.query.sortOrder || SortOrder.ASCENDING
)
}
if (this.query.limit) {
result = dataFilters.limit(result, this.query.limit.toString())
}
return result
} else { } else {
return ( return (
await config.api.row.search(table._id!, { await config.api.row.search(table._id!, {

View File

@ -10,6 +10,8 @@ import {
SortType, SortType,
FieldConstraints, FieldConstraints,
SortOrder, SortOrder,
RowSearchParams,
EmptyFilterOption,
} from "@budibase/types" } from "@budibase/types"
import dayjs from "dayjs" import dayjs from "dayjs"
import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants" import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants"
@ -260,6 +262,17 @@ export const buildQuery = (filter: SearchFilter[]) => {
return query return query
} }
export const search = (docs: Record<string, any>[], query: RowSearchParams) => {
let result = runQuery(docs, query.query)
if (query.sort) {
result = sort(result, query.sort, query.sortOrder || SortOrder.ASCENDING)
}
if (query.limit) {
result = limit(result, query.limit.toString())
}
return result
}
/** /**
* Performs a client-side search on an array of data * Performs a client-side search on an array of data
* @param docs the data * @param docs the data
@ -278,6 +291,13 @@ export const runQuery = (
query = cleanupQuery(query) query = cleanupQuery(query)
if (
!hasFilters(query) &&
query.onEmptyFilter === EmptyFilterOption.RETURN_NONE
) {
return []
}
const match = const match =
( (
type: SearchFilterOperator, type: SearchFilterOperator,