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