txorm

package
v0.0.0-...-5bcacdd Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2021 License: GPL-3.0 Imports: 10 Imported by: 1

README

xorm_ext

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

database(mysql)

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

Documentation

Index

Constants

View Source
const (
	Logic = iota
	BeforeLogic
	AfterLogic
	OnError
	AfterCommit
)

Function Flags

Variables

View Source
var (
	ErrNotFoundDefaultDatabase     = errcode.New("not found default database")
	ErrAtLeastOneRepo              = errcode.New("input one repo at least")
	ErrNotFoundTransactionFunction = errcode.New("not found transaction function")
	ErrStructCombineWithRepo       = errcode.New("your repository struct should combine repo")
	ErrFailToCreateRepo            = errcode.New("fail to create an new repo")
	ErrFailToConvertTXToNonTX      = errcode.New("could not convert TX to NON-TX")
	ErrTransactionIsAlreadyBegin   = errcode.New("transaction is already begin")
	ErrNonTransactionCantCommit    = errcode.New("non-transaction can't commit")
	ErrTransactionSessionIsNil     = errcode.New("transaction session is nil")
	ErrNotFoundXormEngine          = errcode.New("not found xorm engine")
)

define connector errors

View Source
var (
	DefaultDatabase = common.FormatNamespaceString("xorm_ext:database")
)

DefaultDatabase default database key

Functions

func AddErrorTypes

func AddErrorTypes(errType reflect.Type)

AddErrorTypes 增加支持的错误类型

func CallFunc

func CallFunc(input interface{}, args ...interface{}) ([]interface{}, error)

CallFunc execute transaction function with logic functions and args

func DeepFields

func DeepFields(iface interface{}, vType reflect.Type, fields []reflect.Value) interface{}

DeepFields reflect interface deep fields

func Derive

func Derive(origin interface{}) (interface{}, error)

Derive derive from developer function

func Get

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

func GetMysqlDSNFromConfig

func GetMysqlDSNFromConfig(name string, conf config.Config) string

GetMysqlDSNFromConfig get mysql dsn from gogap config

func Inherit

func Inherit(new, origin interface{}) error

Inherit new repository from origin repository

func InsertMulti

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

InsertMulti insert multi seperated data in a big data for every step

func NewEnginesFromConfig

func NewEnginesFromConfig(conf config.Config) (engines map[string]*xorm.Engine, err error)

NewEnginesFromConfig initial xorm engine from config

func NewEnginesFromDSN

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

NewEnginesFromDSN initial xorm engine by dsn

func NewEnginesFromFile

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

NewEnginesFromFile initial xorm engine from file

func TransactionDo

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

TransactionDo to do transaction with customer function

func Update

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

Types

type Committer

type Committer interface {
	TX(fn interface{}, repos ...interface{}) error
	TXWithName(fn interface{}, name string, repos ...interface{}) error
	NonTX(fn interface{}, repos ...interface{}) error
	NonTXWithName(fn interface{}, name string, repos ...interface{}) error
}

Committer 事务处理者

func NewCommitter

func NewCommitter() Committer

NewCommitter get trellis gorm committer

type Derivative

type Derivative interface {
	Derive() (repo interface{}, err error)
}

Derivative derive function

type GetOption

type GetOption func(*GetOptions)

func GetArgs

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

func GetLimit

func GetLimit(limit, offset int) GetOption

func GetOrderBy

func GetOrderBy(order string) GetOption

func GetWheres

func GetWheres(wheres interface{}) GetOption

type GetOptions

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

	Limit, Offset int
	OrderBy       string
}

type Inheritor

type Inheritor interface {
	Inherit(repo interface{}) error
}

Inheritor inherit function

type LogicFunc

type LogicFunc struct {
	BeforeLogic interface{}
	AfterLogic  interface{}
	OnError     interface{}
	Logic       interface{}
	AfterCommit interface{}
}

LogicFunc logic functions

func GetLogicFunc

func GetLogicFunc(input interface{}) *LogicFunc

GetLogicFunc reflect logic function

type Repo

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

Repo trellis xorm

func (*Repo) BeginNonTransaction

func (p *Repo) BeginNonTransaction(name string) error

func (*Repo) BeginTransaction

func (p *Repo) BeginTransaction(name string) error

func (*Repo) Session

func (p *Repo) Session() *xorm.Session

Session get session

func (*Repo) SetEngines

func (p *Repo) SetEngines(engines map[string]*xorm.Engine)

SetEngines set xorm engines

type TXFunc

type TXFunc func(repos ...interface{}) error

TXFunc Transaction function

type Transaction

type Transaction interface {
	SetEngines(engines map[string]*xorm.Engine)
	Session() *xorm.Session
	BeginTransaction(name string) error
	BeginNonTransaction(name string) error
}

Transaction 事务处理对象 TODO: Engines 为一个option,可以支持redis等

func New

func New() Transaction

New get trellis xorm committer

type UpdateOption

type UpdateOption func(*UpdateOptions)

func UpdateArgs

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

func UpdateCols

func UpdateCols(cols ...string) UpdateOption

func UpdateWheres

func UpdateWheres(wheres interface{}) UpdateOption

type UpdateOptions

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

Jump to

Keyboard shortcuts

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