Methods
# column(columnName) → {function}
Decorator that maps a model property to a specific column name in the database
Specifies the database column name for a model property
Parameters:
Name | Type | Description |
---|---|---|
columnName |
string
|
The name of the column in the database |
A decorator function that can be applied to a class property
function
# createdBy() → {function}
Decorator that marks a property to store the identifier of the user who created the model instance
Tracks the creator of a model instance
A decorator function that can be applied to a class property
function
Example
```typescript
class Document extends BaseModel {
# final() → {function}
This decorator prevents a method from being overridden by making it non-configurable. It throws an error if used on anything other than a method.
Creates a decorator that makes a method non-configurable
A decorator function that can be applied to methods
function
# index(directionsopt, compositionsopt) → {function}
Decorator that marks a property to be indexed in the database, optionally with specific directions and compositions
Creates an index on a model property for improved query performance
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
directions |
Array.<OrderDirection>
|
<optional> |
Optional array of sort directions for the index |
compositions |
Array.<string>
|
<optional> |
Optional array of property names to create a composite index |
A decorator function that can be applied to a class property
function
# manyToOne(clazz, cascadeOptionsopt, populateopt) → {function}
Decorator that establishes a many-to-one relationship between multiple instances of the current model and another model
Defines a many-to-one relationship between models
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
clazz |
Constructor.<M>
|
The constructor of the related model class |
||
cascadeOptions |
CascadeMetadata
|
<optional> |
DefaultCascade | Options for cascading operations (create, update, delete) |
populate |
boolean
|
<optional> |
true | If true, automatically populates the relationship when the model is retrieved |
A decorator function that can be applied to a class property
function
Example
```typescript
class Book extends BaseModel {
# oneToMany(clazz, cascadeOptionsopt, populateopt) → {function}
Decorator that establishes a one-to-many relationship between the current model and multiple instances of another model
Defines a one-to-many relationship between models
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
clazz |
Constructor.<M>
|
The constructor of the related model class |
||
cascadeOptions |
CascadeMetadata
|
<optional> |
DefaultCascade | Options for cascading operations (create, update, delete) |
populate |
boolean
|
<optional> |
true | If true, automatically populates the relationship when the model is retrieved |
A decorator function that can be applied to a class property
function
Example
```typescript
class Author extends BaseModel {
# oneToOne(clazz, cascadeOptionsopt, populateopt) → {function}
Decorator that establishes a one-to-one relationship between the current model and another model
Defines a one-to-one relationship between models
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
clazz |
Constructor.<M>
|
The constructor of the related model class |
||
cascadeOptions |
CascadeMetadata
|
<optional> |
DefaultCascade | Options for cascading operations (create, update, delete) |
populate |
boolean
|
<optional> |
true | If true, automatically populates the relationship when the model is retrieved |
A decorator function that can be applied to a class property
function
Example
```typescript
class User extends BaseModel {
# pk(opts) → {PropertyDecorator}
Marks a property as the model's primary key with automatic sequence generation This decorator combines multiple behaviors: it marks the property as unique, required, and ensures the index is created properly according to the provided sequence options.
Primary Key Decorator
Parameters:
Name | Type | Description |
---|---|---|
opts |
Omit.<SequenceOptions, ("cycle"|"startWith"|"incrementBy")>
|
Options for the sequence generation |
A property decorator that can be applied to model properties
PropertyDecorator
Example
```typescript
class User extends BaseModel {
# pkOnCreate(context, data, key, model) → {Promise.<void>}
Handles the creation of primary key values for models using sequences
Callback function for primary key creation
Parameters:
Name | Type | Description |
---|---|---|
context |
Context.<F>
|
The execution context |
data |
V
|
The sequence options |
key |
The property key to set as primary key |
|
model |
M
|
The model instance |
A promise that resolves when the primary key is set
Promise.<void>
# repository(model, nameOverrideopt) → {any}
Creates and registers a repository for a model class. Can be used as both a property decorator and a class decorator.
Repository decorator for model classes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
model |
Constructor.<T>
|
The constructor of the model class. |
|
nameOverride |
string
|
<optional> |
Optional name override for the repository. |
- The decorator function.
any
# table(tableName) → {function}
Decorator that sets the table name for a model class in the database
Specifies the database table name for a model
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string
|
The name of the table in the database |
A decorator function that can be applied to a class
function
# unique() → {function}
Decorator that ensures a property value is unique across all instances of a model in the database
Tags a property as unique
A decorator function that can be applied to a class property
function
Example
```typescript
class User extends BaseModel {
# updatedBy() → {function}
Decorator that marks a property to store the identifier of the user who last updated the model instance
Tracks the last updater of a model instance
A decorator function that can be applied to a class property
function
Example
```typescript
class Document extends BaseModel {
# uses(flavour) → {function}
This decorator applies metadata to a model class to indicate which persistence adapter flavor should be used when performing database operations on instances of the model. The flavor is a string identifier that corresponds to a registered adapter configuration.
Specifies which persistence adapter flavor a model should use
Parameters:
Name | Type | Description |
---|---|---|
flavour |
string
|
The identifier of the adapter flavor to use |
A decorator function that can be applied to a model class
function