Skip to content

Commit

Permalink
fix: give transaction the Mightyql connection
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jun 7, 2017
1 parent d903240 commit 0386e86
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const any: InternalQueryAnyType = async (connection, clientConfiguration,
};

export const transaction: InternalTransactionType = async (connection, handler) => {
await query(connection, 'START TRANSACTION');
await connection.query('START TRANSACTION');

try {
const result = await handler(connection);
Expand Down Expand Up @@ -222,7 +222,7 @@ const createConnection = async (

let ended = false;

return {
const bindConnection = {
any: mapTaggedTemplateLiteralInvocation(any.bind(null, connection, clientConfiguration)),
end: async () => {
if (ended) {
Expand All @@ -239,8 +239,12 @@ const createConnection = async (
maybeOne: mapTaggedTemplateLiteralInvocation(maybeOne.bind(null, connection, clientConfiguration)),
one: mapTaggedTemplateLiteralInvocation(one.bind(null, connection, clientConfiguration)),
query: mapTaggedTemplateLiteralInvocation(query.bind(null, connection)),
transaction: transaction.bind(null, connection)
transaction: (handler) => {
return transaction(bindConnection, handler);
}
};

return bindConnection;
};

const createPool = (
Expand All @@ -252,15 +256,19 @@ const createPool = (
const connect = async () => {
const connection = await pool.connect();

return {
const bindConnection = {
any: mapTaggedTemplateLiteralInvocation(any.bind(null, connection, clientConfiguration)),
many: mapTaggedTemplateLiteralInvocation(many.bind(null, connection, clientConfiguration)),
maybeOne: mapTaggedTemplateLiteralInvocation(maybeOne.bind(null, connection, clientConfiguration)),
one: mapTaggedTemplateLiteralInvocation(one.bind(null, connection, clientConfiguration)),
query: mapTaggedTemplateLiteralInvocation(query.bind(null, connection)),
release: connection.release.bind(connection),
transaction: transaction.bind(null, connection)
transaction: (handler) => {
return transaction(bindConnection, handler);
}
};

return bindConnection;
};

return {
Expand Down

0 comments on commit 0386e86

Please sign in to comment.