From b715b584fb21735a14971b0e30a8d9f23da493e6 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Thu, 20 Mar 2025 00:34:22 +0700 Subject: [PATCH] QFIX: PG object query (#8283) Signed-off-by: Andrey Sobolev --- server/postgres/src/storage.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/postgres/src/storage.ts b/server/postgres/src/storage.ts index 204bbd1a67..317b487ae3 100644 --- a/server/postgres/src/storage.ts +++ b/server/postgres/src/storage.ts @@ -726,7 +726,7 @@ abstract class PostgresAdapterBase implements DbAdapter { })) as FindResult } 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 = {} 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 ') }