Last active
July 23, 2019 23:54
-
-
Save jfeng45/b72975f49f7d65462ef455068491bb26 to your computer and use it in GitHub Desktop.
Wrapper for database access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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