Skip to content

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? ​

optional hooks?: boolean

Run beforeFind / afterFind hooks.

Default Value ​

ts
true

include? ​

optional include?: IncludeOption

Eager-load associations through JOINs (or separate queries for separate includes).

nest? ​

optional nest?: boolean

With raw, build nested objects from dotted keys such as 'posts.title'.

Default Value ​

ts
false

paranoid? ​

optional paranoid?: boolean

For paranoid models: false includes soft-deleted rows.

Default Value ​

ts
true

plain? ​

optional plain?: boolean

Return a single row instead of an array (set internally by findOne).

Default Value ​

ts
false

raw? ​

optional raw?: boolean

Return plain row objects instead of model instances.

Default Value ​

ts
false

rejectOnEmpty? ​

optional rejectOnEmpty?: boolean | Error

Throw EmptyResultError (or the given Error) when no row is found.

Default Value ​

ts
false

subQuery? ​

optional subQuery?: boolean

false disables the sub-query used for limit combined with multi-row includes.

tableAs? ​

optional tableAs?: 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? ​

optional where?: WhereOptions<T>

Filter rows; see WhereOptions. All rows when omitted.

See ​

Example ​

ts
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);

Released under the MIT License.