> For the complete documentation index, see [llms.txt](https://docs.soapjs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.soapjs.com/examples/database-interaction-strategies/using-repositoryquery.md).

# 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.

```typescript
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 } });
  }
}
```

```typescript
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`.
