Skip to content

Commit 706fd78

Browse files
committed
Create sub filter builder
1 parent 809537a commit 706fd78

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/core/database/query/filters.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,24 @@ export const comparisonOfDateTimeFilter = (
193193
? (...args) => comparators.map((comp) => comp(...args)).join(' AND ')
194194
: undefined;
195195
};
196+
197+
export const sub =
198+
<Input extends Record<string, any>>(
199+
subBuilder: () => (input: Partial<Input>) => (q: Query) => void,
200+
) =>
201+
<
202+
// TODO this doesn't enforce Input type on Outer property
203+
K extends string,
204+
Outer extends Partial<Record<K, Partial<Input>>>,
205+
>(
206+
matchSubNode: (sub: Query) => Query,
207+
): Builder<Outer, K> =>
208+
({ key, value, query }) =>
209+
query
210+
.subQuery('node', (sub) =>
211+
sub
212+
.apply(matchSubNode)
213+
.apply(subBuilder()(value))
214+
.return(`true as ${key}FiltersApplied`),
215+
)
216+
.with('*');

0 commit comments

Comments
 (0)