Documentation ¶
Index ¶
Constants ¶
const ( DBDriverUndefined = iota DBDriverSQLite DBDriverPostgres )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConfigPostgres ¶
type ConfigPostgres struct { Host string User string Password string DBName string Port int SslMode bool }
func (ConfigPostgres) GetDSN ¶
func (c ConfigPostgres) GetDSN() string
GetDSN creates the DSN (Data Source Name) string for the postgres database connection.
func (ConfigPostgres) GetGormDialector ¶
func (c ConfigPostgres) GetGormDialector() (gorm.Dialector, error)
type ConfigSQLite ¶
type ConfigSQLite struct { ResolvePathCreateDir bool DSN string // contains filtered or unexported fields }
func (ConfigSQLite) GetGormDialector ¶
func (c ConfigSQLite) GetGormDialector() (gorm.Dialector, error)
type ConnOption ¶
type ConnOption func(*connOptions)
func WithLogger ¶
func WithLogger(writer logger.Writer, config logger.Config) ConnOption
WithLogger configures the logger instance used by the database manager. writer instance allows setting up the log destination. By default, we set it to standard `log.Default()`. config is the gorm logger config that allows setting the log level, etc. by default, we set log level to Warning.
func WithRetries ¶
func WithRetries(maxRetries, retryIntervalSec, jitterLimitSec int) ConnOption
WithRetries configures db connection retries. maxRetries represents number of times the connection request should be retried on failure. one attempt is done regardless. and then re-attempt is done based on this number. i.e. <1 means total 1 attempt. >1 means n+1 attempt in total. retryIntervalSec represents wait time (in seconds) before each retry attempt. jitterLimitSec represents jitter time limit (in seconds), such that a random time interval between 0 and this number is selected and added to the retry interval on each retry attempt to avoid high retry traffic on exact same time from all servers.
type DialectorGetter ¶
type DialectorSwitcher ¶
type DialectorSwitcher struct { ConfigPostgres ConfigSQLite }
func (DialectorSwitcher) Connect ¶
func (conf DialectorSwitcher) Connect(dbType DBDriver, ops ...ConnOption) (*gorm.DB, error)