mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: allow drivers to only implement Context variants
Drivers shouldn't need to implement both Queryer and QueryerContext, they should just implement QueryerContext. Same with Execer and ExecerContext. This CL tests for QueryContext and ExecerContext first so drivers do not need to implement Queryer and Execer with an empty definition. Fixes #21663 Change-Id: Ifbaa71da669f4bc60f8da8c41a04a4afed699a9f Reviewed-on: https://go-review.googlesource.com/65733 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
89a7adf8e4
commit
532714829e
3 changed files with 143 additions and 13 deletions
|
|
@ -26,8 +26,8 @@ func ctxDriverPrepare(ctx context.Context, ci driver.Conn, query string) (driver
|
|||
return si, err
|
||||
}
|
||||
|
||||
func ctxDriverExec(ctx context.Context, execer driver.Execer, query string, nvdargs []driver.NamedValue) (driver.Result, error) {
|
||||
if execerCtx, is := execer.(driver.ExecerContext); is {
|
||||
func ctxDriverExec(ctx context.Context, execerCtx driver.ExecerContext, execer driver.Execer, query string, nvdargs []driver.NamedValue) (driver.Result, error) {
|
||||
if execerCtx != nil {
|
||||
return execerCtx.ExecContext(ctx, query, nvdargs)
|
||||
}
|
||||
dargs, err := namedValueToValue(nvdargs)
|
||||
|
|
@ -43,10 +43,9 @@ func ctxDriverExec(ctx context.Context, execer driver.Execer, query string, nvda
|
|||
return execer.Exec(query, dargs)
|
||||
}
|
||||
|
||||
func ctxDriverQuery(ctx context.Context, queryer driver.Queryer, query string, nvdargs []driver.NamedValue) (driver.Rows, error) {
|
||||
if queryerCtx, is := queryer.(driver.QueryerContext); is {
|
||||
ret, err := queryerCtx.QueryContext(ctx, query, nvdargs)
|
||||
return ret, err
|
||||
func ctxDriverQuery(ctx context.Context, queryerCtx driver.QueryerContext, queryer driver.Queryer, query string, nvdargs []driver.NamedValue) (driver.Rows, error) {
|
||||
if queryerCtx != nil {
|
||||
return queryerCtx.QueryContext(ctx, query, nvdargs)
|
||||
}
|
||||
dargs, err := namedValueToValue(nvdargs)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue