Build

Querying options and filters

Master paging, filtering, sorting, and projection for generated service queries.

findMany combines filtering, projection, relation loading, sorting, and bounded pagination. Keep API-level limits explicit so callers cannot request an unbounded result set.

Find options

interface FindOptions {
  select?: string[];
  where?: WhereClause;
  orderBy?: Array<{
    column: string;
    direction?: "ASC" | "DESC";
    nulls?: "NULLS FIRST" | "NULLS LAST";
  }>;
  skip?: number;
  take?: number; // capped by the generated MAX_PAGE_SIZE
  include?: string[];
  withDeleted?: boolean;
}
const admins = await users.users.findMany({
  where: { role: "admin", createdAt: { gte: since } },
  orderBy: [{ column: "createdAt", direction: "DESC" }],
  select: ["id", "email"],
  take: 50,
});

Operator map

A where value is either a direct value (equals) or an operator object.

OperatorMeaning
eq / neqequals / not equals
gt / gte / lt / ltecomparisons
like / ilikestring pattern matches
in / notInvalue set checks
isNull / isNotNullnull checks
betweeninclusive range
await posts.posts.findMany({
  where: {
    title: { ilike: "%damat%" },
    status: { in: ["published", "featured"] },
    deletedBy: { isNull: true },
  },
});

If your API needs nested or cross-model filters, review generated model scopes in @damatjs/orm docs after confirming base where operators here.