kea-manage/lib/database/postgres/postgres.go

24 lines
448 B
Go
Raw Normal View History

package postgres
import (
"context"
"fmt"
"github.com/jackc/pgx/v5"
)
type Postgres struct {
connString string
}
func Open(host string, port int, user string, password string, name string) *Postgres {
var p = &Postgres{
connString: fmt.Sprintf("postgres://%s:%s@%s:%d/%s", user, password, host, port, name),
}
return p
}
func (p *Postgres) Connection(ctx context.Context) (*pgx.Conn, error) {
return pgx.Connect(ctx, p.connString)
}