-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransaction.go
More file actions
28 lines (24 loc) · 841 Bytes
/
transaction.go
File metadata and controls
28 lines (24 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package database
import (
"context"
)
// TxDB exposes Provider and Transaction functions.
type TxDB[T any] interface {
Provider[T]
Transaction
// Ctx must be used after Begin() to propagate the new context with
// the TxDB instance
Ctx() context.Context
}
// Transaction represents the operations on a database transaction.
type Transaction interface {
// Commit the transaction. If the transaction was not started in the current context, it will be ignored.
// If any errors are provided in the e parameter, the transaction will be rolled back (but only for the parent context).
Commit(e ...error) error
Rollback(err error) error
}
type Tx[T any] interface {
// Begin starts a transaction. If the transaction is already started,
// it continues from the underlying transaction context.
Begin(ctx context.Context) TxDB[T]
}