-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransactional.go
72 lines (57 loc) · 1.42 KB
/
transactional.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package transactional
import (
"context"
)
type Transaction interface {
Commit() error
Rollback() error
}
type Transactional interface {
BeginTransaction(ctx context.Context, opts BeginTransactionOptions) (Transaction, error)
DefaultLogFields() map[string]any
}
type TxAccessMode string
func (t TxAccessMode) String() string {
return string(t)
}
const (
ReadWrite TxAccessMode = "read write"
ReadOnly TxAccessMode = "read only"
)
type TxIsoLevel string
func (t TxIsoLevel) String() string {
return string(t)
}
const (
Serializable TxIsoLevel = "serializable"
RepeatableRead TxIsoLevel = "repeatable read"
ReadCommitted TxIsoLevel = "read committed"
ReadUncommitted TxIsoLevel = "read uncommitted"
)
type TxDeferrableMode string
func (t TxDeferrableMode) String() string {
return string(t)
}
const (
Deferrable TxDeferrableMode = "deferrable"
NotDeferrable TxDeferrableMode = "not deferrable"
)
func DefaultWriteTransactionOptions() BeginTransactionOptions {
return BeginTransactionOptions{
AccessMode: ReadWrite,
IsolationLevel: Serializable,
DeferrableMode: NotDeferrable,
}
}
func DefaultReadOnlyTransactionOptions() BeginTransactionOptions {
return BeginTransactionOptions{
AccessMode: ReadOnly,
IsolationLevel: Serializable,
DeferrableMode: NotDeferrable,
}
}
type BeginTransactionOptions struct {
AccessMode TxAccessMode
IsolationLevel TxIsoLevel
DeferrableMode TxDeferrableMode
}