QFIX: PG object query (#8283)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2025-03-20 00:34:22 +07:00 committed by GitHub
parent fdec5500b9
commit b715b584fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -726,7 +726,7 @@ abstract class PostgresAdapterBase implements DbAdapter {
})) as FindResult<T>
} catch (err) {
const sqlFull = vars.injectVars(fquery)
ctx.error('Error in findAll', { err, sql: fquery, sqlFull })
ctx.error('Error in findAll', { err, sql: fquery, sqlFull, query })
throw err
}
},
@ -1316,6 +1316,7 @@ abstract class PostgresAdapterBase implements DbAdapter {
} else if (typeof value === 'object' && !Array.isArray(value)) {
// we can have multiple criteria for one field
const res: string[] = []
const nonOperator: Record<string, any> = {}
for (const operator in value) {
let val = value[operator]
if (tkeyData && (Array.isArray(val) || (typeof val !== 'object' && typeof val !== 'string'))) {
@ -1402,10 +1403,14 @@ abstract class PostgresAdapterBase implements DbAdapter {
}
break
default:
res.push(`${tkey} @> '[${JSON.stringify(value)}]'`)
nonOperator[operator] = value[operator]
break
}
}
if (Object.keys(nonOperator).length > 0) {
const qkey = tkey.replace('#>>', '->').replace('{', '').replace('}', '')
res.push(`(${qkey} @> '${JSON.stringify(nonOperator)}' or ${qkey} @> '[${JSON.stringify(nonOperator)}]')`)
}
return res.length === 0 ? undefined : res.join(' AND ')
}