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

Method prepareEnvironment

lib/transaction.js:101–139  ·  lib/transaction.js::Transaction.prepareEnvironment

* 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)

Source from the content-addressed store, hash-verified

99 * @returns {Promise}
100 */
101 async prepareEnvironment(useCLS) {
102 let connectionPromise;
103
104 if (useCLS === undefined) {
105 useCLS = true;
106 }
107
108 if (this.parent) {
109 connectionPromise = Promise.resolve(this.parent.connection);
110 } else {
111 const acquireOptions = { uuid: this.id };
112 if (this.options.readOnly) {
113 acquireOptions.type = class="st">'SELECT';
114 }
115 connectionPromise = this.sequelize.connectionManager.getConnection(acquireOptions);
116 }
117
118 let result;
119 const connection = await connectionPromise;
120 this.connection = connection;
121 this.connection.uuid = this.id;
122
123 try {
124 await this.begin();
125 result = await this.setDeferrable();
126 } catch (setupErr) {
127 try {
128 result = await this.rollback();
129 } finally {
130 throw setupErr; class="cm">// eslint-disable-line no-unsafe-finally
131 }
132 }
133
134 if (useCLS && this.sequelize.constructor._cls) {
135 this.sequelize.constructor._cls.set(class="st">'transaction', this);
136 }
137
138 return result;
139 }
140
141 async setDeferrable() {
142 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