aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/driver/driver.go
diff options
context:
space:
mode:
authorDaniel Theophanes <kardianos@gmail.com>2016-12-13 07:55:12 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2016-12-14 18:13:13 +0000
commitd0501f1da9c54a8053940feeb86e1644ffaae522 (patch)
tree35a699faceba0cf306bdf1a413d24828ac2e21da /src/database/sql/driver/driver.go
parentfe07091f9eb9a1dcedc6eab1762de5383f520a00 (diff)
downloadgo-d0501f1da9c54a8053940feeb86e1644ffaae522.tar.xz
database/sql: do not store Tx options in Context
Drivers which previously supported tip will need to update to this revision before release. Fixes #18284 Change-Id: I70b8e7afff1558a8b5348885ce9f50e067c72ee9 Reviewed-on: https://go-review.googlesource.com/34330 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/database/sql/driver/driver.go')
-rw-r--r--src/database/sql/driver/driver.go41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/database/sql/driver/driver.go b/src/database/sql/driver/driver.go
index 2e47cd9ee7..d66196fd48 100644
--- a/src/database/sql/driver/driver.go
+++ b/src/database/sql/driver/driver.go
@@ -10,7 +10,6 @@ package driver
import (
"context"
- "database/sql/internal"
"errors"
"reflect"
)
@@ -157,7 +156,7 @@ type Conn interface {
// Begin starts and returns a new transaction.
//
- // Deprecated: Drivers should implement ConnBeginContext instead (or additionally).
+ // Deprecated: Drivers should implement ConnBeginTx instead (or additionally).
Begin() (Tx, error)
}
@@ -169,41 +168,35 @@ type ConnPrepareContext interface {
PrepareContext(ctx context.Context, query string) (Stmt, error)
}
-// IsolationLevel is the transaction isolation level stored in Context.
+// IsolationLevel is the transaction isolation level stored in TxOptions.
//
// This type should be considered identical to sql.IsolationLevel along
// with any values defined on it.
type IsolationLevel int
-// IsolationFromContext extracts the isolation level from a Context.
-func IsolationFromContext(ctx context.Context) (level IsolationLevel, ok bool) {
- level, ok = ctx.Value(internal.IsolationLevelKey{}).(IsolationLevel)
- return level, ok
-}
-
-// ReadOnlyFromContext extracts the read-only property from a Context.
-// When readonly is true the transaction must be set to read-only
-// or return an error.
-func ReadOnlyFromContext(ctx context.Context) (readonly bool) {
- readonly, _ = ctx.Value(internal.ReadOnlyKey{}).(bool)
- return readonly
+// TxOptions holds the transaction options.
+//
+// This type should be considered identical to sql.TxOptions.
+type TxOptions struct {
+ Isolation IsolationLevel
+ ReadOnly bool
}
-// ConnBeginContext enhances the Conn interface with context.
-type ConnBeginContext interface {
- // BeginContext starts and returns a new transaction.
+// ConnBeginTx enhances the Conn interface with context and TxOptions.
+type ConnBeginTx interface {
+ // BeginTx starts and returns a new transaction.
// If the context is canceled by the user the sql package will
// call Tx.Rollback before discarding and closing the connection.
//
- // This must call IsolationFromContext to determine if there is a set
- // isolation level. If the driver does not support setting the isolation
- // level and one is set or if there is a set isolation level
- // but the set level is not supported, an error must be returned.
+ // This must check opts.Isolation to determine if there is a set
+ // isolation level. If the driver does not support a non-default
+ // level and one is set or if there is a non-default isolation level
+ // that is not supported, an error must be returned.
//
- // This must also call ReadOnlyFromContext to determine if the read-only
+ // This must also check opts.ReadOnly to determine if the read-only
// value is true to either set the read-only transaction property if supported
// or return an error if it is not supported.
- BeginContext(ctx context.Context) (Tx, error)
+ BeginTx(ctx context.Context, opts TxOptions) (Tx, error)
}
// Result is the result of a query execution.