MCPcopy
hub / github.com/sequelize/sequelize / prepareEnvironment

Method prepareEnvironment

src/transaction.js:112–147  ·  view source on GitHub ↗

* Called to acquire a connection to use and set the correct options on the connection. * We should ensure all of the environment that's set up is cleaned up in `cleanup()` below. * * @param {boolean} useCLS Defaults to true: Use CLS (Continuation Local Storage) with Sequelize. With CLS, all

(useCLS = true)

Source from the content-addressed store, hash-verified

110 * @returns {Promise}
111 */
112 async prepareEnvironment(useCLS = true) {
113 let connectionPromise;
114
115 if (this.parent) {
116 connectionPromise = Promise.resolve(this.parent.connection);
117 } else {
118 const acquireOptions = { uuid: this.id };
119 if (this.options.readOnly) {
120 acquireOptions.type = 'SELECT';
121 }
122 connectionPromise = this.sequelize.connectionManager.getConnection(acquireOptions);
123 }
124
125 let result;
126 const connection = await connectionPromise;
127 this.connection = connection;
128 this.connection.uuid = this.id;
129
130 try {
131 await this.begin();
132 result = await this.setDeferrable();
133 } catch (setupErr) {
134 try {
135 result = await this.rollback();
136 } finally {
137 throw setupErr; // eslint-disable-line no-unsafe-finally
138 }
139 }
140
141 // TODO (@ephys) [>=7.0.0]: move this inside of sequelize.transaction, remove parameter.
142 if (useCLS && this.sequelize.constructor._cls) {
143 this.sequelize.constructor._cls.set('transaction', this);
144 }
145
146 return result;
147 }
148
149 async setDeferrable() {
150 if (this.options.deferrable) {

Callers 1

transactionMethod · 0.95

Calls 5

beginMethod · 0.95
setDeferrableMethod · 0.95
rollbackMethod · 0.95
getConnectionMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected