txorm

package
v0.0.0-...-cda2eac Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: GPL-3.0 Imports: 11 Imported by: 1

README

txorm

txorm is a tool to connect to mysql, base on xorm.io/xorm

database(mysql)

  • go get -v trellis.tech/trellis/common.v1/txorm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args(args ...interface{}) []interface{}

func CheckSession

func CheckSession(x interface{}) (*xorm.Session, error)

func Count

func Count(session *xorm.Session, bean interface{}, opts ...GetOption) (int64, error)

func Delete

func Delete(session *xorm.Session, bean interface{}, opts ...DeleteOption) (int64, error)

func Do

func Do(engine *xorm.Engine, fn func(*xorm.Session) error) error

Do to do transaction with customer function

func Find

func Find(session *xorm.Session, bean interface{}, opts ...GetOption) error

func FindAndCount

func FindAndCount(session *xorm.Session, bean interface{}, opts ...GetOption) (int64, error)

func Get

func Get(session *xorm.Session, bean interface{}, opts ...GetOption) (bool, error)

func Insert

func Insert(session *xorm.Session, beans ...interface{}) (int64, error)

func InsertMulti

func InsertMulti(session *xorm.Session, ones interface{}, opts ...InsertMultiOption) (int64, error)

InsertMulti insert multi seperated slice data in a big slice with every step number default to insert the slice with no seperated.

func NewEnginesFromConfig

func NewEnginesFromConfig(cfg config.Config, opts ...Option) (engines map[string]transaction.Engine, err error)

NewEnginesFromConfig initial engines from config

func NewEnginesFromFile

func NewEnginesFromFile(file string) (map[string]transaction.Engine, error)

NewEnginesFromFile initial engines from file

func NewXORMEngine

func NewXORMEngine(driver string, dsn string) (*xorm.Engine, error)

func NewXORMEngines

func NewXORMEngines(cfg config.Config, opts ...Option) (engines map[string]*xorm.Engine, err error)

func NewXORMEnginesFromFile

func NewXORMEnginesFromFile(file string) (map[string]*xorm.Engine, error)

NewXORMEnginesFromFile initial xorm engine from file

func TransactionDo

func TransactionDo(engine *xorm.Engine, fn func(*xorm.Session) error) error

TransactionDo to do transaction with customer function

func TransactionDoWithSession

func TransactionDoWithSession(s *xorm.Session, fn func(*xorm.Session) error) (err error)

TransactionDoWithSession to do transaction with customer function

func Update

func Update(session *xorm.Session, bean interface{}, opts ...UpdateOption) (int64, error)

Types

type BaseRepo

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

func NewBaseRepo

func NewBaseRepo(ss ...*xorm.Session) *BaseRepo

func (*BaseRepo) Count

func (p *BaseRepo) Count(beans interface{}, opts ...GetOption) (int64, error)

func (*BaseRepo) Delete

func (p *BaseRepo) Delete(bean interface{}, opts ...DeleteOption) (int64, error)

func (*BaseRepo) Find

func (p *BaseRepo) Find(beans interface{}, opts ...GetOption) error

func (*BaseRepo) FindAndCount

func (p *BaseRepo) FindAndCount(beans interface{}, opts ...GetOption) (int64, error)

func (*BaseRepo) Get

func (p *BaseRepo) Get(bean interface{}, opts ...GetOption) (bool, error)

func (*BaseRepo) Insert

func (p *BaseRepo) Insert(beans ...interface{}) (int64, error)

func (*BaseRepo) InsertMulti

func (p *BaseRepo) InsertMulti(beans interface{}, opts ...InsertMultiOption) (int64, error)

func (*BaseRepo) SetSession

func (p *BaseRepo) SetSession(x interface{}) error

func (*BaseRepo) Update

func (p *BaseRepo) Update(bean interface{}, opts ...UpdateOption) (int64, error)

type BaseRepository

type BaseRepository interface {
	Get(bean interface{}, opts ...GetOption) (bool, error)
	Find(beans interface{}, opts ...GetOption) error
	FindAndCount(beans interface{}, opts ...GetOption) (int64, error)
	Count(beans interface{}, opts ...GetOption) (int64, error)

	ExecRepository
}

type DeleteOption

type DeleteOption func(*DeleteOptions)

