gxorm

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2019 License: MIT Imports: 6 Imported by: 0

README

gxorm

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

参考手册

https://github.com/go-xorm/xorm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseAllDb

func CloseAllDb()

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

func CloseDbByName

func CloseDbByName(name string) error

CloseDbByName 关闭指定name的db engine

func GetEngine

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

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

func NewEngineGroup

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

======================读写分离设置================== NewEngineGroup 设置读写分离db engine slaveEngine可以多个 返回读写分离的db engine

func NewEngineGroupWithOption added in v1.8.1

func NewEngineGroupWithOption(m *xorm.Engine, s []*xorm.Engine, opt *EngineGroupOption) (*xorm.EngineGroup, error)

NewEngineGroupWithOption 创建读写分离的引擎组,附带一些拓展配置 这里可以采用功能模式,方便后面对引擎组句柄进行拓展

Types

type DbConf

type DbConf struct {
	Ip        string
	Port      int
	User      string
	Password  string
	Database  string
	Charset   string //字符集 utf8mb4 支持表情符号
	Collation string //整理字符集 utf8mb4_unicode_ci
	ParseTime bool
	Loc       string //时区字符串 Local,PRC

	MaxIdleConns int  //设置连接池的空闲数大小
	MaxOpenConns int  //最大open connection个数
	SqlCmd       bool //sql语句是否输出到终端,true输出到终端
	UsePool      bool //当前db实例是否采用db连接池,默认不采用,如采用请求配置该参数
	ShowExecTime bool //是否打印sql执行时间
}

DbConf 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) InitDbEngine added in v1.8.1

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

InitDbEngine new a db engine

func (*DbConf) NewEngine added in v1.8.1

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

NewEngine create a db engine 如果配置上有显示sql执行时间和采用pool机制,就会建立db连接池

func (*DbConf) SetEngineName

func (conf *DbConf) SetEngineName(name string) error

SetEngineName 给当前数据库指定engineName 一般用在多个db 数据库连接引擎的时候,可以给当前的db engine设置一个name 这样业务上游层,就可以通过 GetEngine(name)获得当前db engine

func (*DbConf) ShortConnect

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

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

type EngineGroupOption added in v1.8.1

type EngineGroupOption struct {
	MaxIdleConns int  //设置连接池的空闲数大小
	MaxOpenConns int  //最大open connection个数
	SqlCmd       bool //sql语句是否输出到终端,true输出到终端
	ShowExecTime bool //是否打印sql执行时间
	MaxLifetime  time.Duration
}

EngineGroupOption 读写分离引擎组其他参数

Jump to

Keyboard shortcuts

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