Documentation ¶
Index ¶
Constants ¶
View Source
const Postgres = "postgres"
Variables ¶
This section is empty.
Functions ¶
func OpenDbConnection ¶
func OpenDbConnection(config DbConnectionConfigProvider) (*gorm.DB, error)
Opens a connection to the database specified in the config. You must call CloseDbConnection at the end of your session!
Types ¶
type BaseConfig ¶
type BaseConfig struct {
IsDebug bool
}
type DbConfig ¶
type DbConfig struct { BaseConfig Host string `json:"host"` Port int `json:"port"` DbName string `json:"dbname"` User string `json:"user"` Password string `json:"password"` ExtraOptions string `json:"options"` }
Database config. Contains values necessary to open a database connection.
type DbConfigSection ¶
type DbConfigSection struct { Host string `json:"host"` Port int `json:"port"` DbName string `json:"dbname"` User string `json:"username"` // Either Password or PasswordPath must be set. Password string `json:"password"` PasswordPath string `json:"passwordPath"` // See http://gorm.io/docs/connecting_to_the_database.html for available options passed, in addition to the above. ExtraOptions string `json:"options"` }
This struct corresponds to the database section of in the config
func (DbConfigSection) GetPFlagSet ¶
func (cfg DbConfigSection) GetPFlagSet(prefix string) *pflag.FlagSet
GetPFlagSet will return strongly types pflags for all fields in DbConfigSection and its nested types. The format of the flags is json-name.json-sub-name... etc.
type DbConnectionConfigProvider ¶
type DbConnectionConfigProvider interface { // Returns the database type. For instance PostgreSQL or MySQL. GetType() string // Returns arguments specific for the database type necessary to open a database connection. GetArgs() string // Enables verbose logging. WithDebugModeEnabled() // Disables verbose logging. WithDebugModeDisabled() // Returns whether verbose logging is enabled or not. IsDebug() bool }
Generic interface for providing a config necessary to open a database connection.
func NewPostgresConfigProvider ¶
func NewPostgresConfigProvider(config DbConfig, scope promutils.Scope) DbConnectionConfigProvider
TODO : Make the Config provider itself env based
type PostgresConfigProvider ¶
type PostgresConfigProvider struct {
// contains filtered or unexported fields
}
PostgreSQL implementation for DbConnectionConfigProvider.
func (*PostgresConfigProvider) GetArgs ¶
func (p *PostgresConfigProvider) GetArgs() string
func (*PostgresConfigProvider) GetType ¶
func (p *PostgresConfigProvider) GetType() string
func (*PostgresConfigProvider) IsDebug ¶
func (p *PostgresConfigProvider) IsDebug() bool
func (*PostgresConfigProvider) WithDebugModeDisabled ¶
func (p *PostgresConfigProvider) WithDebugModeDisabled()
func (*PostgresConfigProvider) WithDebugModeEnabled ¶
func (p *PostgresConfigProvider) WithDebugModeEnabled()
Click to show internal directories.
Click to hide internal directories.