MySQL has all of
This commit is contained in:
parent
76e4ffc04d
commit
a85ad2ced6
|
@ -229,28 +229,28 @@ class InternalBuilder {
|
||||||
if (filters.contains) {
|
if (filters.contains) {
|
||||||
const fnc = allOr ? "orWhere" : "where"
|
const fnc = allOr ? "orWhere" : "where"
|
||||||
const rawFnc = `${fnc}Raw`
|
const rawFnc = `${fnc}Raw`
|
||||||
|
function stringifyArray(value: Array<any>): string {
|
||||||
|
for (let i in value) {
|
||||||
|
if (typeof value[i] === "string") {
|
||||||
|
value[i] = `"${value[i]}"`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return `'[${value.join(",")}]'`
|
||||||
|
}
|
||||||
if (this.client === SqlClients.POSTGRES) {
|
if (this.client === SqlClients.POSTGRES) {
|
||||||
iterate(filters.contains, (key: string, value: Array<any>) => {
|
iterate(filters.contains, (key: string, value: Array<any>) => {
|
||||||
const fieldNames = key.split(/\./g)
|
const fieldNames = key.split(/\./g)
|
||||||
const tableName = fieldNames[0]
|
const tableName = fieldNames[0]
|
||||||
const columnName = fieldNames[1]
|
const columnName = fieldNames[1]
|
||||||
for (let i in value) {
|
|
||||||
if (typeof value[i] === "string") {
|
|
||||||
value[i] = `"${value[i]}"`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
query = query[rawFnc](
|
query = query[rawFnc](
|
||||||
`"${tableName}"."${columnName}"::jsonb @> '[${value.join(",")}]'`
|
`"${tableName}"."${columnName}"::jsonb @> ${stringifyArray(value)}`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
} else if (this.client === SqlClients.MY_SQL) {
|
} else if (this.client === SqlClients.MY_SQL) {
|
||||||
iterate(filters.contains, (key: string, value: any) => {
|
iterate(filters.contains, (key: string, value: Array<any>) => {
|
||||||
if (typeof value === "string") {
|
|
||||||
value = `"${value}"`
|
|
||||||
}
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
query = query[rawFnc](`JSON_CONTAINS(${key}, '${value}')`)
|
query = query[rawFnc](`JSON_CONTAINS(${key}, ${stringifyArray(value)})`)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
iterate(filters.contains, like)
|
iterate(filters.contains, like)
|
||||||
|
|
Loading…
Reference in New Issue