AfterCreateCommit decorator
class User {
@deco.AfterCreateCommit()
public doSomething() {
console.log('hi!')
}
}
Optionalopts: AfterHookOpts<T>The AfterCreateCommit decorator
AfterDestroy decorator
class User {
@deco.AfterDestroy()
public doSomething() {
console.log('hi!')
}
}
The AfterDestroy decorator
AfterDestroyCommit decorator
class User {
@deco.AfterDestroyCommit()
public doSomething() {
console.log('hi!')
}
}
The AfterDestroyCommit decorator
AfterSave decorator
class User {
@deco.AfterSave()
public doSomething() {
console.log('hi!')
}
}
Optionalopts: AfterHookOpts<T>The AfterSave decorator
AfterSaveCommit decorator
class User {
@deco.AfterSaveCommit()
public doSomething() {
console.log('hi!')
}
}
Optionalopts: AfterHookOpts<T>The AfterSaveCommit decorator
AfterUpdate decorator
class User {
@deco.AfterUpdate()
public doSomething() {
console.log('hi!')
}
}
Optionalopts: AfterHookOpts<T>The AfterUpdate decorator
AfterUpdateCommit decorator
class User {
@deco.AfterUpdateCommit()
public doSomething() {
console.log('hi!')
}
}
Optionalopts: AfterHookOpts<T>The AfterUpdateCommit decorator
BeforeCreate decorator
class User {
@deco.BeforeCreate()
public doSomething() {
console.log('hi!')
}
}
Optionalopts: BeforeHookOpts<T>The BeforeCreate decorator
BeforeDestroy decorator
class User {
@deco.BeforeDestroy()
public doSomething() {
console.log('hi!')
}
}
The BeforeDestroy decorator
BeforeSave decorator
class User {
@deco.BeforeSave()
public doSomething() {
console.log('hi!')
}
}
Optionalopts: BeforeHookOpts<T>The BeforeSave decorator
BeforeUpdate decorator
class User {
@deco.BeforeUpdate()
public doSomething() {
console.log('hi!')
}
}
Optionalopts: BeforeHookOpts<T>The BeforeUpdate decorator
Optionaloptions: NonPolymorphicBelongsToOptions<Optionaloptions: PolymorphicBelongsToOptions<The Encrypted decorator automatically encrypts (upon setting) and decrypts (upon getting) so that the encrypted value is stored in the database.
class User {
@deco.Encrypted()
// automatically sets `encryptedSsn` to the encrypted value that
// `ssn` is set to in new/create/update, e.g., `await user.update({ ssn })`
public ssn: string
// automatically sets `myEncryptedPhone` to the encrypted value that
// `phone` is set to new/create/update, e.g., `await user.update({ phone })`
@deco.Encrypted('myEncryptedPhone)
public phone: string
}
Optionalcolumn: keyof T["DB"][T["table"] & keyof T["DB"]] & string— if omitted, then 'encrypted' is prepended to the Pascal cased version of the decorated field
An Encrypted decorator
Optionaloptions: HasManyOptions<T, AssociationGlobalName, ThroughAssociationName>Optionaloptions: HasManyThroughOptions<T, AssociationGlobalName, ThroughAssociationName>Optionaloptions: PolymorphicHasManyOptions<T, AssociationGlobalName, ThroughAssociationName>Optionaloptions: HasOneOptions<T, AssociationGlobalName, ThroughAssociationName>Optionaloptions: HasOneThroughOptions<T, AssociationGlobalName, ThroughAssociationName>Optionaloptions: PolymorphicHasOneOptions<T, AssociationGlobalName, ThroughAssociationName>The Scope decorator decorates a static method that accepts and returns a Dream Query.
class Collar {
@deco.Scope({ default: true })
public static hideHiddenCollars(query: Query<Collar>) {
return query.where({ hidden: false })
}
}
— optional options
Optionaldefault?: booleanIf true, this scope will be applied automatically to all queries involving this model.
Defaults to false.
A Scope decorator
The Sortable decorator automatically adjusts the value of the columns corresponding to the decorated field.
NOTE: the Sortable decorator may not be used in STI child models (it may be used in the STI base class)
class Balloon {
@deco.Sortable({ scope: 'user' })
public position: DreamColumn<Balloon, 'position'>
}
Optionalopts: SortableOptions<T>Configuration options for the sortable decorator
The column, association, or combination thereof which you would like to restrict the incrementing logic to. Can be a single column name, a single belongs-to association name, or an array of column/association names
A Sortable decorator
The Validate decorator decorates a method to run before saving a model to the database.
class Sandbag {
@deco.Validate()
public validateWeight(this: Sandbag) {
if (!this.weight) return
const undefinedOrNull: any[] = [undefined, null]
if (!undefinedOrNull.includes(this.weightKgs))
this.addError('weight', 'cannot include weightKgs AND weight')
if (!undefinedOrNull.includes(this.weightTons))
this.addError('weight', 'cannot include weightTons AND weight')
}
}
A Validate decorator
The Validates decorator decorates a field to validate according to the specified validator and options.
class Balloon {
@deco.Validates('numericality', { min: 0, max: 100 })
public volume: DreamColumn<Balloon, 'volume'>
}
— the type of validation
Optionalargs: VTArgs— optional arguments specific to the type of validation
A Validates decorator
The Virtual decorator enables setting of fields as if they corresponded to columns in the model's table so they can be passed to new, create, and update.
For example, in the first example, below, one could call
await bodyMeasurement.update({ lbs 180.1 }), and 180.1 will be
passed into the lbs setter, which then translates lbs
to grams to be stored in the grams column in the metrics
table.
And in the second example, below, one could call
await user.update({ password }), and, in the BeforeSave
lifecycle hook, the password would be hashed into
hashedPassword. (This is just an example to illustrate
using the Virtual decorator on a simple field; it might be
better design to use the getter/setter pattern for password,
with the getter simply returning undefined.)
class BodyMeasurement {
@deco.Virtual('number')
public get lbs() {
const self: User = this
return gramsToLbs(self.getAttribute('grams') ?? 0)
}
public set lbs(lbs: number) {
const self: User = this
self.setAttribute('grams', lbsToGrams(lbs))
}
@deco.Virtual('number')
public get kilograms() {
const self: User = this
return gramsToKilograms(self.getAttribute('grams') ?? 0)
}
public set kilograms(kg: number) {
const self: User = this
self.setAttribute('grams', kilogramsToGrams(kg))
}
}
class User {
@deco.Virtual('string')
public password: string
@deco.BeforeSave()
public hasPassword() {
this.setAttribute('hashedPassword', preferredHashingAlgorithm(this.password))
}
}
Required. The OpenAPI shape that defines both the serializer OpenAPI shape and request body OpenAPI shape (in Psychic)
A Virtual decorator
AfterCreate decorator