Adding test case and updating how prefix updates in filters work.
This commit is contained in:
parent
2d31e327e7
commit
510baf4f6e
|
@ -2108,4 +2108,26 @@ describe.each([
|
||||||
}).toNotHaveProperty(["totalRows"])
|
}).toNotHaveProperty(["totalRows"])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("special data_ case", () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
table = await createTable({
|
||||||
|
name_data_test: {
|
||||||
|
name: "name_data_test",
|
||||||
|
type: FieldType.STRING,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await createRows([{ name_data_test: "a" }, { name_data_test: "b" }])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should be able to query a column with data_ in it", async () => {
|
||||||
|
await expectSearch({
|
||||||
|
query: {
|
||||||
|
equal: {
|
||||||
|
["1:name_data_test"]: "a",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).toContainExactly([{ name_data_test: "a" }])
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,6 +36,7 @@ import {
|
||||||
getRelationshipColumns,
|
getRelationshipColumns,
|
||||||
getTableIDList,
|
getTableIDList,
|
||||||
} from "./filters"
|
} from "./filters"
|
||||||
|
import { dataFilters } from "@budibase/shared-core"
|
||||||
|
|
||||||
const builder = new sql.Sql(SqlClient.SQL_LITE)
|
const builder = new sql.Sql(SqlClient.SQL_LITE)
|
||||||
const NO_SUCH_COLUMN_REGEX = new RegExp(`no such colum.+${USER_COLUMN_PREFIX}`)
|
const NO_SUCH_COLUMN_REGEX = new RegExp(`no such colum.+${USER_COLUMN_PREFIX}`)
|
||||||
|
@ -101,19 +102,14 @@ function cleanupFilters(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
// sort longest first, don't find substrings
|
|
||||||
const userColumnList = Object.keys(userColumnMap).sort(
|
|
||||||
(a, b) => b.length - a.length
|
|
||||||
)
|
|
||||||
// update the keys of filters to manage user columns
|
// update the keys of filters to manage user columns
|
||||||
for (let filter of Object.values(filters)) {
|
const keyInAnyTable = (key: string): boolean =>
|
||||||
for (let key of Object.keys(filter)) {
|
allTables.some(table => table.schema[key])
|
||||||
const found = userColumnList.find(possibleColumn =>
|
for (const filter of Object.values(filters)) {
|
||||||
key.endsWith(possibleColumn)
|
for (const key of Object.keys(filter)) {
|
||||||
)
|
const { prefix, key: rawKey } = dataFilters.getKeyNumbering(key)
|
||||||
if (found) {
|
if (keyInAnyTable(rawKey)) {
|
||||||
const newKey = key.replace(found, userColumnMap[found])
|
filter[`${prefix || ""}${mapToUserColumn(rawKey)}`] = filter[key]
|
||||||
filter[newKey] = filter[key]
|
|
||||||
delete filter[key]
|
delete filter[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,13 +131,22 @@ const cleanupQuery = (query: SearchFilters) => {
|
||||||
* Removes a numeric prefix on field names designed to give fields uniqueness
|
* Removes a numeric prefix on field names designed to give fields uniqueness
|
||||||
*/
|
*/
|
||||||
export const removeKeyNumbering = (key: string): string => {
|
export const removeKeyNumbering = (key: string): string => {
|
||||||
|
return getKeyNumbering(key).key
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the part of the keys, returning the numeric prefix and the field name
|
||||||
|
*/
|
||||||
|
export const getKeyNumbering = (
|
||||||
|
key: string
|
||||||
|
): { prefix?: string; key: string } => {
|
||||||
if (typeof key === "string" && key.match(/\d[0-9]*:/g) != null) {
|
if (typeof key === "string" && key.match(/\d[0-9]*:/g) != null) {
|
||||||
const parts = key.split(":")
|
const parts = key.split(":")
|
||||||
// remove the number
|
// remove the number
|
||||||
parts.shift()
|
const number = parts.shift()
|
||||||
return parts.join(":")
|
return { prefix: `${number}:`, key: parts.join(":") }
|
||||||
} else {
|
} else {
|
||||||
return key
|
return { key }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue