data layer
This commit is contained in:
28
data-layer/api/internal/repo/pool.go
Normal file
28
data-layer/api/internal/repo/pool.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user