1
0
Fork 0
mirror of synced 2024-07-13 02:05:54 +12:00

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

View file

@ -10,6 +10,8 @@ import {
SortType,
FieldConstraints,
SortOrder,
RowSearchParams,
EmptyFilterOption,
} from "@budibase/types"
import dayjs from "dayjs"
import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants"
@ -260,6 +262,17 @@ export const buildQuery = (filter: SearchFilter[]) => {
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
* @param docs the data
@ -278,6 +291,13 @@ export const runQuery = (
query = cleanupQuery(query)
if (
!hasFilters(query) &&
query.onEmptyFilter === EmptyFilterOption.RETURN_NONE
) {
return []
}
const match =
(
type: SearchFilterOperator,