Skip to Content

WhereClause

Filter operators accepted by ObjectSet.where and the where option of @osdk/react hooks, by property type.

import type { WhereClause } from "@osdk/client";

type WhereClause<
  T extends ObjectOrInterfaceDefinition,
  RDPs extends Record<string, SimplePropertyDef> = {},
> =
  | { $and: WhereClause<T, RDPs>[] }
  | { $or: WhereClause<T, RDPs>[] }
  | { $not: WhereClause<T, RDPs> }
  | { $title?: Filter; $primaryKey?: Filter }
  | { [property in PropertyKeys<T>]?: FilterFor<property> };

A where clause maps property names to filters. Properties in one clause combine with AND. A bare value, such as { department: "Engineering" }, is shorthand for $eq. Each filter object holds exactly one operator.

The type is a union of mapped and conditional types, so these tables are written by hand.

Logical operators

OperatorValueMatches
$andWhereClause[]Objects that match every clause.
$orWhereClause[]Objects that match at least one clause.
$notWhereClauseObjects that do not match the clause.

Operators by property type

Operatorstringnumberdate and timestampbooleanValue
$eq, $neYesYesYesYesA value of the property's type.
$inYesYesYesYesAn array of values. An empty array matches every object.
$isNullYesYesYesYestrue or false.
$gt, $gte, $lt, $lteYesYesYesA bound. Dates and timestamps take ISO 8601 strings.
$startsWithYesA prefix, or { term, phoneticSearch? }.
$containsAnyTermYesA string, { term, fuzzySearch? }, or { term, phoneticSearch? }. Matches any whitespace-separated term.
$containsAllTermsYesA string, { term, fuzzySearch? }, or { term, phoneticSearch? }. Matches every term, in any order.
$containsAllTermsInOrderYesA string, or { term, phoneticSearch? }. Matches the terms in order.
$intervalYesAn IntervalRule.
$matchesRegexYesBeta. A regular expression in Foundry search syntax.

Number filters apply to integer, long, double, float, decimal, and byte properties.

Array properties

OperatorValueMatches
$containsAn element valueArrays that contain the value.
$isNullbooleanArrays that are null, or not null.

Geo properties

geopoint and geoshape properties take $within, $intersects, and $isNull.

OperatorValue
$within{ $distance: [number, unit], $of: [lon, lat] | Point }, { $bbox: BBox }, a BBox, { $polygon: coordinates }, or a GeoJSON Polygon.
$intersects{ $bbox: BBox }, a BBox, { $polygon: coordinates }, or a GeoJSON Polygon.

The distance unit is one of "cm", "m", "km", "inches", "feet", "yards", "miles", or "nautical miles", or a singular or long form such as "meter" or "kilometers".

Struct properties

Filter one field of a struct property by nesting it: { address: { city: { $eq: "Denver" } } }. A struct filter holds exactly one field.

Example

src/seniorEngineers.ts
import { Employee } from "@my-app/sdk";
import type { Client, WhereClause } from "@osdk/client";

const seniorEngineers: WhereClause<Employee> = {
  $and: [
    { department: "Engineering" },
    { startDate: { $lt: "2020-01-01" } },
    { $or: [{ jobTitle: { $startsWith: "Senior" } }, { skills: { $contains: "Go" } }] },
    { $not: { salary: { $isNull: true } } },
  ],
};

export function loadSeniorEngineers(client: Client) {
  return client(Employee).where(seniorEngineers).fetchPage({ $pageSize: 50 });
}

See also

On this page