database

package
v1.47.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConnection

func NewConnection(config *Config, environment, appName string) (*gorm.DB, error)

NewConnection returns a new instrumented Gorm database connection.

Types

type Config

type Config struct {
	Host     string `mapstructure:"host"`
	Port     int    `mapstructure:"port"`
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`
	Database string `mapstructure:"database"`
	Timeout  string `mapstructure:"timeout"`
	// Connection settings
	// TODO Pool field name must be modified in the next major change.
	Pool                  int           `mapstructure:"pool"`
	MaxOpenConnections    int           `mapstructure:"max_open_connections"`
	ConnectionMaxIdleTime time.Duration `mapstructure:"connection_max_idle_time"`
	ConnectionMaxLifetime time.Duration `mapstructure:"connection_max_lifetime"`

	// Performance settings
	DisableDefaultGormTransaction bool `mapstructure:"disable_default_gorm_transaction"`
	CachePreparedStatements       bool `mapstructure:"cache_prepared_statements"`
	MysqlInterpolateParams        bool `mapstructure:"mysql_interpolate_params"`
}

Config is the database connection configuration.

func NewConfig

func NewConfig() (*Config, error)

NewConfig returns a new Config instance.

type ConnectionDetails

type ConnectionDetails struct {
	Dialect                string
	Username               string
	Password               string
	Host                   string
	Port                   int
	Database               string
	Encoding               string
	Timeout                string
	Pool                   int
	MysqlInterpolateParams bool
}

ConnectionDetails represents database connection details.

func NewConnectionDetails

func NewConnectionDetails(config *Config) ConnectionDetails

NewConnectionDetails creates a new ConnectionDetails struct from a DB configuration.

func (ConnectionDetails) String

func (cd ConnectionDetails) String() string

String builds a connection string from a database Config.

func (ConnectionDetails) StringWithoutDB

func (cd ConnectionDetails) StringWithoutDB() string

StringWithoutDB builds a connection string from a database Config without the database.

Jump to

Keyboard shortcuts

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