pg-mem
pg-mem copied to clipboard
jsonb '?|' operator
I noticed that ?|
operator is missing and we use it in one query.
so I'm trying to implement it and came up with this
db.public.registerOperator({
operator: '?|',
left: DataType.jsonb,
right: DataType.text,
returns: DataType.bool,
implementation: (a, b) => {
if (Array.isArray(a)) {
return a.some((key) => b.includes(key));
}
if (typeof a === 'object') {
return Object.keys(a).some((key) => b.includes(key));
}
throw new QueryError('cannot check scalar', '22023');
},
});
sadly (or maybe not) right side is supposed to be string[]
but I fail to do right: DataType.array
relevant part of query looks like this: data ?| ARRAY['5063098c-40fb-4375-94aa-b2c9ea14380d', '56062138-04df-4115-ad5e-80c5accbaff3']
how to make right side to work with string[]
type?
if you think this operator could land in pg-mem I'm happy to open PR.
Yes, exactly the same problem
I was experimenting with it a little
registerOperator
also accepts IType
as left and right operands, I was trying to construct one for text[]
with no luck