== Using transactions

=== Transactions with connections

You can execute transaction using SQL `BEGIN`/`COMMIT`/`ROLLBACK`, if you do so you must use
a `link:../../jsdoc/module-vertx-sql-client-js_sql_connection-SqlConnection.html[SqlConnection]` and manage it yourself.

Or you can use the transaction API of `link:../../jsdoc/module-vertx-sql-client-js_sql_connection-SqlConnection.html[SqlConnection]`:

[source,js]
----
throw "an error occured";

----

When PostgreSQL reports the current transaction is failed (e.g the infamous _current transaction is aborted, commands ignored until
end of transaction block_), the transaction is rollbacked and the `link:../../jsdoc/module-vertx-sql-client-js_transaction-Transaction.html#abortHandler[abortHandler]`
is called:

[source,js]
----
throw "an error occured";

----

=== Simplified transaction API

When you use a pool, you can start a transaction directly on the pool.

It borrows a connection from the pool, begins the transaction and releases the connection to the pool when the transaction ends.

[source,js]
----
throw "an error occured";

----

NOTE: this code will not close the connection because it will always be released back to the pool when the transaction