Documentation
¶
Overview ¶
Package connection provides a multi-profile PostgreSQL connection registry.
Index ¶
- func GenerateConfigJSON(t *target.Target) ([]byte, error)
- type CompatConfig
- type CompatProfile
- type Profile
- type ProfileConfig
- type ProfileInfo
- type Registry
- func (r *Registry) Active() string
- func (r *Registry) ActivePool() (*pgxpool.Pool, error)
- func (r *Registry) Add(name string, cfg ProfileConfig) error
- func (r *Registry) Connect(ctx context.Context, name string) error
- func (r *Registry) Disconnect(name string) error
- func (r *Registry) Get(name string) (*Profile, error)
- func (r *Registry) List() []ProfileInfo
- func (r *Registry) Remove(name string) error
- func (r *Registry) Switch(name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CompatConfig ¶
type CompatConfig struct {
Profiles []CompatProfile `json:"profiles"`
Active string `json:"active"`
}
CompatConfig is the JSON-serializable form of a multi-profile connection config.
type CompatProfile ¶
type CompatProfile struct {
Name string `json:"name"`
Config ProfileConfig `json:"config"`
}
CompatProfile is the JSON-serializable form of a single profile.
type Profile ¶
type Profile struct {
Name string `json:"name"`
Config ProfileConfig `json:"config"`
Pool *pgxpool.Pool `json:"-"`
}
Profile represents a named database connection profile.
type ProfileConfig ¶
type ProfileConfig struct {
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
Database string `json:"database" yaml:"database"`
SSLMode string `json:"sslmode" yaml:"sslmode"`
User string `json:"user" yaml:"user"`
Password string `json:"-" yaml:"-"`
PoolMin int32 `json:"pool_min" yaml:"pool_min"`
PoolMax int32 `json:"pool_max" yaml:"pool_max"`
}
ProfileConfig holds the connection parameters for a PostgreSQL profile.
func (ProfileConfig) DSN ¶
func (c ProfileConfig) DSN() string
DSN returns the PostgreSQL connection string for this config.
type ProfileInfo ¶
type ProfileInfo struct {
Name string `json:"name"`
Host string `json:"host"`
Port int `json:"port"`
Database string `json:"database"`
SSLMode string `json:"sslmode"`
User string `json:"user"`
Connected bool `json:"connected"`
}
ProfileInfo is a serializable representation of a profile (no pool, no password).
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages multiple named PostgreSQL connection profiles.
func (*Registry) ActivePool ¶
ActivePool returns the pgxpool.Pool for the active profile, or an error if no profile is active or the active profile is not connected.
func (*Registry) Add ¶
func (r *Registry) Add(name string, cfg ProfileConfig) error
Add registers a new profile. Returns an error if the name is already taken.
func (*Registry) Disconnect ¶
Disconnect closes the pool for the named profile.
func (*Registry) List ¶
func (r *Registry) List() []ProfileInfo
List returns a sorted slice of ProfileInfo for all registered profiles.