Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Closure ¶
Closure is a function that is executed within a transaction. The function should not commit or rollback the transaction.
type Middleware ¶
Middleware is a function that is executed before and after the closure.
type Opener ¶
Opener is an interface for database connections that support opening transactions. This interface is implemented by *sql.DB and *sql.Conn.
type Transactor ¶
type Transactor interface { // InTx executes the given closure within a transaction. The transaction is // committed if the closure returns nil, otherwise it is rolled back. It is // important that the closure does not commit or rollback the transaction as // this is handled by the transactor automatically. Recursively calling InTx // will re-use the same transaction. InTx(context.Context, Closure) error }
The transactor is responsible for creating and committing or rolling back transactions.
func NewTransactor ¶
func NewTransactor(o Opener, opts TransactorOptions) Transactor
NewTransactor creates a new Transactor that uses the given a Opener. This function panics if the Opener is nil. The transactor is responsible for creating and committing or rolling back transactions.
type TransactorOptions ¶
type TransactorOptions struct { // sql.TxOptions to pass the opener when it begins a transaction. This does // not apply to new savepoint transactions (only the root transaction). BeginOptions *sql.TxOptions // Middlewares to execute before and after the closure. The middlewares are // executed in the order they are passed. The middlewares are executed only // once per opened transaction, not for each recursive call to InTx. BeginMiddlewares []Middleware // If true, the transactor will use savepoints to create nested transactions. // Make sure the database supports savepoints before enabling this option. EnableSavepoints bool }
Click to show internal directories.
Click to hide internal directories.