Skip to content

Commit

Permalink
Merge pull request #218 from shogo82148/fix-execer-context
Browse files Browse the repository at this point in the history
improve context interfaces for Exec and Query
  • Loading branch information
shogo82148 authored Oct 19, 2021
2 parents 97d7dc1 + 65c571c commit 541f6dd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions xraysql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func (conn *driverConn) Exec(query string, args []driver.Value) (driver.Result,

func (conn *driverConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
execer, ok := conn.Conn.(driver.Execer)
if !ok {
execerCtx, okCtx := conn.Conn.(driver.ExecerContext)
if !ok && !okCtx {
return nil, driver.ErrSkip
}

Expand All @@ -135,7 +136,7 @@ func (conn *driverConn) ExecContext(ctx context.Context, query string, args []dr

var err error
var result driver.Result
if execerCtx, ok := conn.Conn.(driver.ExecerContext); ok {
if okCtx {
result, err = execerCtx.ExecContext(ctx, query, args)
} else {
select {
Expand Down Expand Up @@ -168,7 +169,8 @@ func (conn *driverConn) Query(query string, args []driver.Value) (driver.Rows, e

func (conn *driverConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
queryer, ok := conn.Conn.(driver.Queryer)
if !ok {
queryerCtx, okCtx := conn.Conn.(driver.QueryerContext)
if !ok && !okCtx {
return nil, driver.ErrSkip
}

Expand All @@ -177,7 +179,7 @@ func (conn *driverConn) QueryContext(ctx context.Context, query string, args []d

var err error
var rows driver.Rows
if queryerCtx, ok := conn.Conn.(driver.QueryerContext); ok {
if okCtx {
rows, err = queryerCtx.QueryContext(ctx, query, args)
} else {
select {
Expand Down

0 comments on commit 541f6dd

Please sign in to comment.