Fix query
This commit is contained in:
parent
68e2313e6c
commit
5c8a789047
|
@ -26,6 +26,7 @@ import {
|
||||||
INTERNAL_TABLE_SOURCE_ID,
|
INTERNAL_TABLE_SOURCE_ID,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import environment from "../../environment"
|
import environment from "../../environment"
|
||||||
|
import { helpers } from "@budibase/shared-core"
|
||||||
|
|
||||||
type QueryFunction = (query: SqlQuery | SqlQuery[], operation: Operation) => any
|
type QueryFunction = (query: SqlQuery | SqlQuery[], operation: Operation) => any
|
||||||
|
|
||||||
|
@ -786,8 +787,7 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
|
||||||
return (
|
return (
|
||||||
field.type === FieldType.JSON ||
|
field.type === FieldType.JSON ||
|
||||||
(field.type === FieldType.BB_REFERENCE &&
|
(field.type === FieldType.BB_REFERENCE &&
|
||||||
// Handling old single user type
|
!helpers.schema.isDeprecatedSingleUserColumn(field))
|
||||||
field.constraints?.type === "array")
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { NoEmptyFilterStrings } from "../../../constants"
|
||||||
import * as sqs from "./search/sqs"
|
import * as sqs from "./search/sqs"
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
import { ExportRowsParams, ExportRowsResult } from "./search/types"
|
import { ExportRowsParams, ExportRowsResult } from "./search/types"
|
||||||
import { dataFilters } from "@budibase/shared-core"
|
import { dataFilters, helpers } from "@budibase/shared-core"
|
||||||
import sdk from "../../index"
|
import sdk from "../../index"
|
||||||
import { searchInputMapping } from "./search/utils"
|
import { searchInputMapping } from "./search/utils"
|
||||||
|
|
||||||
|
@ -79,7 +79,9 @@ export async function search(
|
||||||
}
|
}
|
||||||
|
|
||||||
const table = await sdk.tables.getTable(options.tableId)
|
const table = await sdk.tables.getTable(options.tableId)
|
||||||
options = searchInputMapping(table, options)
|
options = searchInputMapping(table, options, {
|
||||||
|
isSql: !!table.sql || !!env.SQS_SEARCH_ENABLE,
|
||||||
|
})
|
||||||
|
|
||||||
if (isExternalTable) {
|
if (isExternalTable) {
|
||||||
return external.search(options, table)
|
return external.search(options, table)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
RowSearchParams,
|
RowSearchParams,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { db as dbCore, context } from "@budibase/backend-core"
|
import { db as dbCore, context } from "@budibase/backend-core"
|
||||||
import { utils } from "@budibase/shared-core"
|
import { helpers, utils } from "@budibase/shared-core"
|
||||||
|
|
||||||
export async function paginatedSearch(
|
export async function paginatedSearch(
|
||||||
query: SearchFilters,
|
query: SearchFilters,
|
||||||
|
@ -49,13 +49,19 @@ function findColumnInQueries(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function userColumnMapping(column: string, options: RowSearchParams) {
|
function userColumnMapping(
|
||||||
|
column: string,
|
||||||
|
options: RowSearchParams,
|
||||||
|
isDeprecatedSingleUserColumn: boolean = false,
|
||||||
|
isSql: boolean = false
|
||||||
|
) {
|
||||||
findColumnInQueries(column, options, (filterValue: any): any => {
|
findColumnInQueries(column, options, (filterValue: any): any => {
|
||||||
const isArray = Array.isArray(filterValue),
|
const isArray = Array.isArray(filterValue),
|
||||||
isString = typeof filterValue === "string"
|
isString = typeof filterValue === "string"
|
||||||
if (!isString && !isArray) {
|
if (!isString && !isArray) {
|
||||||
return filterValue
|
return filterValue
|
||||||
}
|
}
|
||||||
|
|
||||||
const processString = (input: string) => {
|
const processString = (input: string) => {
|
||||||
const rowPrefix = DocumentType.ROW + SEPARATOR
|
const rowPrefix = DocumentType.ROW + SEPARATOR
|
||||||
if (input.startsWith(rowPrefix)) {
|
if (input.startsWith(rowPrefix)) {
|
||||||
|
@ -64,6 +70,12 @@ function userColumnMapping(column: string, options: RowSearchParams) {
|
||||||
return input
|
return input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDeprecatedSingleUserColumn && filterValue && isString && isSql) {
|
||||||
|
// Decreated single users are stored as stringified arrays of a single value
|
||||||
|
return JSON.stringify([processString(filterValue)])
|
||||||
|
}
|
||||||
|
|
||||||
if (isArray) {
|
if (isArray) {
|
||||||
return filterValue.map(el => {
|
return filterValue.map(el => {
|
||||||
if (typeof el === "string") {
|
if (typeof el === "string") {
|
||||||
|
@ -80,7 +92,11 @@ function userColumnMapping(column: string, options: RowSearchParams) {
|
||||||
|
|
||||||
// maps through the search parameters to check if any of the inputs are invalid
|
// maps through the search parameters to check if any of the inputs are invalid
|
||||||
// based on the table schema, converts them to something that is valid.
|
// based on the table schema, converts them to something that is valid.
|
||||||
export function searchInputMapping(table: Table, options: RowSearchParams) {
|
export function searchInputMapping(
|
||||||
|
table: Table,
|
||||||
|
options: RowSearchParams,
|
||||||
|
datasourceOptions: { isSql?: boolean }
|
||||||
|
) {
|
||||||
if (!table?.schema) {
|
if (!table?.schema) {
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
@ -99,7 +115,12 @@ export function searchInputMapping(table: Table, options: RowSearchParams) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case FieldType.BB_REFERENCE: {
|
case FieldType.BB_REFERENCE: {
|
||||||
userColumnMapping(key, options)
|
userColumnMapping(
|
||||||
|
key,
|
||||||
|
options,
|
||||||
|
helpers.schema.isDeprecatedSingleUserColumn(column),
|
||||||
|
datasourceOptions.isSql
|
||||||
|
)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue