Skip to content

Commit f0ccf55

Browse files
- accept interface instead of *sql.DB
- improve interface
1 parent b1497ca commit f0ccf55

File tree

8 files changed

+20
-15
lines changed

8 files changed

+20
-15
lines changed

conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// connection fail with ErrConnDone.
1919
type Conn struct {
2020
conn *stdSql.Conn
21-
killerPool *stdSql.DB
21+
killerPool StdSQLDB
2222
connectionID string
2323
}
2424

db.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
// can be controlled with SetMaxIdleConns.
2424
type DB struct {
2525
// DB is the primary connection pool
26-
DB *stdSql.DB
26+
DB StdSQLDB
2727
// KillerPool is an optional (but recommended) secondary connection pool.
2828
// If provided, it is used to fire KILL signals.
29-
KillerPool *stdSql.DB
29+
KillerPool StdSQLDB
3030
}
3131

3232
// Begin starts a transaction. The default isolation level is dependent on

helpers.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
package sql
44

5-
import (
6-
stdSql "database/sql"
7-
)
8-
95
// kill is used to kill a running query.
106
// It is advised that db be another pool that the
117
// connection was NOT derived from.
12-
func kill(db *stdSql.DB, connectionID string) error {
8+
func kill(db StdSQLDB, connectionID string) error {
139

1410
if connectionID == "" {
1511
return nil

interfaces.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package sql
55
import (
66
"context"
77
stdSql "database/sql"
8+
"database/sql/driver"
9+
"time"
810
)
911

1012
// StdSQLCommon is the interface that allows query and exec interactions with a database.
@@ -24,9 +26,16 @@ type StdSQLDB interface {
2426
Ping() error
2527
PingContext(ctx context.Context) error
2628
StdSQLCommon
29+
Conn(ctx context.Context) (*stdSql.Conn, error)
2730
Begin() (*stdSql.Tx, error)
2831
BeginTx(ctx context.Context, opts *stdSql.TxOptions) (*stdSql.Tx, error)
2932
Close() error
33+
34+
Driver() driver.Driver
35+
SetConnMaxLifetime(d time.Duration)
36+
SetMaxIdleConns(n int)
37+
SetMaxOpenConns(n int)
38+
Stats() stdSql.DBStats
3039
}
3140

3241
// StdSQLTx is the interface that allows a transaction to be committed or rolledback.
@@ -38,11 +47,11 @@ type StdSQLTx interface {
3847
Rollback() error
3948
}
4049

41-
// SQLBasic is the interface that allows sql.DB, Conn and Stmt to be used.
50+
// SQLBasic is the interface that allows Conn and Stmt to be used.
4251
type SQLBasic interface {
4352
ExecContext(ctx context.Context, query string, args ...interface{}) (stdSql.Result, error)
44-
QueryContext(ctx context.Context, query string, args ...interface{}) (*stdSql.Rows, error)
45-
QueryRowContext(ctx context.Context, query string, args ...interface{}) *stdSql.Row
53+
QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
54+
QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row
4655
}
4756

4857
// SQLConn is the interface that allows Conn and Stmt to be used.

row.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
type Row struct {
1010
ctx context.Context
1111
row *stdSql.Row
12-
killerPool *stdSql.DB
12+
killerPool StdSQLDB
1313
connectionID string
1414
}
1515

rows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type Rows struct {
1111
ctx context.Context
1212
rows *stdSql.Rows
13-
killerPool *stdSql.DB
13+
killerPool StdSQLDB
1414
connectionID string
1515
}
1616

stmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// A Stmt is safe for concurrent use by multiple goroutines.
1212
type Stmt struct {
1313
stmt *stdSql.Stmt
14-
killerPool *stdSql.DB
14+
killerPool StdSQLDB
1515
connectionID string
1616
}
1717

tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
// by the call to Commit or Rollback.
2121
type Tx struct {
2222
tx *stdSql.Tx
23-
killerPool *stdSql.DB
23+
killerPool StdSQLDB
2424
connectionID string
2525

2626
// Lock and store stmts

0 commit comments

Comments
 (0)