postgrelize / FindOptions
Type Alias: FindOptions<T> ​
FindOptions<
T> =QueryOptionsBase&Omit<SelectOptions,"where"> &object&CteFindOptions
Defined in: src/model/find-options.ts:47
Options of the finders (findAll, findOne, findByPk, ...), without association loading details.
Extends the query options (transaction, logging, ...) and the SELECT options with finder flags and the PostgreSQL CTE extension. include is typed through IncludeOption. A beforeFind hook may change these options before the query runs.
Type Parameters ​
T ​
T = Values
Type Declaration ​
hooks? ​
optionalhooks?:boolean
Run beforeFind / afterFind hooks.
Default Value ​
trueinclude? ​
optionalinclude?:IncludeOption
Eager-load associations through JOINs (or separate queries for separate includes).
nest? ​
optionalnest?:boolean
With raw, build nested objects from dotted keys such as 'posts.title'.
Default Value ​
falseparanoid? ​
optionalparanoid?:boolean
For paranoid models: false includes soft-deleted rows.
Default Value ​
trueplain? ​
optionalplain?:boolean
Return a single row instead of an array (set internally by findOne).
Default Value ​
falseraw? ​
optionalraw?:boolean
Return plain row objects instead of model instances.
Default Value ​
falserejectOnEmpty? ​
optionalrejectOnEmpty?:boolean|Error
Throw EmptyResultError (or the given Error) when no row is found.
Default Value ​
falsesubQuery? ​
optionalsubQuery?:boolean
false disables the sub-query used for limit combined with multi-row includes.
tableAs? ​
optionaltableAs?:string
Alias of the main table in FROM instead of the model name, so literals and col('alias.x') can refer to it (a v6 internal option that v6's typings omit). Ignored when include is set.
where? ​
optionalwhere?:WhereOptions<T>
Filter rows; see WhereOptions. All rows when omitted.
See ​
Example ​
const opts: FindOptions<User> = {
where: { active: true, age: { [Op.gte]: 18 } },
attributes: ['id', 'name'],
order: [['name', 'ASC']],
limit: 10,
include: [Post],
};
const rows = await User.findAll(opts);