* Use CLS (Continuation Local Storage) with Sequelize. With Continuation * Local Storage, all queries within the transaction callback will * automatically receive the transaction object. * * CLS namespace provided is stored as `Sequelize._cls` * * @param {object} ns CLS namespace
(ns)
| 1221 | * @returns {object} Sequelize constructor |
| 1222 | */ |
| 1223 | static useCLS(ns) { |
| 1224 | // check `ns` is valid CLS namespace |
| 1225 | if (!ns || typeof ns !== 'object' || typeof ns.bind !== 'function' || typeof ns.run !== 'function') throw new Error('Must provide CLS namespace'); |
| 1226 | |
| 1227 | // save namespace as `Sequelize._cls` |
| 1228 | Sequelize._cls = ns; |
| 1229 | |
| 1230 | // return Sequelize for chaining |
| 1231 | return this; |
| 1232 | } |
| 1233 | |
| 1234 | /** |
| 1235 | * Run function in CLS context. |
no outgoing calls
no test coverage detected