kea-manage/lib/database/postgres/postgres.go
Matthew Stobbs 1d0a5811ce migrated to cobra structure
adding abstractions for database to avoid passing around the connection
2024-09-20 15:21:41 -06:00

24 lines
448 B
Go

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)
}