Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hopehook/golang-db
db pool helper for golang
https://github.com/hopehook/golang-db
db go mysql pool redis
Last synced: 4 months ago
JSON representation
db pool helper for golang
- Host: GitHub
- URL: https://github.com/hopehook/golang-db
- Owner: hopehook
- Created: 2016-06-01T06:33:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-29T08:39:36.000Z (almost 6 years ago)
- Last Synced: 2024-10-02T03:03:41.794Z (4 months ago)
- Topics: db, go, mysql, pool, redis
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 60
- Watchers: 8
- Forks: 19
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# golang-db
db pool helper for golang, welcome everyone contribute code, your name will
in CONTRIBUTORS.### How to use mysql pool helper
1 go get github.com/hopehook/golang-db/mysql
2 go get github.com/go-sql-driver/mysql
Note: please use go-sql-driver Version >= 1.4
3 code snippet
```go
import "github.com/hopehook/golang-db/mysql"// get a mysql db pool as global variable
DB := mysql.InitMySQLPool(host, database, user, password, charset, maxOpenConns, maxIdleConns)// use helper function
data, err := DB.Query(`select * from table limit 10`)
... ...// use transaction
TX, _ := DB.Begin()
defer TX.Rollback()
TX.Exec(`delete from table where id = 1`)
TX.Commit()// if you want to use golang own function, please get DB.SQLDB as your db pool variable
SQLDB := DB.SQLDB
SQLDB.Exec(`delete from table where id = 1`)// use golang own transaction
TX, _ := SQLDB.Begin()
defer TX.Rollback()
TX.Exec(`delete from table where id = 1`)
TX.Commit()
```