Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve context interfaces for Exec and Query #218

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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