I need to execute several SQL queries (select
, update
, delete
) concurrently and roll back if any goroutine errors out. Thus the question: are DB transactions safe for concurrent access?
DB is safe to be accessed from multiple goroutines:
DB is a database handle representing a pool of zero or more underlying connections.
It's safe for concurrent use by multiple goroutines.
Also Stmt
is safe to be used from multiple goroutines:
Stmt is a prepared statement. Stmt is safe for concurrent use by multiple goroutines.
You should use only one sql.Tx
per goroutine:
Once DB.Begin is called, the returned Tx is bound to a single connection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With