Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add _is_null filter in query helpers #154

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading