Skip to content

Commit

Permalink
Renaming conn to connection for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalBush committed Dec 5, 2019
1 parent a6fe9f3 commit 5bbc42d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class Client extends Api {
}

async withConnection( action ) {
let conn;
let connection;
const { pool } = this[ _state ];
try {
conn = await pool.acquire();
const result = await action( conn );
connection = await pool.acquire();
const result = await action( connection );
return result;
} finally {
if ( conn ) {
await pool.release( conn );
if ( connection ) {
await pool.release( connection );
}
}
}
Expand All @@ -56,7 +56,7 @@ class Client extends Api {
}
const { onBeginTransaction, onEndTransaction } = this[ _state ];

return this.withConnection( conn => Transaction.run( { conn, isolationLevel, action, context, onBeginTransaction, onEndTransaction } ) );
return this.withConnection( connection => Transaction.run( { connection, isolationLevel, action, context, onBeginTransaction, onEndTransaction } ) );
}

async dispose() {
Expand Down
12 changes: 6 additions & 6 deletions src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ class Transaction extends Api {
this.context = context;
}

static async run( { conn, isolationLevel, action, context, onBeginTransaction, onEndTransaction } ) {
const tx = new Transaction( conn, context );
static async run( { connection, isolationLevel, action, context, onBeginTransaction, onEndTransaction } ) {
const tx = new Transaction( connection, context );
try {
await conn.beginTransaction( "" /* name */, isolationLevel );
await connection.beginTransaction( "" /* name */, isolationLevel );
await onBeginTransaction( tx );
const result = await action( tx );
await onEndTransaction( tx );
await conn.commitTransaction();
await connection.commitTransaction();
return result;
} catch ( err ) {
// TODO: wrap err instead of mangling message
err.message = `Automatic Rollback. Failed Because: ${ err.message }`;
try {
await conn.rollbackTransaction();
await connection.rollbackTransaction();
} catch ( _ ) {
conn.close();
connection.close();
}
throw err;
}
Expand Down

0 comments on commit 5bbc42d

Please sign in to comment.