Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func LoadGenericDBConfig ¶ added in v1.1.34
func LoadGenericDBConfig(fileName string, genericDBConfigMap *GenericDBConfigMap) error
LoadGenericDBConfig reads a config yaml file Sapple config file : databases:
- type: mysql name: my-mysql-db host: myMysqlHost database: myMysqlDatabase user: myMysqlUser password: myMysqlPassword port: 3306
- type: postgre name: my-postgres-db host: myPostgresHost database: myPostgresDatabase user: myPostgresUser password: myPostgresPassword port: 5432
Types ¶
type DBConfig ¶
type DBConfig struct { Host string `default:"127.0.0.1" json:"host"` Database string `required:"true" json:"database"` User string `default:"root" json:"user"` Password string `required:"true" env:"MysqlPassword"` Port uint `default:"3306" json:"port"` }
func LoadMySQLConfig ¶
LoadMySQLConfig returns the mysql connection config
type DBNameType ¶ added in v1.1.34
type DBNameType string
type GenericDBConfig ¶ added in v1.1.34
type GenericDBConfig struct { Name DBNameType `required:"true" json:"name"` // database connection name, ex : orders-mysql Type string `required:"true" json:"type"` // mysql/postgre Host string `required:"true" json:"host"` Database string `required:"true" json:"database"` User string `required:"true" json:"user"` Password string `required:"true"` Port uint `required:"true" json:"port"` }
GenericDBConfig holds database config for MySQL/Postgre/...
func (*GenericDBConfig) Connect ¶ added in v1.1.34
func (dbConfig *GenericDBConfig) Connect() (*gorm.DB, error)
Connect connects to the database
func (*GenericDBConfig) DSN ¶ added in v1.1.34
func (dbConfig *GenericDBConfig) DSN() (string, error)
DSN returns the connection string corresponding to the database type
func (*GenericDBConfig) Validate ¶ added in v1.1.34
func (dbConfig *GenericDBConfig) Validate() error
type GenericDBConfigMap ¶ added in v1.1.34
type GenericDBConfigMap map[DBNameType]GenericDBConfig
GenericDBConfigMap holds the database configs by name
Click to show internal directories.
Click to hide internal directories.