Decorator's
@Schema
@Schema
The @Schema
program processes the schema and makes it ready for saving to the table, it is mandatory* to use it when creating a model.
@Timestamps
The @Timestamps
decorator automatically adds createdAt
and updatedAt
columns to the model. These columns store the creation and last update timestamps, with the updatedAt
column being automatically updated on every change. Using @Timestamps
is optional and can be included as needed to simplify timestamp management in your models.
@Paranoid
The @Paranoid
decorator enables soft deletion for the model by adding a deletedAt
column. Instead of permanently removing a record, it sets a timestamp in the deletedAt
column when the record is deleted. This allows the data to be retained and queried if needed. Using @Paranoid
is optional and can be implemented when soft delete functionality is required.
@Force
The @Force
option in sync is used to drop and recreate the table in the database. When @Force
is set to true, it completely removes the existing table, including all its data, and creates a new table based on the current model definition. This is useful for development purposes to quickly apply model changes, but it should be used with caution in production environments as it results in data loss.
@Debug
The @Debug
decorator logs all operations performed on the schema where it is used. It provides detailed information about actions such as creation, updates, deletions, and queries, making it easier to debug and monitor database interactions. Using @Debug
is optional and can be enabled when you need better insight into schema-level operations.
@Provider
(
providerName:
string
)
The @Provider
decorator specifies which model the schema will be associated with, particularly in scenarios involving multiple connections or databases. It should be placed above the class structure and below other schema decorators. By default, the @Provider
decorator uses 'nexorm'
as the default connection. This makes it easier to manage and organize schemas across various database setups when working with multiple data sources.
For Example
Last updated