Skip to content

postgrelize / Scopes

Function: Scopes() ​

Scopes(scopes): ModelClassDecorator

Defined in: src/decorators/table-decorators.ts:52

Defines the named scopes of a model (scopes of Model.init).

Parameters ​

scopes ​

Readonly<Record<string, ScopeDefinition>> | (() => ScopesInput)

Scopes by name (options or functions returning options), or a function returning them.

Returns ​

ModelClassDecorator

A class decorator.

Example ​

ts
@Scopes({ recent: { order: [['createdAt', 'DESC']] }, named: (name: string) => ({ where: { name } }) })
class User extends Model {}

Released under the MIT License.