An open API service indexing awesome lists of open source software.

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

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 int

errQuery := 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())
```