Transactions
- Begin a transaction.
DB.BeginTx
 begins a new transaction, returning anÂsql.Tx
 that represents it - Perform database operations using anÂ
sql.Tx
- End the transaction with one of the following:
- Commit usingÂ
Tx.Commit
. If it succeeds, all queries and updates are confirmed and applied atomically. If it fails, discard all results fromÂQuery
 andÂExec
 as invalid - Rollback usingÂ
Tx.Rollback
. Even if it fails, the transaction remains invalid and won’t be committed. ATx.Rollback
call after a successfulTx.Commit
is a no-op
- Commit usingÂ
Prepared Statements
Using DB.Exec
When executing DB.Exec
without placeholder parameters, a prepared statement will not be utilized
The connection will be released to the pool automatically
When executing DB.Exec
with placeholder parameters, a new prepared statement will be used under the hood for each invocation
The connection will be released to the pool automatically
Using DB.Query
When executing DB.Query
without placeholder parameters, a prepared statement will not be used
The connection will be released to the pool automatically when the returned rows are iterated or after the call to Rows.Close()
When executing DB.Query
with placeholder parameters, a new prepared statement will be used under the hood for each invocation
The connection will be released to the pool automatically when the returned rows are iterated or after the call to Rows.Close()
Using DB.Prepare
When executing DB.Prepare
, a new prepared statement will be used once for all the invocations in the given connection
The connection will be released to the pool after the call to Stmt.Close()
Using pgx
TODO: PGX Top to Bottom - YouTube