database

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConnection

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

NewConnection returns a new 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"`
}

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
}

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