tgorm

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

README

tgorm

tgorm is a tool to connect to mysql, base on github.com/jinzhu/gorm

database(mysql)

Documentation

Index

Constants

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

Function Flags

View Source
const (
	DefaultDatabase = "go-trellis::tgorm::default"
)

defines

Variables

View Source
var (
	ErrFailToExecuteLogicFunction = errors.TN(_namespace, 10001, "{{.message}}")

	// define orm errors
	ErrNotFoundDefaultDatabase    = errors.TN(_namespace, 20000, "not found default database")
	ErrAtLeastOneRepo             = errors.TN(_namespace, 20001, "input one repo at least")
	ErrNotFoundTransationFunction = errors.TN(_namespace, 20002, "not found transation function")
	ErrStructCombineWithRepo      = errors.TN(_namespace, 20003, "your repository struct should combine with {{.name}} repo")
	ErrFailToCreateRepo           = errors.TN(_namespace, 20004, "fail to create an new repo")
	ErrFailToDerive               = errors.TN(_namespace, 20005, "fail to derive: {{.message}}")
	ErrFailToInherit              = errors.TN(_namespace, 20006, "fail to inherit: {{.message}}")
	ErrFailToConvetTXToNonTX      = errors.TN(_namespace, 20007, "could not convert TX to NON-TX")
	ErrFailToCreateTransaction    = errors.TN(_namespace, 20008, "fail to create transaction: {{.message}}")
	ErrTransactionIsAlreadyBegin  = errors.TN(_namespace, 20009, "transaction is already begin: {{.name}}")
	ErrNonTransactionCantCommit   = errors.TN(_namespace, 20010, "non-transaction can't commit")
	ErrTransactionSessionIsNil    = errors.TN(_namespace, 20011, "transaction session is nil")
	ErrFailToCommitTransaction    = errors.TN(_namespace, 20012, "fail to commit transaction")
	ErrNotFoundGormDB             = errors.TN(_namespace, 20013, "not found gorm engine with {{.name}}")
)

define connector errors

Functions

func AddErrorTypes

func AddErrorTypes(errType reflect.Type)

AddErrorTypes 增加支持的错误类型

func CallFunc

func CallFunc(fn interface{}, funcs LogicFuncs, args []interface{}) ([]interface{}, errors.ErrorCode)

CallFunc execute transaction function with logic functions and args

func DeepFields

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

DeepFields relect interface deep fields

func Derive

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

Derive derive from developer function

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 inherit a new repository from origin repository

func NewDBsFromConfig

func NewDBsFromConfig(conf config.Config, name string) (map[string]*gorm.DB, error)

NewDBsFromConfig initial gorm engine from config

func NewDBsFromFile

func NewDBsFromFile(file string) (map[string]*gorm.DB, error)

NewDBsFromFile initial gorm dbs from file

Types

type Committer

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

Committer Defination

func NewCommitter

func NewCommitter() Committer

NewCommitter get trellis gorm committer

type Deriver

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

Deriver derive function

type Inheritor

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

Inheritor inherit function

type LogicFuncs

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

LogicFuncs logic functions

func GetLogicFuncs

func GetLogicFuncs(fn interface{}) (funcs LogicFuncs)

GetLogicFuncs reflect logic function

type TGorm

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

TGorm trellis gorm

func (*TGorm) Session

func (p *TGorm) Session() *gorm.DB

Session get session

func (*TGorm) SetDBs

func (p *TGorm) SetDBs(dbs map[string]*gorm.DB)

SetDBs set gorm dbs

type TXFunc

type TXFunc func(repos []interface{}) errors.ErrorCode

TXFunc Transation function

Jump to

Keyboard shortcuts

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