func DeleteArgs

func DeleteArgs(args ...interface{}) DeleteOption

func DeleteIn

func DeleteIn(ins ...*In) DeleteOption

func DeleteNotIn

func DeleteNotIn(ins ...*In) DeleteOption

func DeleteWheres

func DeleteWheres(wheres interface{}) DeleteOption

type DeleteOptions

type DeleteOptions struct {
	Wheres interface{}
	Args   []interface{}

	InWheres    []*In
	NotInWheres []*In
}

type ExecRepository

type ExecRepository interface {
	Insert(...interface{}) (int64, error)
	InsertMulti(beans interface{}, opts ...InsertMultiOption) (int64, error)
	Update(bean interface{}, opts ...UpdateOption) (int64, error)
	Delete(bean interface{}, opts ...DeleteOption) (int64, error)

	transaction.Repo
}

type GetOption

type GetOption func(*GetOptions)

func GetArgs

func GetArgs(args ...interface{}) GetOption

func GetCols

func GetCols(cols ...string) GetOption

func GetDistinct

func GetDistinct(args ...string) GetOption

func GetGroupBy

func GetGroupBy(groupBy string) GetOption

func GetHaving

func GetHaving(having string) GetOption

func GetIn

func GetIn(ins ...*In) GetOption

func GetLimit

func GetLimit(limit, offset int) GetOption

func GetNotIn

func GetNotIn(ins ...*In) GetOption

func GetOrderBy

func GetOrderBy(order string) GetOption

func GetWheres

func GetWheres(wheres interface{}) GetOption

type GetOptions

type GetOptions struct {
	Wheres interface{}
	Args   []interface{}

	InWheres    []*In
	NotInWheres []*In

	Limit, Offset int
	OrderBy       string
	GroupBy       string
	Having        string

	Cols     []string
	Distinct []string
}

func (*GetOptions) Session

func (p *GetOptions) Session(session *xorm.Session) *xorm.Session

type In

type In struct {
	Column string
	Args   []interface{}
}

func InOpts

func InOpts(column string, args ...interface{}) *In

type InsertMultiOption

type InsertMultiOption func(*InsertMultiOptions)

func InsertMultiCheckNumber

func InsertMultiCheckNumber(check ...bool) InsertMultiOption

func InsertMultiStepNumber

func InsertMultiStepNumber(number int) InsertMultiOption

type InsertMultiOptions

type InsertMultiOptions struct {
	StepNumber  int
	CheckNumber bool
}

type Option

type Option func(*Options)

func OptLogger

func OptLogger(l logger.XormLogger) Option

type Options

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

type UpdateOption

type UpdateOption func(*UpdateOptions)

func UpdateArgs

func UpdateArgs(args ...interface{}) UpdateOption

func UpdateCols

func UpdateCols(cols ...string) UpdateOption

func UpdateIn

func UpdateIn(ins ...*In) UpdateOption

func UpdateNotIn

func UpdateNotIn(ins ...*In) UpdateOption

func UpdateWheres

func UpdateWheres(wheres interface{}) UpdateOption

type UpdateOptions

type UpdateOptions struct {
	Wheres interface{}
	Args   []interface{}
	Cols   []string

	InWheres    []*In
	NotInWheres []*In
}

type XEngine

type XEngine struct {
	*xorm.Engine
}

func NewEngine

func NewEngine(driver string, dsn string) (*XEngine, error)

NewEngine New XEngine Deprecated: Use NewXEngine

func NewXEngine

func NewXEngine(driver string, dsn string) (*XEngine, error)

func (*XEngine) BeginNonTransaction

func (p *XEngine) BeginNonTransaction() (transaction.Transaction, error)

func (*XEngine) BeginTransaction

func (p *XEngine) BeginTransaction() (transaction.Transaction, error)

func (*XEngine) Exec

func (p *XEngine) Exec(sql string, args ...interface{}) (sql.Result, error)

func (*XEngine) NewSession

func (p *XEngine) NewSession() (interface{}, error)

func (*XEngine) NewXORMSession

func (p *XEngine) NewXORMSession() (*xorm.Session, error)

func (*XEngine) TransactionDo

func (p *XEngine) TransactionDo(fn func(*xorm.Session) error) error

Jump to

Keyboard shortcuts

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