Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10455843
tx.go
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
626 B
Subscribers
None
tx.go
View Options
package
db
import
(
"context"
"database/sql"
)
// TransactionScopedWork describes code executed within a database transaction.
type
TransactionScopedWork
func
(
ctx
context
.
Context
,
db
*
sql
.
Tx
)
error
// RunTransactionWithOptions executes a block of code within a database transaction.
func
RunTransactionWithOptions
(
ctx
context
.
Context
,
db
*
sql
.
DB
,
txOpts
*
sql
.
TxOptions
,
txWork
TransactionScopedWork
)
error
{
tx
,
err
:=
db
.
BeginTx
(
ctx
,
txOpts
)
if
err
!=
nil
{
return
err
}
if
err
=
txWork
(
ctx
,
tx
);
err
!=
nil
{
if
txErr
:=
tx
.
Rollback
();
txErr
!=
nil
{
return
txErr
}
return
err
}
return
tx
.
Commit
()
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 1, 2:01 AM (21 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3146023
Attached To
rWF WriteFreely
Event Timeline
Log In to Comment