diff --git a/docs/pages/packages/utils/Queries.mdx b/docs/pages/packages/utils/Queries.mdx index 8e02a99..24a717c 100644 --- a/docs/pages/packages/utils/Queries.mdx +++ b/docs/pages/packages/utils/Queries.mdx @@ -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 diff --git a/packages/utils/src/queries/filter.ts b/packages/utils/src/queries/filter.ts index faecd15..9ad63e9 100644 --- a/packages/utils/src/queries/filter.ts +++ b/packages/utils/src/queries/filter.ts @@ -10,6 +10,7 @@ import { LteFilter, NeqFilter, NinFilter, + IsNullFilter, Value, } from '../types/filter'; import { ZERO_ADDRESS, DEAD_ADDRESS } from '../constants'; @@ -146,3 +147,10 @@ export function createBetweenFilter( ) : {}; } + +export function createIsNullFilter( + key: string, + value: boolean, +): FieldFilter { + return createField(key, { _is_null: value }); +} diff --git a/packages/utils/src/types/filter.ts b/packages/utils/src/types/filter.ts index 4023a3b..c03bd90 100644 --- a/packages/utils/src/types/filter.ts +++ b/packages/utils/src/types/filter.ts @@ -36,6 +36,10 @@ export interface LteFilter { _lte: V; } +export interface IsNullFilter { + _is_null: boolean; +} + export type AnyFilter = Partial & Partial & Partial & @@ -44,7 +48,8 @@ export type AnyFilter = Partial & Partial & Partial & Partial & - Partial; + Partial & + Partial; export type FieldFilter = { [key: string]: FieldFilter | F;