Add constants for transaction isolation levels

scan-io
Jack Christensen 2014-05-19 08:25:34 -05:00
parent 6d6fb4561a
commit bc2a120301
2 changed files with 14 additions and 6 deletions

18
conn.go
View File

@ -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)
}

View File

@ -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 {