https://github.com/danteay/gomysql
A MySQL connection pool based on Circuitbreaker
https://github.com/danteay/gomysql
Last synced: about 1 month ago
JSON representation
A MySQL connection pool based on Circuitbreaker
- Host: GitHub
- URL: https://github.com/danteay/gomysql
- Owner: danteay
- License: apache-2.0
- Created: 2018-06-29T18:19:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-29T18:37:56.000Z (almost 7 years ago)
- Last Synced: 2025-01-28T22:31:27.543Z (3 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mysqlcp
## Install
```bash
go get -u -v github.com/danteay/gomysql
```And import in your files whit the next lines:
```go
import (
"database/sql"
"github.com/danteay/gomysql"
)
```## Configure
Setup config for circut and recover strategies
```go
conf := gomysql.MysqlOptions{
Url: "user:password@/dbname",
Poolsize: 10,
FailRate: 0.25,
Regenerate: time.Second * 5,
TimeOut: time.Second * 1,
}
```Init connection pool
```go
pool, err := gomysql.InitPool(conf)if err != nil {
fmt.Println(err)
}
```Execute querys inside of the circuit breaker
```go
var suma interrQuery := pool.Execute(func(db *sql.DB) error {
fmt.Println("Entra callback")
return db.QueryRow("SELECT 1+1 AS suma").Scan(&suma)
})if errQuery != nil {
fmt.Println(errQuery)
}
```Healt check of the pool connection
```go
fmt.Println("==>> State: ", pool.State())
```