Documentation
¶
Index ¶
- type Pool
- func (p *Pool) Close() error
- func (p *Pool) DiscoverDatabases(ctx context.Context) ([]string, error)
- func (p *Pool) ExecContext(ctx context.Context, database, query string, args ...any) (sql.Result, error)
- func (p *Pool) QueryContext(ctx context.Context, database, query string, args ...any) ([]map[string]any, error)
- type PoolManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents a single PostgreSQL host. Because each Postgres connection is bound to a specific database at connect time, Pool keeps one *sql.DB per database name, lazily opened on first use.
func (*Pool) DiscoverDatabases ¶
DiscoverDatabases lists all non-system, non-template databases on the host. It uses the default database for the query.
func (*Pool) ExecContext ¶
func (p *Pool) ExecContext(ctx context.Context, database, query string, args ...any) (sql.Result, error)
ExecContext executes a statement against the given database.
func (*Pool) QueryContext ¶
func (p *Pool) QueryContext(ctx context.Context, database, query string, args ...any) ([]map[string]any, error)
QueryContext runs a query against the given database and returns results as a slice of column-name -> value maps. Byte slices are converted to strings for JSON-friendliness.
type PoolManager ¶
type PoolManager struct {
// contains filtered or unexported fields
}
PoolManager manages multiple named PostgreSQL host pools with lazy reconnection. Hosts that fail to connect at startup are not fatal — they will be retried on the next Get() call.
func NewManager ¶
func NewManager(hosts map[string]config.HostConfig) (*PoolManager, error)
NewManager creates a PoolManager. It attempts to connect to all hosts but does NOT fail if some are unreachable — those will be retried lazily. Only returns an error if zero hosts are configured.
func (*PoolManager) Close ¶
func (m *PoolManager) Close()
func (*PoolManager) Get ¶
func (m *PoolManager) Get(hostName string) (*Pool, error)
Get returns the pool for a host. If the host previously failed to connect, it attempts to reconnect. Returns an error only if the host is unknown or the connection (re)attempt fails.
func (*PoolManager) HostNames ¶
func (m *PoolManager) HostNames() []string
HostNames returns all configured host names (including disconnected ones).
func (*PoolManager) HostStatus ¶
func (m *PoolManager) HostStatus(hostName string) (connected bool, lastErr error)
HostStatus returns the connection status of a host.