29 lines
789 B
Go
29 lines
789 B
Go
// Package repo holds data-access code. PostgreSQL handles owned tables
|
|
// (trait_definitions, profile_traits, segment_*, saved_queries) and read-only
|
|
// joins onto ingestion-owned tables (workspaces, profiles, sources, ...).
|
|
package repo
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// NewPool returns a pgxpool ready for use. Caller owns Close().
|
|
func NewPool(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
|
|
cfg, err := pgxpool.ParseConfig(dsn)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("parse pg dsn: %w", err)
|
|
}
|
|
pool, err := pgxpool.NewWithConfig(ctx, cfg)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("open pg pool: %w", err)
|
|
}
|
|
if err := pool.Ping(ctx); err != nil {
|
|
pool.Close()
|
|
return nil, fmt.Errorf("ping pg: %w", err)
|
|
}
|
|
return pool, nil
|
|
}
|