gormdb

package
v0.0.0-...-b4bec84 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrDBNotSetUp get gorm db but not set up.
	ErrDBNotSetUp = errors.New("gorm db not set up")
	// ErrDBNameNotFound config db name not found.
	ErrDBNameNotFound = errors.New("db config dbname not found")
)

Functions

func GetGormDB

func GetGormDB() (*gorm.DB, error)

func GormMySQLByConfig

func GormMySQLByConfig(conf DBConfig) (*gorm.DB, error)

GormMySQLByConfig set up gorm db with mysql config.

func GormPgSQLByConfig

func GormPgSQLByConfig(conf DBConfig) (*gorm.DB, error)

GormPgSQLByConfig set up gorm db with pg config.

func SetUp

func SetUp(conf DBConfig) (*gorm.DB, error)

Types

type DBConfig

type DBConfig struct {
	Type         string `mapstructure:"type" json:"type" yaml:"type"`                             // 类型 mysql/postgresql.
	Host         string `mapstructure:"host" json:"host" yaml:"host"`                             // 服务器地址.
	Port         string `mapstructure:"port" json:"port" yaml:"port"`                             // 端口.
	Config       string `mapstructure:"config" json:"config" yaml:"config"`                       // 高级配置.
	Dbname       string `mapstructure:"dbname" json:"dbname" yaml:"dbname"`                       // 数据库名.
	Username     string `mapstructure:"username" json:"username" yaml:"username"`                 // 数据库用户名.
	Password     string `mapstructure:"password" json:"password" yaml:"password"`                 // 数据库密码.
	MaxIdleConns int    `mapstructure:"max_idle_conns" json:"max_idle_conns" yaml:"maxIdleConns"` // nolint
	MaxOpenConns int    `mapstructure:"max_open_conns" json:"max_open_conns" yaml:"maxOpenConns"` // nolint
	LogLevel     string `mapstructure:"log_level" json:"log_level" yaml:"logLevel"`               // nolint
}

func (*DBConfig) MysqlDsn

func (conf *DBConfig) MysqlDsn() string

func (*DBConfig) PGDsn

func (conf *DBConfig) PGDsn() string

Jump to

Keyboard shortcuts

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