For the complete documentation index, see llms.txt. This page is also available as Markdown.

Using RepositoryQuery

A RepositoryQuery is a named, reusable query object. Extend it, build a query in build(), and pass it to the repository's find(). This decouples query construction from call sites and turns complex/reused queries into first-class, testable units.

import { RepositoryQuery, FindParams, Where } from '@soapjs/soap';

export class ThreatsQuery extends RepositoryQuery<FindParams> {
  constructor(private readonly universe?: string) { super(); }

  build(): FindParams {
    const where = new Where()
      .brackets(w => w.valueOf('alignment').isEq('villain').or.valueOf('alignment').isEq('anti-hero'));
    if (this.universe) where.and.valueOf('universe').isEq(this.universe);
    return FindParams.create({ where, sort: { name: 1 } });
  }
}
const result = await repo.find(new ThreatsQuery('dc'));

build() returns portable FindParams (a Where + paging/sort) — no database syntax — so the same query object works across storages. For queries this can't express, see Using Native Queries.

Note: this class was called QueryBuilder in older versions; the current name is RepositoryQuery.

Last updated