mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
81 lines
2.1 KiB
TypeScript
81 lines
2.1 KiB
TypeScript
// Loaded from https://raw.githubusercontent.com/denjucks/dex/master/lib/dialects/oracledb/transaction.js
|
|
|
|
|
|
import Transaction from '../../transaction.js';
|
|
import { timeout, KnexTimeoutError } from '../../util/timeout.js';
|
|
import debuglib from '../../deps/debug@4.1.1/src/index.js';
|
|
const debugTx = debuglib('knex:tx');
|
|
|
|
export default class Oracle_Transaction extends Transaction {
|
|
// disable autocommit to allow correct behavior (default is true)
|
|
begin() {
|
|
return Promise.resolve();
|
|
}
|
|
|
|
async commit(conn, value) {
|
|
this._completed = true;
|
|
try {
|
|
await conn.commitAsync();
|
|
this._resolver(value);
|
|
} catch (err) {
|
|
this._rejecter(err);
|
|
}
|
|
}
|
|
|
|
release(conn, value) {
|
|
return this._resolver(value);
|
|
}
|
|
|
|
rollback(conn, err) {
|
|
this._completed = true;
|
|
debugTx('%s: rolling back', this.txid);
|
|
return timeout(conn.rollbackAsync(), 5000)
|
|
.catch((e) => {
|
|
if (!(e instanceof KnexTimeoutError)) {
|
|
return Promise.reject(e);
|
|
}
|
|
this._rejecter(e);
|
|
})
|
|
.then(() => {
|
|
if (err === undefined) {
|
|
if (this.doNotRejectOnRollback) {
|
|
this._resolver();
|
|
return;
|
|
}
|
|
err = new Error(`Transaction rejected with non-error: ${err}`);
|
|
}
|
|
this._rejecter(err);
|
|
});
|
|
}
|
|
|
|
savepoint(conn) {
|
|
return this.query(conn, `SAVEPOINT ${this.txid}`);
|
|
}
|
|
|
|
async acquireConnection(config, cb) {
|
|
const configConnection = config && config.connection;
|
|
|
|
const connection =
|
|
configConnection || (await this.client.acquireConnection());
|
|
try {
|
|
connection.__knexTxId = this.txid;
|
|
connection.isTransaction = true;
|
|
return await cb(connection);
|
|
} finally {
|
|
debugTx('%s: releasing connection', this.txid);
|
|
connection.isTransaction = false;
|
|
try {
|
|
await connection.commitAsync();
|
|
} catch (err) {
|
|
this._rejecter(err);
|
|
} finally {
|
|
if (!configConnection) {
|
|
await this.client.releaseConnection(connection);
|
|
} else {
|
|
debugTx('%s: not releasing external connection', this.txid);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|