Documentation ¶
Index ¶
- func AddGormCallbacks(db *gorm.DB)
- type Database
- func (database *Database) GORM(name string) *GORMClient
- func (database *Database) RegisterGORMClient(name string, config *ORMConfig) error
- func (database *Database) RegisterGORMClients(configs map[string]*ORMConfig) error
- func (database *Database) RegisterORMClient(name string, config *ORMConfig) error
- func (database *Database) RegisterORMClients(configs map[string]*ORMConfig) error
- type GORMClient
- func (client *GORMClient) Client() *gorm.DB
- func (client *GORMClient) Close() error
- func (client *GORMClient) Connect() error
- func (client *GORMClient) Name() string
- func (client *GORMClient) Ping() error
- func (client *GORMClient) Reconnect() error
- func (client *GORMClient) SetLogger(log logger.Log)
- func (client *GORMClient) WithCtx(ctx context.Context) *gorm.DB
- type GORMClientManager
- type ORMConfig
- type ORMConfigs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddGormCallbacks ¶
AddGormCallbacks adds callbacks for tracing, you should call SetSpanToGorm to make them work
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
----------------------------------------
数据库客户端管理器
----------------------------------------
func (*Database) GORM ¶
func (database *Database) GORM(name string) *GORMClient
获取一个已经注册的 GORM 客户端(如果未注册将返回 nil)
func (*Database) RegisterGORMClient ¶
注册一个 GORM 客户端实例
func (*Database) RegisterGORMClients ¶
注册多个 GORM 客户端实例
func (*Database) RegisterORMClient ¶
注册一个 ORM 客户端实例(支持 XORM 和 GORM)
type GORMClient ¶
type GORMClient struct {
// contains filtered or unexported fields
}
----------------------------------------
GORM 客户端
----------------------------------------
func CreateGORMClient ¶
func CreateGORMClient(name string, config *ORMConfig) (*GORMClient, error)
创建 GORM 客户端实例
type GORMClientManager ¶
type GORMClientManager struct {
// contains filtered or unexported fields
}
----------------------------------------
GORM 客户端管理器
----------------------------------------
func (*GORMClientManager) Get ¶
func (manager *GORMClientManager) Get(name string) *GORMClient
获取给定名称的 GORM 客户端实例(如果客户端不存在则返回 nil)
func (*GORMClientManager) Set ¶
func (manager *GORMClientManager) Set(name string, client *GORMClient)
添加或更新 GORM 客户端实例
type ORMConfig ¶
type ORMConfig struct { Engine string `toml:"engine" mapstructure:"engine"` Driver string `toml:"driver" mapstructure:"driver"` Host string `toml:"host" mapstructure:"host"` Port int `toml:"port" mapstructure:"port"` Username string `toml:"username" mapstructure:"username"` Password string `toml:"password" mapstructure:"password"` Database string `toml:"database" mapstructure:"database"` Charset string `toml:"charset" mapstructure:"charset"` MaxConn int `toml:"max_conn" mapstructure:"max_conn"` MaxIdleConn int `toml:"max_idle_conn" mapstructure:"max_idle_conn"` Ping bool `toml:"ping" mapstructure:"ping"` }
----------------------------------------
ORM 配置项(TOML 支持, Viper 支持)
----------------------------------------
type ORMConfigs ¶
----------------------------------------
ORM 配置集合(TOML 支持)
----------------------------------------