Skip to content

Commit

Permalink
feat: Add _is_null filter in query helpers (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
reobin authored Dec 19, 2024
1 parent 12c0f67 commit eeb2fb0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/pages/packages/utils/Queries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The possible filters to create are:
- `createInFilter`: if the field is contained in any of the given values.
- `createNinFilter`: not contained in the given values.
- `createBetweenFilter`: from and to values, mostly used for dates.
- `createIsNullFilter`: to check if the field is null.

### Use of DOT notation

Expand Down
8 changes: 8 additions & 0 deletions packages/utils/src/queries/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
LteFilter,
NeqFilter,
NinFilter,
IsNullFilter,
Value,
} from '../types/filter';
import { ZERO_ADDRESS, DEAD_ADDRESS } from '../constants';
Expand Down Expand Up @@ -146,3 +147,10 @@ export function createBetweenFilter<V = Value>(
)
: {};
}

export function createIsNullFilter(
key: string,
value: boolean,
): FieldFilter<IsNullFilter> {
return createField<IsNullFilter>(key, { _is_null: value });
}
7 changes: 6 additions & 1 deletion packages/utils/src/types/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export interface LteFilter<V = Value> {
_lte: V;
}

export interface IsNullFilter {
_is_null: boolean;
}

export type AnyFilter = Partial<EqFilter> &
Partial<NeqFilter> &
Partial<LikeFilter> &
Expand All @@ -44,7 +48,8 @@ export type AnyFilter = Partial<EqFilter> &
Partial<GtFilter> &
Partial<GteFilter> &
Partial<LtFilter> &
Partial<LteFilter>;
Partial<LteFilter> &
Partial<IsNullFilter>;

export type FieldFilter<F = AnyFilter> = {
[key: string]: FieldFilter<F> | F;
Expand Down

0 comments on commit eeb2fb0

Please sign in to comment.