1 const Sequelize = require('sequelize');
2 const Promise = require('bluebird');
3 const clsBluebird = require('cls-bluebird');
4 const cls = require('continuation-local-storage');
5
6 const ns = cls.createNamespace('transaction-namespace');
7 clsBluebird(ns, Promise);
8
9 Sequelize.useCLS(ns);
10
1const Model = sequelize.define('Model', {
2 ...
3}, {
4 classMethods: {
5 associate: function (model) {...}
6 },
7 instanceMethods: {
8 someMethod: function () { ...}
9 }
10});
11
1user.findOne({
2 include: {
3 model: project,
4 include: {
5 model: task,
6 required: true
7 }
8 }
9});
10
1const Model = sequelize.define('Model', {
2 ...
3});
4
5// Class Method
6Model.associate = function (models) {
7 ...associate the models
8};
9
10// Instance Method
11Model.prototype.someMethod = function () {..}
12
1 pool: {
2 maxIdleTime: 30000,
3 minConnections: 20,
4 maxConnections: 30
5 }
6