2
0

Add QueryRowContext

This commit is contained in:
Jack Christensen
2017-02-04 15:57:06 -06:00
parent 3e13b333d9
commit 24193ee322
2 changed files with 73 additions and 8 deletions
+7 -8
View File
@@ -507,12 +507,6 @@ func (c *Conn) QueryRow(sql string, args ...interface{}) *Row {
}
func (c *Conn) QueryContext(ctx context.Context, sql string, args ...interface{}) (*Rows, error) {
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
doneChan := make(chan struct{})
go func() {
@@ -529,9 +523,9 @@ func (c *Conn) QueryContext(ctx context.Context, sql string, args ...interface{}
if err != nil {
select {
case <-ctx.Done():
return nil, ctx.Err()
return rows, ctx.Err()
case doneChan <- struct{}{}:
return nil, err
return rows, err
}
}
@@ -540,3 +534,8 @@ func (c *Conn) QueryContext(ctx context.Context, sql string, args ...interface{}
return rows, nil
}
func (c *Conn) QueryRowContext(ctx context.Context, sql string, args ...interface{}) *Row {
rows, _ := c.QueryContext(ctx, sql, args...)
return (*Row)(rows)
}