@@ -5,29 +5,30 @@ package squirrel
5
5
import (
6
6
"context"
7
7
"database/sql"
8
+ "errors"
8
9
)
9
10
10
- // Execer is the interface that wraps the Exec method.
11
+ // NoContextSupport is returned if a db doesn't support Context.
12
+ var NoContextSupport = errors .New ("DB does not support Context" )
13
+
14
+ // ExecerContext is the interface that wraps the ExecContext method.
11
15
//
12
- // Exec executes the given query as implemented by database/sql.Exec.
13
- type Execer interface {
14
- Exec (query string , args ... interface {}) (sql.Result , error )
16
+ // Exec executes the given query as implemented by database/sql.ExecContext.
17
+ type ExecerContext interface {
15
18
ExecContext (ctx context.Context , query string , args ... interface {}) (sql.Result , error )
16
19
}
17
20
18
- // Queryer is the interface that wraps the Query method.
21
+ // QueryerContext is the interface that wraps the QueryContext method.
19
22
//
20
- // Query executes the given query as implemented by database/sql.Query.
21
- type Queryer interface {
22
- Query (query string , args ... interface {}) (* sql.Rows , error )
23
+ // QueryContext executes the given query as implemented by database/sql.QueryContext.
24
+ type QueryerContext interface {
23
25
QueryContext (ctx context.Context , query string , args ... interface {}) (* sql.Rows , error )
24
26
}
25
27
26
- // QueryRower is the interface that wraps the QueryRow method.
28
+ // QueryRowerContext is the interface that wraps the QueryRowContext method.
27
29
//
28
- // QueryRow executes the given query as implemented by database/sql.QueryRow.
29
- type QueryRower interface {
30
- QueryRow (query string , args ... interface {}) RowScanner
30
+ // QueryRowContext executes the given query as implemented by database/sql.QueryRowContext.
31
+ type QueryRowerContext interface {
31
32
QueryRowContext (ctx context.Context , query string , args ... interface {}) RowScanner
32
33
}
33
34
@@ -40,7 +41,7 @@ func (r *txRunner) QueryRowContext(ctx context.Context, query string, args ...in
40
41
}
41
42
42
43
// ExecContextWith ExecContexts the SQL returned by s with db.
43
- func ExecContextWith (ctx context.Context , db Execer , s Sqlizer ) (res sql.Result , err error ) {
44
+ func ExecContextWith (ctx context.Context , db ExecerContext , s Sqlizer ) (res sql.Result , err error ) {
44
45
query , args , err := s .ToSql ()
45
46
if err != nil {
46
47
return
@@ -49,7 +50,7 @@ func ExecContextWith(ctx context.Context, db Execer, s Sqlizer) (res sql.Result,
49
50
}
50
51
51
52
// QueryContextWith QueryContexts the SQL returned by s with db.
52
- func QueryContextWith (ctx context.Context , db Queryer , s Sqlizer ) (rows * sql.Rows , err error ) {
53
+ func QueryContextWith (ctx context.Context , db QueryerContext , s Sqlizer ) (rows * sql.Rows , err error ) {
53
54
query , args , err := s .ToSql ()
54
55
if err != nil {
55
56
return
@@ -58,7 +59,7 @@ func QueryContextWith(ctx context.Context, db Queryer, s Sqlizer) (rows *sql.Row
58
59
}
59
60
60
61
// QueryRowContextWith QueryRowContexts the SQL returned by s with db.
61
- func QueryRowContextWith (ctx context.Context , db QueryRower , s Sqlizer ) RowScanner {
62
+ func QueryRowContextWith (ctx context.Context , db QueryRowerContext , s Sqlizer ) RowScanner {
62
63
query , args , err := s .ToSql ()
63
64
return & Row {RowScanner : db .QueryRowContext (ctx , query , args ... ), err : err }
64
65
}
0 commit comments