Documentation ¶
Overview ¶
Package db database plugin based on xorm.
Index ¶
- func Transaction(ctx context.Context, handlers ...TransactionHandler) error
- func TransactionWithSession(ctx context.Context, sess *xorm.Session, handlers ...TransactionHandler) (err error)
- type Configuration
- type Connection
- func (o *Connection) GetEngineGroup(keys ...string) (engine *xorm.EngineGroup)
- func (o *Connection) GetMaster(keys ...string) *xorm.Session
- func (o *Connection) GetMasterWithContext(ctx context.Context, keys ...string) *xorm.Session
- func (o *Connection) GetSlave(keys ...string) *xorm.Session
- func (o *Connection) GetSlaveWithContext(ctx context.Context, keys ...string) *xorm.Session
- type Database
- type Service
- type TransactionHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transaction ¶
func Transaction(ctx context.Context, handlers ...TransactionHandler) error
Transaction 创建事务.
func TransactionWithSession ¶
func TransactionWithSession(ctx context.Context, sess *xorm.Session, handlers ...TransactionHandler) (err error)
TransactionWithSession 基于指定连接创建事务.
Types ¶
type Configuration ¶
type Configuration struct { // 数据源列表. Databases map[string]*Database `yaml:"databases"` // contains filtered or unexported fields }
Configuration 配置参数.
var ( // Config // 应用于IRIS的配置. Config *Configuration )
func (*Configuration) GetDatabase ¶
func (o *Configuration) GetDatabase(key string) *Database
GetDatabase 按Key名称读取数据源.
func (*Configuration) GetUndefined ¶ added in v5.1.1
func (o *Configuration) GetUndefined() *Database
GetUndefined 读取数据源.
func (*Configuration) SetDatabase ¶
func (o *Configuration) SetDatabase(key string, database *Database)
SetDatabase 设置数据源.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection 连接管理接口.
var ( // Connector // 连接管理. Connector *Connection )
func (*Connection) GetEngineGroup ¶
func (o *Connection) GetEngineGroup(keys ...string) (engine *xorm.EngineGroup)
GetEngineGroup 读取XORM引擎组.
func (*Connection) GetMaster ¶
func (o *Connection) GetMaster(keys ...string) *xorm.Session
GetMaster 从Master获取Session.
func (*Connection) GetMasterWithContext ¶
GetMasterWithContext 基于Context从Master获取Session.
func (*Connection) GetSlave ¶
func (o *Connection) GetSlave(keys ...string) *xorm.Session
GetSlave 从Slave获取Session.
func (*Connection) GetSlaveWithContext ¶
GetSlaveWithContext 基于Context从Slave获取Session.
type Database ¶
type Database struct { Driver string `yaml:"driver"` Dsn []string `yaml:"dsn"` EnableSession *bool `yaml:"enable-session"` MaxIdle int `yaml:"max-idle"` MaxLifetime int `yaml:"max-lifetime"` MaxOpen int `yaml:"max-open"` Mapper string `yaml:"mapper"` ShowSQL *bool `yaml:"show-sql"` // contains filtered or unexported fields }
Database 数据源定义.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 服务封装.
func (*Service) UseConnection ¶
UseConnection 绑定连接名.
Click to show internal directories.
Click to hide internal directories.