mirror of https://github.com/jackc/pgx.git
Add constants for transaction isolation levels
parent
6d6fb4561a
commit
bc2a120301
18
conn.go
18
conn.go
|
@ -23,6 +23,14 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// Transaction isolation levels
|
||||
const (
|
||||
Serializable = "serializable"
|
||||
RepeatableRead = "repeatable read"
|
||||
ReadCommitted = "read committed"
|
||||
ReadUncommitted = "read uncommitted"
|
||||
)
|
||||
|
||||
// ConnConfig contains all the options used to establish a connection.
|
||||
type ConnConfig struct {
|
||||
Socket string // path to unix domain socket directory (e.g. /private/tmp)
|
||||
|
@ -798,11 +806,11 @@ func (c *Conn) Transaction(f func() bool) (committed bool, err error) {
|
|||
// TransactionIso is the same as Transaction except it takes an isoLevel argument that
|
||||
// it uses as the transaction isolation level.
|
||||
//
|
||||
// Valid isolation levels are:
|
||||
// serializable
|
||||
// repeatable read
|
||||
// read committed
|
||||
// read uncommitted
|
||||
// Valid isolation levels (and their constants) are:
|
||||
// serializable (pgx.Serializable)
|
||||
// repeatable read (pgx.RepeatableRead)
|
||||
// read committed (pgx.ReadCommitted)
|
||||
// read uncommitted (pgx.ReadUncommitted)
|
||||
func (c *Conn) TransactionIso(isoLevel string, f func() bool) (committed bool, err error) {
|
||||
return c.transaction(isoLevel, f)
|
||||
}
|
||||
|
|
|
@ -727,7 +727,7 @@ func TestTransactionIso(t *testing.T) {
|
|||
}
|
||||
defer conn.Close()
|
||||
|
||||
isoLevels := []string{"serializable", "repeatable read", "read committed", "read uncommitted"}
|
||||
isoLevels := []string{pgx.Serializable, pgx.RepeatableRead, pgx.ReadCommitted, pgx.ReadUncommitted}
|
||||
for _, iso := range isoLevels {
|
||||
_, err := conn.TransactionIso(iso, func() bool {
|
||||
if level := mustSelectValue(t, conn, "select current_setting('transaction_isolation')"); level != iso {
|
||||
|
|
Loading…
Reference in New Issue