sequelize-tokens
v0.0.2
Published
Sequelize plugin for managing tokens attached to any model
Downloads
7
Maintainers
Readme
Tokens Sequelize plugin
This plugin allows to quickly attach tokens to any Sequelize model
Install
npm install sequelize-tokens
and then attach the plugin:
require('sequelize-tokens')(Sequelize);
Usage
Declare token in model definition options:
sequelize.define('Model', attributes, {
// ... other options
useTokens: { typeA: true, typeB: true }
});
Such a definition gives to Model and each its instances the following superpowers:
associations
typeAToken
,typeBToken
This allows to fetch the token (of any type) along with fething the entity itself:
Model.find({include: [{ association: Model.associations.typeAToken }]});
instance methods
instance.createTypeAToken()
,instance.getTypeAToken()
andinstance.setTypeAToken({...})