@gopato/sequelize-transforms1.0.1 • Public • Published
Sequelize plugin to add configurable attribute transforms. It allows you to
define transform functions (aka filters) to run on attribute values when an instance is updated (through assignment,
create etc.). The transform functions can be enabled and configured on attribute level.
npm install sequelize-transforms
To activate the plugin for all your models, call the plugin on your
var sequelizeTransforms = ;;
To activate the plugin on specific models, call the plugin on the models:
var sequelizeTransforms = ;var Model = sequelize;;
To use transforms for an attribute, just add them to its definition:
var Model = sequelize;
With this configuration, the
The plugin comes with the following predefined transforms:
trim: trim value
lowercase: transform value to all lower case
uppercase: transform value to all upper case
It is possible to override predefined transforms or add your own by passing an object as the second argument:
This would override the
trim transform and add a new one called
append. Every transform function is called with
two parameters: the value to transform and the definition of the attribute being transformed.
- If more than one transform is defined on an attribute, then the order in which they are executed is unpredictable.
This is generally not an issue as you should not use mutually exclusive transforms together, e.g.
- If an attribute is updated with the
rawoption set to
true, then the transforms will not be run.