dao

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2019 License: MIT Imports: 5 Imported by: 0

README

xorm mysql dao

基于github.com/go-xorm/xorm v0.7.1封装而成的dao操作库

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseAllEngine

func CloseAllEngine()

由于xorm db.Close()是关闭当前连接,一般建议如下函数放在main/init关闭连接就可以

func CloseAllEngineGroup

func CloseAllEngineGroup()

=============================读写分离,关闭连接对象,辅助函数==================== 关闭所有的读写分离连接句柄对象

func CloseEngineByName

func CloseEngineByName(name string) error

关闭指定name的db engine

func CloseEngineGroupByName

func CloseEngineGroupByName(name string) error

根据读写分离的句柄名称关闭连接对象

func GetEngine

func GetEngine(name string) (*xorm.Engine, error)

从db pool获取一个数据库连接句柄 根据数据库连接句柄name获取指定的连接句柄

func GetEngineGroup

func GetEngineGroup(name string) (*xorm.EngineGroup, error)

通过name获取读写分离的句柄对象,并非真正建立连接,只有在使用的时候才会建立连接

func SetEngineGroup

func SetEngineGroup(masterEngine *xorm.Engine, slave1Engine ...*xorm.Engine) (*xorm.EngineGroup, error)

======================读写分离设置================== 读写分离,masterEngine,slaveEngine可以多个

func SetEngineGroupName

func SetEngineGroupName(name string, engineGroup *xorm.EngineGroup)

给读写分离的dbGroup设置name,一般用于业务上游层调度

Types

type DbConf

type DbConf struct {
	Ip           string
	Port         int
	User         string
	Password     string
	Database     string
	Charset      string //字符集 utf8mb4 支持表情符号
	Collation    string //整理字符集 utf8mb4_unicode_ci
	MaxIdleConns int    //空闲pool个数
	MaxOpenConns int    //最大open connection个数
	ParseTime    bool
	Loc          string //时区字符串 Local,PRC

	SqlCmd  bool //sql语句是否输出到终端,true输出到终端
	UsePool bool //当前db实例是否采用db连接池,默认不采用,如采用请求配置该参数
	// contains filtered or unexported fields
}

mysql连接信息 parseTime=true changes the output type of DATE and DATETIME values to time.Time instead of []byte / string The date or datetime like 0000-00-00 00:00:00 is converted into zero value of time.Time.

func (*DbConf) Close

func (conf *DbConf) Close() error

func (*DbConf) Db

func (conf *DbConf) Db() (*xorm.Engine, error)

返回当前db实例对象,并非立即连接db,用的时候才会真正的建立连接

func (*DbConf) SetEngine

func (conf *DbConf) SetEngine() error

创建当前数据库db对象,并非连接,在使用的时候才会真正建立db连接

func (*DbConf) SetEngineName

func (conf *DbConf) SetEngineName(name string)

给当前数据库指定engineName

func (*DbConf) ShortConnect

func (conf *DbConf) ShortConnect() error

短连接设置,一般用于短连接服务的数据库句柄

Jump to

Keyboard shortcuts

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