BaseModel class
The class every model in an @imqueue service extends.
Signature:
export declare abstract class BaseModel<T> extends Model<BaseModel<T>>
Extends: Model<BaseModel<T>>
Remarks
Sequelize's own Model with four additions.
Views: a model declared with View or DynamicView is created and dropped as a view, skipped by the table sync, and has its numeric columns cast back to numbers after every finder, since a view returns them as strings.
Indices: ColumnIndex and NullableIndex declarations become CREATE INDEX statements at sync time, which plain sequelize cannot express.
Serialization: toJSON() honours the returning column list left behind by the last write, and picks up associated instances that the loaded attributes do not already cover.
Associations as a graph: toGraph() walks them transitively, so a cycle can be found before a query walks into it.
Example
@Table
export class Lead extends BaseModel<Lead> {
@PrimaryKey
@AutoIncrement
@Column(DataType.BIGINT)
public readonly id: number;
@AllowNull(false)
@Column(DataType.STRING)
public name: string;
@CreatedBy()
@Column(DataType.BIGINT)
public createdBy: number;
}
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
Attaches related data to this instance as though it had been joined in. | ||
|
|
Drops this model's relation: | |
|
|
Search for multiple instances. | |
|
|
Finds one instance by primary key. | |
|
|
Finds the first instance matching the options. | |
|
Casts this instance's numeric columns back to numbers. | ||
|
|
This view's SQL, with any dynamic parameters substituted in. | |
|
Forgets the | ||
|
|
Creates this model's table, or does nothing when the model is a view. | |
|
|
Builds and runs the statements that create one column index. | |
|
|
Creates every column index declared on this model. | |
|
|
Creates this view, replacing whatever definition is in the database. | |
|
|
Builds a graph of this model's associations, following them transitively. | |
|
Serializes this instance, honouring the |