Help us shape the future of Go! Take the 2026 Go Developer Survey

dbpool

package
v1.12.10 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, datas ...any)

func SetObject

func SetObject(oj *DbPool)

Types

type Component

type Component struct {
	Object *DbPool
}

func (*Component) Close

func (d *Component) Close()

func (*Component) Init

func (d *Component) Init(data map[string]any) error

初始化

type Config

type Config struct {
	DbType   string            `yaml:"db_type,omitempty"`  // 数据库类型,默认为mysql
	DbName   string            `yaml:"dbname,omitempty"`   // 数据库名称
	Db       uint32            `yaml:"db,omitempty"`       // 数据库编号
	User     string            `yaml:"user,omitempty"`     // 数据库用户名
	Password string            `yaml:"password,omitempty"` // 数据库密码
	Host     string            `yaml:"host,omitempty"`     // 数据库主机地址
	Port     uint32            `yaml:"port,omitempty"`     // 数据库端口
	Slaves   map[int32]*Config `yaml:"slaves,omitempty"`   // 从库配置列表
}

Config 数据库分片配置

type DbPool

type DbPool struct {
	// contains filtered or unexported fields
}

func NewDbPool

func NewDbPool(f func(string) IClient) *DbPool

func (*DbPool) Close

func (d *DbPool) Close()

func (*DbPool) Get

func (d *DbPool) Get(name string) IClient

func (*DbPool) Init

func (d *DbPool) Init(cfgs map[string]*Config) error

初始化全局数据库

type IClient

type IClient interface {
	Init(*Config, ...any) error
	Close() error
	Connect() error
	Ping() error
	IsAlive() bool
	Engine() *xorm.EngineGroup
	NewSession() *xorm.Session
}

func Get

func Get(name string) IClient

Directories

Path Synopsis
adapter
internal

Jump to

Keyboard shortcuts

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