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