database

package
v0.0.0-...-aadc1fd Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDSN

func BuildDSN(config Config) string

Types

type Config

type Config struct {
	Host              string `koanf:"host"`
	Port              int    `koanf:"port"`
	Username          string `koanf:"user"`
	Password          string `koanf:"password"`
	DBName            string `koanf:"db_name"`
	Schema            string `koanf:"schema"`
	SSLMode           string `koanf:"ssl_mode"`
	MaxConns          int32  `koanf:"max_conns"`
	MinConns          int32  `koanf:"min_conns"`
	MaxConnLifetime   int    `koanf:"max_conn_lifetime"`
	MaxConnIdleTime   int    `koanf:"max_conn_idle_time"`
	HealthCheckPeriod int    `koanf:"health_check_period"`
	PathOfMigrations  string `koanf:"path_of_migrations"`
}

Config represents the configuration for a database connection.

func NewConfig

func NewConfig(opts ...ConfigOption) Config

NewConfig creates a new Config with default values and applies the provided options.

type ConfigOption

type ConfigOption func(*Config)

ConfigOption defines a function that modifies a Config.

func WithDBName

func WithDBName(dbName string) ConfigOption

WithDBName sets the DBName field of the Config.

func WithHealthCheckPeriod

func WithHealthCheckPeriod(healthCheckPeriod int) ConfigOption

WithHealthCheckPeriod sets the HealthCheckPeriod field of the Config.

func WithHost

func WithHost(host string) ConfigOption

WithHost sets the Host field of the Config.

func WithMaxConnIdleTime

func WithMaxConnIdleTime(maxConnIdleTime int) ConfigOption

WithMaxConnIdleTime sets the MaxConnIdleTime field of the Config.

func WithMaxConnLifetime

func WithMaxConnLifetime(maxConnLifetime int) ConfigOption

WithMaxConnLifetime sets the MaxConnLifetime field of the Config.

func WithMaxConns

func WithMaxConns(maxConns int32) ConfigOption

WithMaxConns sets the MaxConns field of the Config.

func WithMinConns

func WithMinConns(minConns int32) ConfigOption

WithMinConns sets the MinConns field of the Config.

func WithPassword

func WithPassword(password string) ConfigOption

WithPassword sets the Password field of the Config.

func WithPathOfMigrations

func WithPathOfMigrations(pathOfMigrations string) ConfigOption

WithPathOfMigrations sets the PathOfMigrations field of the Config.

func WithPort

func WithPort(port int) ConfigOption

WithPort sets the Port field of the Config.

func WithSSLMode

func WithSSLMode(sslMode string) ConfigOption

WithSSLMode sets the SSLMode field of the Config.

func WithUsername

func WithUsername(username string) ConfigOption

WithUsername sets the Username field of the Config.

type Database

type Database struct {
	Pool *pgxpool.Pool
}

func Connect

func Connect(config Config) (*Database, error)

func (*Database) Close

func (db *Database) Close()

Jump to

Keyboard shortcuts

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