Skip to content

Commit a5f8406

Browse files
committed
Added _id column handling to use a regular column instead of jsonb nested query
1 parent a403146 commit a5f8406

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/packages/pongo/src/postgres/filter/queryOperators.ts

+29
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export const handleOperator = (
3232
operator: string,
3333
value: unknown,
3434
): string => {
35+
if (path === '_id') {
36+
return handleIdOperator(operator, value);
37+
}
38+
3539
switch (operator) {
3640
case '$eq':
3741
return format(
@@ -90,6 +94,31 @@ export const handleOperator = (
9094
}
9195
};
9296

97+
const handleIdOperator = (operator: string, value: unknown): string => {
98+
switch (operator) {
99+
case '$eq':
100+
return format(`_id = %L`, value);
101+
case '$gt':
102+
case '$gte':
103+
case '$lt':
104+
case '$lte':
105+
case '$ne':
106+
return format(`_id ${OperatorMap[operator]} %L`, value);
107+
case '$in':
108+
return format(
109+
`_id IN (%s)`,
110+
(value as unknown[]).map((v) => format('%L', v)).join(', '),
111+
);
112+
case '$nin':
113+
return format(
114+
`_id NOT IN (%s)`,
115+
(value as unknown[]).map((v) => format('%L', v)).join(', '),
116+
);
117+
default:
118+
throw new Error(`Unsupported operator: ${operator}`);
119+
}
120+
};
121+
93122
const buildNestedObject = (
94123
path: string,
95124
value: unknown,

0 commit comments

Comments
 (0)