Skip to content

Commit

Permalink
- separate out the interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
rocketlaunchr-cto committed Apr 3, 2019
1 parent f0ccf55 commit 4b890b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
// connection is returned to DB's idle connection pool. The pool size
// can be controlled with SetMaxIdleConns.
type DB struct {
// DB is the primary connection pool
DB StdSQLDB
// KillerPool is an optional (but recommended) secondary connection pool.
// DB is the primary connection pool (i.e. *stdSql.DB).
DB StdSQLDBExtra
// KillerPool is an optional (but recommended) secondary connection pool (i.e. *stdSql.DB).
// If provided, it is used to fire KILL signals.
KillerPool StdSQLDB
KillerPool StdSQLDBExtra
}

// Begin starts a transaction. The default isolation level is dependent on
Expand Down
17 changes: 13 additions & 4 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import (
"time"
)

// StdSQLLegacy will potentially be removed in Go 2.
type StdSQLLegacy interface {
Exec(query string, args ...interface{}) (stdSql.Result, error)
Prepare(query string) (*stdSql.Stmt, error)
Query(query string, args ...interface{}) (*stdSql.Rows, error)
QueryRow(query string, args ...interface{}) *stdSql.Row
}

// StdSQLCommon is the interface that allows query and exec interactions with a database.
type StdSQLCommon interface {
Exec(query string, args ...interface{}) (stdSql.Result, error)
StdSQLLegacy
ExecContext(ctx context.Context, query string, args ...interface{}) (stdSql.Result, error)
Prepare(query string) (*stdSql.Stmt, error)
PrepareContext(ctx context.Context, query string) (*stdSql.Stmt, error)
Query(query string, args ...interface{}) (*stdSql.Rows, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (*stdSql.Rows, error)
QueryRow(query string, args ...interface{}) *stdSql.Row
QueryRowContext(ctx context.Context, query string, args ...interface{}) *stdSql.Row
}

Expand All @@ -30,7 +35,11 @@ type StdSQLDB interface {
Begin() (*stdSql.Tx, error)
BeginTx(ctx context.Context, opts *stdSql.TxOptions) (*stdSql.Tx, error)
Close() error
}

// StdSQLDBExtra is the interface that directly maps to a *stdSql.DB.
type StdSQLDBExtra interface {
StdSQLDB
Driver() driver.Driver
SetConnMaxLifetime(d time.Duration)
SetMaxIdleConns(n int)
Expand Down

0 comments on commit 4b890b8

Please sign in to comment.