Skip to main content

Repository.FindManyOptions

The options object accepted by Repository.findMany(). See Repositories for the full guide (filters, projection, associations).

namespace Repository {
interface FindManyOptions extends FindOneOptions {
limit?: number;
distinct?: boolean;
maxEagerFetch?: number;
maxSubQueries?: number;
onTransformRow?: TransformRowFunction;
}

type TransformRowFunction = (
fields: FieldInfoMap,
row: object,
obj: object,
) => void;
}

FindManyOptions extends FindOneOptions, which extends FindOptions, which extends CommandOptions plus projection/filter/params — see the Repository.CommandOptions table for the full chain.

OptionTypeDescription
projectionstring | string[]Fields to include/exclude. See Repositories → Projection. Passing a projection narrows the resolved type from T to PartialDTO<T>.
filterLogicalOperator | LogicalOperator[] | object | object[]See Repositories → Filters.
paramsanyNamed-parameter values referenced from filter via Param('name').
sortstring[]Column or dotted-path names to sort by; prefix with - for descending (default ascending, + also accepted). Sorting through a to-many association is rejected (Can not sort by "...", since there's no single row to order against).
offsetnumberRow offset.
limitnumberMax rows to return.
distinctbooleanAdds DISTINCT to the generated SELECT.
maxEagerFetchnumberCaps how many related rows a to-many association's eager sub-query may return in total across the whole result set before throwing (Number of returning rows for "..." exceeds maxEagerFetch limit). Defaults to 100000.
maxSubQueriesnumberCaps how many levels deep chained to-many associations are allowed to eagerly resolve before @sqb/connect stops adding more sub-queries. Defaults to 5.
onTransformRowTransformRowFunction(fields, row, obj) => void — called once per raw row during conversion, letting you inspect/mutate the raw row alongside the object being built.

Every CommandOptions field (connection, prettyPrint, comment, optimizerHint) is also accepted, since FindManyOptions ultimately extends it.

const customers = await repo.findMany({
filter: { active: true },
projection: ['id', 'givenName', 'country'],
sort: ['givenName'],
limit: 20,
offset: 40,
distinct: true,
});

Repository.FindOneOptions (the same shape minus limit/distinct/maxEagerFetch/ maxSubQueries/onTransformRow) backs findOne()/findById() instead, and does not have its own page — see the table on the CommandOptions page for its exact shape.