Optional
returnType: DataTypeClassOrInstanceOptional
attributeDependencies: string[]array of attributes this virtual type is dependent on
Optional
options: VirtualOptionsPrivate
#dialectWhere this DataType is being used.
Protected
_checkOverride this method to emit an error or a warning if the Data Type, as it is configured, is not compatible with the current dialect.
The dialect using this data type.
Protected
_constructRest
...args: ConstructorParameters<Constructor>Protected
_getPrivate
attachPrivate
Escapes a value for the purposes of inlining it in a SQL query. The resulting value will be inlined as-is with no further escaping.
The value to escape.
This method is called when AbstractQueryGenerator needs to add a bind parameter to a query it is building. This method allows for customizing both the SQL to add to the query, and convert the bind parameter value to a DB-compatible value.
If you only need to prepare the bind param value, implement toBindableValue instead.
This method must return the SQL to add to the query. You can obtain a bind parameter ID by calling BindParamOptions#bindParam with the value associated to that bind parameter.
An example of a data type that requires customizing the SQL is the GEOMETRY data type.
The value to bind.
Options.
Called when a value is retrieved from the Database, and its DataType is specified. Used to normalize values from the database.
Note: It is also possible to do an initial parsing of a Database value using AbstractDialect#registerDataTypeParser. That normalization uses the type ID from the database instead of a Sequelize Data Type to determine which parser to use, and is called before this method.
The value to parse.
Used to normalize a value when Model#set is called. That is, when a user sets a value on a Model instance.
Returns this DataType, using its dialect-specific subclass.
Static
getStatic
to
A virtual value that is not stored in the DB. This could for example be useful if you want to provide a default value in your model that is returned to the user but not stored in the DB.
You could also use it to validate a value before permuting and storing it. VIRTUAL also takes a return type and dependency fields as arguments If a virtual attribute is present in
attributes
it will automatically pull in the extra fields as well. Return type is mostly useful for setups that rely on types like GraphQL.Example: Checking password length before hashing it
In the above code the password is stored plainly in the password field so it can be validated, but is never stored in the DB.
Example: Virtual with dependency fields