xormhelper

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SnakeMapper = "snake"
	SameMapper  = "same"
	GonicMapper = "gonic"
)

Variables

View Source
var ConnMaxLifetimeDefault time.Duration = 30 * time.Second
View Source
var MaxIdleConnsDefault int = 16
View Source
var MaxOpenConnsDefault int = 32

Functions

func Close

func Close(params ...string) (err error)
 Close 关闭连接
 范例:
	Close() 关闭名字为default的连接
	Close("my") 关闭名字为my的连接
	Close("my","your") 关闭多个连接
	Close("__all__") 关闭所有的连接。

func Register added in v1.1.0

func Register(poolName, dsn string, params ...string) error

Register 注册一个mysql连接池 范例:

给连接池取个名称
Register("default","test:test@(127.0.0.1:3306)/db?charset=utf8mb4&parseTime=True&loc=Local")
指定表前缀
Register("default","test:test@(127.0.0.1:3306)/db?charset=utf8mb4&parseTime=True&loc=Local","prefix_")
设置调试模式,会打印sql语句
Register("default","test:test@(127.0.0.1:3306)/db?charset=utf8mb4&parseTime=True&loc=Local","prefix_","true")
指定xorm的mapper规则
Register("default","test:test@(127.0.0.1:3306)/db?charset=utf8mb4&parseTime=True&loc=Local","prefix_","true","gonic)

func Using

func Using(params ...string) (*xorm.Session, error)

Using 使用指定的名字的连接池, 不指定默认为default

Types

type Model added in v1.1.0

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

func (*Model) AllCols added in v1.1.0

func (m *Model) AllCols() *Model

func (*Model) And added in v1.1.0

func (m *Model) And(column string, args ...interface{}) *Model

func (*Model) Asc added in v1.1.0

func (m *Model) Asc(colNames ...string) *Model

func (*Model) Cols added in v1.1.0

func (m *Model) Cols(columns ...string) *Model

func (*Model) Count added in v1.1.0

func (m *Model) Count(bean ...interface{}) (int64, error)

func (*Model) Delete added in v1.1.0

func (m *Model) Delete(bean interface{}) (int64, error)

func (*Model) Desc added in v1.1.0

func (m *Model) Desc(colNames ...string) *Model

func (*Model) Distinct added in v1.1.0

func (m *Model) Distinct(columns ...string) *Model

func (*Model) Exist added in v1.1.0

func (m *Model) Exist(bean ...interface{}) (bool, error)

func (*Model) FilterID added in v1.1.0

func (m *Model) FilterID(id interface{}) *Model

func (*Model) FindAll added in v1.1.0

func (m *Model) FindAll(rowsSlicePtr interface{}, condiBean ...interface{}) error

func (*Model) FindAndCount added in v1.1.0

func (m *Model) FindAndCount(rowsSlicePtr interface{}, condiBean ...interface{}) (int64, error)

func (*Model) FindOne added in v1.1.0

func (m *Model) FindOne(bean interface{}) (bool, error)

func (*Model) GroupBy added in v1.1.0

func (m *Model) GroupBy(keys string) *Model

func (*Model) Having added in v1.1.0

func (m *Model) Having(conditions string) *Model

func (*Model) IN added in v1.1.0

func (m *Model) IN(column string, args ...interface{}) *Model

func (*Model) LastSQL added in v1.1.0

func (m *Model) LastSQL() (string, []interface{})

func (*Model) Limit added in v1.1.0

func (m *Model) Limit(limit int, start ...int) *Model

func (*Model) NotIn added in v1.1.0

func (m *Model) NotIn(column string, args ...interface{}) *Model

func (*Model) Or added in v1.1.0

func (m *Model) Or(column string, args ...interface{}) *Model

func (*Model) OrderBy added in v1.1.0

func (m *Model) OrderBy(order string) *Model

func (*Model) Pagination added in v1.1.1

func (m *Model) Pagination(page, pagesize int, data interface{}) (currentPage, currentPagesize, totalRecords, totalPages int, err error)

func (*Model) Rows added in v1.1.0

func (m *Model) Rows(bean interface{}) (*xorm.Rows, error)

func (*Model) SQL added in v1.1.0

func (m *Model) SQL(query interface{}, args ...interface{}) *Model

func (*Model) Save added in v1.1.0

func (m *Model) Save() (int64, error)

func (*Model) SessionInit added in v1.1.0

func (m *Model) SessionInit(session *xorm.Session, tableNameOrBean interface{})

func (*Model) Update added in v1.1.0

func (m *Model) Update() (int64, error)

func (*Model) Where added in v1.1.0

func (m *Model) Where(query interface{}, args ...interface{}) *Model

type XormSession

type XormSession struct {
	Name            string
	DSN             string
	Prefix          string
	Mapper          string
	ConnMaxLifetime time.Duration
	MaxIdleConns    int
	MaxOpenConns    int
	Debug           bool
	// contains filtered or unexported fields
}

func (*XormSession) Close

func (xc *XormSession) Close() error

func (*XormSession) Connect

func (xc *XormSession) Connect() (err error)

func (*XormSession) Register added in v1.0.6

func (xc *XormSession) Register() error

Register

type Xorms

type Xorms struct {
	Engine map[string]*XormSession
	sync.RWMutex
}
var PublicXorms Xorms = Xorms{Engine: make(map[string]*XormSession)}

Jump to

Keyboard shortcuts

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