Skip to content

Instantly share code, notes, and snippets.

@jfeng45
Last active July 23, 2019 23:54
Show Gist options
  • Save jfeng45/b72975f49f7d65462ef455068491bb26 to your computer and use it in GitHub Desktop.
Save jfeng45/b72975f49f7d65462ef455068491bb26 to your computer and use it in GitHub Desktop.
Wrapper for database access
// SqlGdbc (SQL Go database connection) is a wrapper for SQL database handler ( can be *sql.DB or *sql.Tx)
// It should be able to work with all SQL data that follows SQL standard.
type SqlGdbc interface {
Exec(query string, args ...interface{}) (sql.Result, error)
Prepare(query string) (*sql.Stmt, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
// If need transaction support, add this interface
Transactioner
}
// SqlDBTx is the concrete implementation of sqlGdbc by using *sql.DB
type SqlDBTx struct {
DB *sql.DB
}
// SqlConnTx is the concrete implementation of sqlGdbc by using *sql.Tx
type SqlConnTx struct {
DB *sql.Tx
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment