aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/driver/driver.go
diff options
context:
space:
mode:
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.