postgresconn

package
v1.3.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyPoolTuning

func ApplyPoolTuning(db *gorm.DB, config *Config) error

ApplyPoolTuning applies MaxIdleConns, MaxOpenConns, and ConnMaxLifetime.

func BuildDSN

func BuildDSN(config *Config) string

BuildDSN assembles a libpq-style DSN from the validated config.

func Close

func Close(db *gorm.DB, logger schemas.Logger)

Close closes the *sql.DB backing a *gorm.DB, logging any error.

func Open

func Open(dsn string, config *Config, logger gormlogger.Interface) (*gorm.DB, error)

Open opens a *gorm.DB against the configured Postgres instance.

func RunPasswordCommand

func RunPasswordCommand(ctx context.Context, config *PasswordCommandConfig) (string, error)

RunPasswordCommand executes a configured password command and returns stdout.

func Validate

func Validate(config *Config, requireStaticPassword bool) error

Validate checks required Postgres connection fields.

Types

type Config

type Config struct {
	Host            *schemas.EnvVar        `json:"host"`
	Port            *schemas.EnvVar        `json:"port"`
	User            *schemas.EnvVar        `json:"user"`
	Password        *schemas.EnvVar        `json:"password"`
	PasswordCommand *PasswordCommandConfig `json:"password_command,omitempty"`
	DBName          *schemas.EnvVar        `json:"db_name"`
	SSLMode         *schemas.EnvVar        `json:"ssl_mode"`
	MaxIdleConns    int                    `json:"max_idle_conns"`
	MaxOpenConns    int                    `json:"max_open_conns"`
	ConnMaxLifetime string                 `json:"conn_max_lifetime,omitempty"`
}

Config is the shared Postgres connection configuration used by framework stores.

type PasswordCommandConfig

type PasswordCommandConfig struct {
	Command string   `json:"command"`
	Args    []string `json:"args,omitempty"`
	Timeout string   `json:"timeout,omitempty"`
}

PasswordCommandConfig describes a command that prints a Postgres password to stdout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL