mbt

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MSessionPtr      = `*mbt.ISession`
	MSession         = `mbt.ISession`
	GoMybatisTime    = `time.Time`
	GoMybatisTimePtr = `*time.Time`
	DefaultOneArg    = `arg` //默认参数前缀,例如arg0 arg1 arg2 ....
)
View Source
const (
	ElementMapper = "mapper"
	ID            = `id`
)
View Source
const AdapterFormatDate = `2006-01-02 15:04:05`
View Source
const SessionFunc = "Session"

(原NewSessionFunc)Session method,auto write implement body code

Variables

View Source
var (
	IntType   = reflect.TypeOf(intDefault)
	Int8Type  = reflect.TypeOf(int8Default)
	Int16Type = reflect.TypeOf(int16Default)
	Int32Type = reflect.TypeOf(int32Default)
	Int64Type = reflect.TypeOf(int64Default)

	UintType   = reflect.TypeOf(uintDefault)
	Uint8Type  = reflect.TypeOf(uint8Default)
	Uint16Type = reflect.TypeOf(uint16Default)
	Uint32Type = reflect.TypeOf(uint32Default)
	Uint64Type = reflect.TypeOf(uint64Default)

	Float32Type = reflect.TypeOf(float32Default)
	Float64Type = reflect.TypeOf(float64Default)

	Complex64Type  = reflect.TypeOf(complex64Default)
	Complex128Type = reflect.TypeOf(complex128Default)

	StringType = reflect.TypeOf(emptyString)
	BoolType   = reflect.TypeOf(boolDefault)
	ByteType   = reflect.TypeOf(byteDefault)
	BytesType  = reflect.SliceOf(ByteType)

	TimeType = reflect.TypeOf(timeDefault)
)
View Source
var (
	PtrIntType   = reflect.PtrTo(IntType)
	PtrInt8Type  = reflect.PtrTo(Int8Type)
	PtrInt16Type = reflect.PtrTo(Int16Type)
	PtrInt32Type = reflect.PtrTo(Int32Type)
	PtrInt64Type = reflect.PtrTo(Int64Type)

	PtrUintType   = reflect.PtrTo(UintType)
	PtrUint8Type  = reflect.PtrTo(Uint8Type)
	PtrUint16Type = reflect.PtrTo(Uint16Type)
	PtrUint32Type = reflect.PtrTo(Uint32Type)
	PtrUint64Type = reflect.PtrTo(Uint64Type)

	PtrFloat32Type = reflect.PtrTo(Float32Type)
	PtrFloat64Type = reflect.PtrTo(Float64Type)

	PtrComplex64Type  = reflect.PtrTo(Complex64Type)
	PtrComplex128Type = reflect.PtrTo(Complex128Type)

	PtrStringType = reflect.PtrTo(StringType)
	PtrBoolType   = reflect.PtrTo(BoolType)
	PtrByteType   = reflect.PtrTo(ByteType)

	PtrTimeType = reflect.PtrTo(TimeType)
)
View Source
var (
	XmlLogicEnable   = `logic_enable="true" logic_undelete="1" logic_deleted="0"`
	XmlVersionEnable = `version_enable="true"`
	ResultItem       = `<result column="#{column}" langType="#{langType}" #{version} #{logic}/>`
)
View Source
var XmlData = `` /* 711-byte string literal not displayed */

Functions

func AopProxyService

func AopProxyService(service interface{}, engine IEngine)

使用AOP切面 代理目标服务,如果服务panic()它的事务会回滚 默认为单协程模型,如果是多协程调用的情况请开启engine.SetGoroutineIDEnable(true)

func AopProxyServiceValue

func AopProxyServiceValue(service reflect.Value, engine IEngine)

使用AOP切面 代理目标服务,如果服务panic()它的事务会回滚

func ByteConvertXml added in v1.0.4

func ByteConvertXml(bytes []byte) (items map[string]etree.Token)

ByteConvertXml(原LoadMapperXml): 将输入的 byte 形式的 xml 文件转换成 map[string]etree.Token形式的 xml

返回值 map[string]etree.Token 就是个这么个玩意儿,例如:
 &{ select [{ id selectByIds} { resultMap BaseResultMap}] [0xc0000de260 0xc0000b04e0 0xc0000de2c0 0xc0000b05a0 0xc0000de460 0xc0000b0720 0xc0000de4c0] 0xc0000b0300}
 &{ select [{ id selectByIdsMap}] [0xc0000de520 0xc0000b0840 0xc0000de5a0] 0xc0000b0300}
 &{ update [{ id updateById}] [0xc0000de600 0xc0000b0960 0xc0000de8e0] 0xc0000b0300}
 &{ select [{ id choose} { resultMap BaseResultMap}] [0xc0000de940 0xc0000b0d20 0xc0000deb00] 0xc0000b0300}

func CreateXml

func CreateXml(tableName string, bean interface{}) []byte

根据结构体 创建xml文件.注意 结构体json对应的是数据库的column

func IsDir added in v1.0.1

func IsDir(path string) bool

判断所给路径是否为文件夹 返回true是文件夹,false不是文件夹

func IsExist added in v1.0.1

func IsExist(path string) bool

判断所给路径文件/文件夹是否存在 返回 ture存在,false不存在

func IsFile added in v1.0.1

func IsFile(path string) bool

判断所给路径是否为文件 返回 true是文件,false不是文件

func OutPutXml

func OutPutXml(pointer interface{}, xmlFilePath string)

输出文件 参数<pointer>为struct/*struct

func Proxy

func Proxy(proxyPtr interface{}, buildFunc func(funcField reflect.StructField, field reflect.Value) func(arg ProxyArg) []reflect.Value)

AopProxy 可写入每个函数代理方法.proxyPtr:代理对象指针,buildFunc:构建代理函数

func ProxyValue

func ProxyValue(mapperValue reflect.Value, buildFunc func(funcField reflect.StructField, field reflect.Value) func(arg ProxyArg) []reflect.Value)

AopProxy 可写入每个函数代理方法

func Snake

func Snake(arg interface{}) string

(原StructToSnakeString)结构体名称转蛇形名称 例如 pcLink = pc_link

func SnakeStr

func SnakeStr(s string) string

(原SnakeString)转蛇形命名snake string, XxYy to xx_yy , XxYY to xx_yy

Types

type Config added in v1.0.2

type Config struct {
	DriverName      string        // 驱动名称。例如: mysql,postgreSQL...
	DSN             string        // 数据库连接信息。例如: "root:root@(127.0.0.1:3306)/test?charset=utf8&parseTime=True&loc=Local"
	MaxOpenConn     int           // 最大的并发打开连接数。例如: 这个值是5则表示==>连接池中最多有5个并发打开的连接,如果5个连接都已经打开被使用,并且应用程序需要另一个连接的话,那么应用程序将被迫等待,直到5个打开的连接其中的一个被释放并变为空闲。
	MaxIdleConn     int           // 最大的空闲连接数。注意: MaxIdleConn 应该始终小于或等于 MaxOpenConn,设置比 MaxOpenConn 更多的空闲连接数是没有意义的,因为你最多也就能拿到所有打开的连接,剩余的空闲连接依然保持的空闲。
	ConnMaxLifetime time.Duration // 连接的最大生命周期(默认值:0)。设置为0的话意味着没有最大生命周期,连接总是可重用。注意: ConnMaxLifetime 越短,从零开始创建连接的频率就越高!
	ConnMaxIdleTime time.Duration
}

数据库配置信息

type DataSource added in v1.0.3

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

动态数据源路由(原GoMybatisDataSourceRouter)

func NewRouter

func NewRouter(routerFunc func(mapperName string) *string) DataSource

初始化路由,routerFunc为nil或者routerFunc返回nil,则框架自行选择第一个数据库作为数据源

func (*DataSource) Name added in v1.0.3

func (it *DataSource) Name() string

func (*DataSource) Router added in v1.0.3

func (it *DataSource) Router(mapperName string, engine IEngine) (ISession, error)

mapperName 即: mapperDao

func (*DataSource) SetDB added in v1.0.3

func (it *DataSource) SetDB(driverType string, dsn string, db *sql.DB)

将 driverType(数据库类型) 例如: mysql;dsn(数据库连接信息)例如:root:root@tcp(127.0.0.1:3306)/test;db(已经初始化的数据库连接对象) dsn 连接信息是唯一的,所以 一个 dsn 绑定一个 *sql.DB 指针,还绑定一个使用该 dsn的驱动!

type ElementType

type ElementType = string
const (
	//root elements
	ElementResultMap ElementType = "resultMap"
	ElementInsert    ElementType = "insert"
	ElementDelete    ElementType = "delete"
	ElementUpdate    ElementType = `update`
	ElementSelect    ElementType = "select"
	ElementSql       ElementType = "sql"

	//root template elements
	ElementInsertTemplate ElementType = "insertTemplate"
	ElementDeleteTemplate ElementType = "deleteTemplate"
	ElementUpdateTemplate ElementType = `updateTemplate`
	ElementSelectTemplate ElementType = "selectTemplate"

	//child elements
	ElementBind      ElementType = "bind"
	ElementString    ElementType = "string" //
	ElementIf        ElementType = `if`
	ElementTrim      ElementType = "trim"
	ElementForeach   ElementType = "for" //
	ElementSet       ElementType = "set"
	ElementChoose    ElementType = "switch"  //
	ElementWhen      ElementType = "case"    //
	ElementOtherwise ElementType = "default" //
	ElementWhere     ElementType = "where"
	ElementInclude   ElementType = "include"
)

type Engine

type Engine struct {
	sync.Once
	// contains filtered or unexported fields
}

Engine 一个 Engine 对象只操作一个SQL数据库!

func New

func New(cfg *Config) *Engine

该方法内部已经使用了单例,请不要再使用单例!

func (*Engine) GetDBRouter

func (it *Engine) GetDBRouter() IDataSource

func (*Engine) GetExpression

func (it *Engine) GetExpression() ast.IExpression

(原ExpressionEngine)获取表达式执行引擎

func (*Engine) GetGoroutine

func (it *Engine) GetGoroutine() *SessionMap

(GoroutineSessionMap)

func (*Engine) GetLog

func (it *Engine) GetLog() ILog

(原Log)获取日志实现类

func (*Engine) GetSessionFactory

func (it *Engine) GetSessionFactory() *SessionFactory

session工厂

func (*Engine) GetSqlBuilder

func (it *Engine) GetSqlBuilder() ISqlBuilder

sql构建器

func (*Engine) GetSqlResultDecoder

func (it *Engine) GetSqlResultDecoder() ISqlResultDecoder

sql查询结果解析器

func (*Engine) GetTpl added in v1.0.3

func (it *Engine) GetTpl() ITplDecoder

模板解析器

func (*Engine) ID added in v1.1.0

func (it *Engine) ID(node int64) ids.ID

生成雪花算法的ID

func (*Engine) IsGoroutine

func (it *Engine) IsGoroutine() bool

(原GoroutineIDEnable)

func (*Engine) IsLog

func (it *Engine) IsLog() bool

(原LogEnable)是否启用日志

func (*Engine) IsPrintWarn added in v1.1.2

func (it *Engine) IsPrintWarn() bool

检查是否设置了答应警告

func (*Engine) LogSystem

func (it *Engine) LogSystem() *LogSystem

func (*Engine) Name

func (it *Engine) Name() string

func (*Engine) NewSession

func (it *Engine) NewSession(mapperName string) (ISession, error)

mapperName 即: mapperDao

func (*Engine) One added in v1.1.3

func (it *Engine) One(mapperPtr interface{}) IEngine

One 运行单个 dao 对象,该方法主要用于测试 dao 对象中的方法!

参数<mapperPtr>是指dao结构体(真正操作数据库的结构体)

func (*Engine) Register added in v1.1.0

func (it *Engine) Register(filePath string, h H) IEngine

Register 注册 mapperPtr 与 modelPtr的映射关系.参数<filePath>不能为空! H 的key是:指针类型的mapperPtr,value是:指针类型的modelPtr

func (*Engine) Run added in v1.1.0

func (it *Engine) Run()

Run 运行当前 Engine 对象中所有已经注册的 dao 对象

func (*Engine) SetExpression

func (it *Engine) SetExpression(engine ast.IExpression)

设置表达式执行引擎

func (*Engine) SetGoroutine

func (it *Engine) SetGoroutine(enable bool)

func (*Engine) SetLog

func (it *Engine) SetLog(log ILog)

设置日志实现类

func (*Engine) SetLogEnable

func (it *Engine) SetLogEnable(enable bool)

设置日志实现类,是否启用日志

func (*Engine) SetPrintWarn added in v1.1.2

func (it *Engine) SetPrintWarn(print bool)

设置是否打印警告

func (*Engine) SetSessionFactory

func (it *Engine) SetSessionFactory(factory *SessionFactory)

设置session工厂

func (*Engine) SetSqlArgTypeConvert

func (it *Engine) SetSqlArgTypeConvert(convert ast.SqlArgTypeConvert)

设置sql类型转换器

func (*Engine) SetSqlBuilder

func (it *Engine) SetSqlBuilder(builder ISqlBuilder)

设置sql构建器

func (*Engine) SetSqlResultDecoder

func (it *Engine) SetSqlResultDecoder(decoder ISqlResultDecoder)

设置sql查询结果解析器

func (*Engine) SetTpl added in v1.0.3

func (it *Engine) SetTpl(decoder ITplDecoder)

设置模板解析器

func (*Engine) Use added in v1.0.2

func (it *Engine) Use(router IDataSource)

Use 原(SetDataSourceRouter)设置动态数据库,参数<router>是mbt.NewRouter()的返回值。

type ExpressionCache added in v1.1.5

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

原 (ExpressionEngineLexerMapCache)表达式引擎缓存

func (*ExpressionCache) Get added in v1.1.5

func (it *ExpressionCache) Get(expression string) (interface{}, error)

func (*ExpressionCache) Name added in v1.1.5

func (it *ExpressionCache) Name() string

func (ExpressionCache) New added in v1.1.5

func (*ExpressionCache) Set added in v1.1.5

func (it *ExpressionCache) Set(expression string, lexer interface{}) error

type ExpressionProxy

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

表达式引擎代理

func NewExpressionProxy

func NewExpressionProxy(engine ast.IExpression, useLexerCache bool) ExpressionProxy

engine :表达式引擎,useLexerCache:是否缓存Lexer表达式编译结果

func (*ExpressionProxy) Eval

func (it *ExpressionProxy) Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error)

执行一个表达式 参数:lexerResult=编译结果,arg=参数 返回:执行结果,错误

func (*ExpressionProxy) Lexer

func (it *ExpressionProxy) Lexer(expression string) (interface{}, error)

编译一个表达式 参数:lexerArg 表达式内容 返回:interface{} 编译结果,error 错误

func (*ExpressionProxy) LexerAndEval

func (it *ExpressionProxy) LexerAndEval(expression string, arg interface{}) (interface{}, error)

执行

func (*ExpressionProxy) LexerCache

func (it *ExpressionProxy) LexerCache() IExpressionLexerCache

func (*ExpressionProxy) LexerCacheable

func (it *ExpressionProxy) LexerCacheable() bool

func (ExpressionProxy) Name

func (it ExpressionProxy) Name() string

引擎名称

func (*ExpressionProxy) SetExpressionEngine

func (it *ExpressionProxy) SetExpressionEngine(engine ast.IExpression)

引擎名称

func (*ExpressionProxy) SetLexerCache

func (it *ExpressionProxy) SetLexerCache(cache IExpressionLexerCache)

func (*ExpressionProxy) SetUseLexerCache

func (it *ExpressionProxy) SetUseLexerCache(isUseCache bool) error

type H added in v1.1.0

type H map[interface{}]interface{}

type IDataSource added in v1.0.3

type IDataSource interface {
	//路由规则
	//参数:mapperName mapper文件包名+名称例如(example.ActivityDao)
	//返回(session,error)路由选择后的session,error异常
	Router(mapperName string, engine IEngine) (ISession, error)
	//设置sql.DB,该方法会被GoMybatis框架内调用
	SetDB(driverName string, dsn string, db *sql.DB)
	Name() string
}

数据源路由接口

type IEngine added in v1.0.2

type IEngine interface {

	// One 运行单个 dao 对象,该方法主要用于测试 dao 对象中的方法!
	//  参数<mapperPtr>是指dao结构体(真正操作数据库的结构体)
	One(mapperPtr interface{}) IEngine
	Register(filePath string, h H) IEngine
	Run()
	//引擎名称
	Name() string
	//创建session
	NewSession(mapperName string) (ISession, error)
	//获取数据源路由
	GetDBRouter() IDataSource
	//设置数据源路由
	//SetDBRouter(router IDataSourceRouter)
	Use(router IDataSource)
	//是否启用日志
	IsLog() bool
	//是否启用日志
	SetLogEnable(enable bool)
	//(原Log)获取日志实现类
	GetLog() ILog
	//设置日志实现类
	SetLog(log ILog)
	//session工厂
	GetSessionFactory() *SessionFactory
	//设置session工厂
	SetSessionFactory(factory *SessionFactory)
	//设置sql类型转换器
	SetSqlArgTypeConvert(convert ast.SqlArgTypeConvert)
	//表达式执行引擎
	GetExpression() ast.IExpression
	//设置表达式执行引擎
	SetExpression(engine ast.IExpression)
	//sql构建器
	GetSqlBuilder() ISqlBuilder
	//设置sql构建器
	SetSqlBuilder(builder ISqlBuilder)
	//sql查询结果解析器
	GetSqlResultDecoder() ISqlResultDecoder
	//设置sql查询结果解析器
	SetSqlResultDecoder(decoder ISqlResultDecoder)
	//模板解析器
	GetTpl() ITplDecoder
	//设置模板解析器
	SetTpl(decoder ITplDecoder)
	//(注意(该方法需要在多协程环境下调用)启用会从栈获取协程id,有一定性能消耗,换取最大的事务定义便捷)
	GetGoroutine() *SessionMap
	//是否启用goroutineIDEnable(注意(该方法需要在多协程环境下调用)启用会从栈获取协程id,有一定性能消耗,换取最大的事务定义便捷)
	SetGoroutine(enable bool)
	//(原GoroutineIDEnable)是否启用goroutineIDEnable(注意(该方法需要在多协程环境下调用)启用会从栈获取协程id,有一定性能消耗,换取最大的事务定义便捷)
	IsGoroutine() bool
	LogSystem() *LogSystem
	IsPrintWarn() bool
	// contains filtered or unexported methods
}

IEngine (原SessionEngine)框架的引擎,对外暴露方法。

type IExpressionLexerCache added in v1.0.3

type IExpressionLexerCache interface {
	Set(expression string, lexer interface{}) error
	Get(expression string) (interface{}, error)
	Name() string
}

原(ExpressionEngineLexerCache)Lexer 结果缓存

type IExpressionLexerCacheable added in v1.0.3

type IExpressionLexerCacheable interface {
	SetUseLexerCache(use bool) error
	LexerCacheable() bool
}

原(ExpressionEngineLexerCacheable)

type ILog added in v1.0.3

type ILog interface {
	QueueLen() int           //日志消息队列长度
	Println(messages []byte) //日志输出方法实现
}

type ISession added in v1.0.2

type ISession interface {
	Query(sqlOrArgs string) ([]map[string][]byte, error)
	Exec(sqlOrArgs string) (*Result, error)
	//Prepare sql, example sqlPrepare: select * from table where id = ?   ,   args:'1'
	QueryPrepare(sqlPrepare string, args ...interface{}) ([]map[string][]byte, error)
	//Prepare sql, example sqlPrepare: select * from table where id = ?   ,   args:'1'
	ExecPrepare(sqlPrepare string, args ...interface{}) (*Result, error)
	Begin(p *tx.Propagation) error
	Commit() error
	Rollback() error
	Id() string
	Close()
	LastPropagation() *tx.Propagation
	StmtConvert() (stmt.IConvert, error)
}

ISession (原Session) 与数据库的一次会话(包括了 *sql.DB 和 *sql.Tx 操作)

调用这个接口,既可以,以非事务方式操作数据库,也可以,以事务方式操作数据库!
这个接口,封装了 *sql.DB 中方法,也封装了 *sql.Tx 中的方法!

type ISqlBuilder

type ISqlBuilder interface {
	BuildSql(paramMap map[string]interface{}, nodes []ast.Node, array *[]interface{}, stmtConvert stmt.IConvert) (string, error)
	ExpressionEngineProxy() *ExpressionProxy
	SetSqlLog(enable bool) // (原SetEnableLog)
	EnableLog() bool
	NodeParser() ast.NodeParser
}

sql文本构建

type ISqlResultDecoder added in v1.0.3

type ISqlResultDecoder interface {
	//resultMap = in xml resultMap element
	//dbData = select the SqlResult
	//decodeResultPtr = need decode result type
	Decode(resultMap map[string]*ResultProperty, SqlResult []map[string][]byte, decodeResultPtr interface{}) error
}

sql查询结果解码

type ITplDecoder added in v1.0.3

type ITplDecoder interface {
	PrintElement(print bool)
	DecodeTree(tree map[string]etree.Token, beanType reflect.Type) error
}

ITplDecoder templateDecoder 接口,该接口由 TplDecoder实现

type LogStandard

type LogStandard struct {
	PrintlnFunc func(messages []byte) //日志输出方法实现
}

func (*LogStandard) Println

func (it *LogStandard) Println(v []byte)

日志输出方法实现

func (*LogStandard) QueueLen

func (it *LogStandard) QueueLen() int

日志消息队列长度

type LogSystem

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

func NewLog added in v1.0.3

func NewLog(log ILog, queueLen int) (LogSystem, error)

logImpl:日志实现类,queueLen:消息队列缓冲长度

func (*LogSystem) Close

func (it *LogSystem) Close() error

关闭日志系统和队列

func (*LogSystem) SendLog

func (it *LogSystem) SendLog(logs ...string) error

日志发送者

type LogicDeleteData

type LogicDeleteData struct {
	Column        string
	Property      string
	LangType      string
	Enable        bool
	DeletedValue  string
	UndeleteValue string
}

type Mapper

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

type ProxyArg

type ProxyArg struct {
	TagArgs    []TagArg
	TagArgsLen int
	Args       []reflect.Value
	ArgsLen    int
}

代理数据

func (ProxyArg) New

func (it ProxyArg) New(tagArgs []TagArg, args []reflect.Value) ProxyArg

type Result

type Result struct {
	LastInsertId int64
	RowsAffected int64
}

type ResultProperty

type ResultProperty struct {
	XMLName  string //`xml:"result/id"`
	Column   string
	LangType string
}

type ReturnType

type ReturnType struct {
	ErrorType     *reflect.Type
	ReturnOutType *reflect.Type
	ReturnIndex   int //返回数据位置索引
	NumOut        int //返回总数
}

type Session

type Session struct {
	SessionId string
	// contains filtered or unexported fields
}

Session 实现了 ISession 接口。

Session 进一步封装了 *sql.DB 和 *sql.Tx
Session 将 *sql.DB 和 *sql.Tx 整合到了一起,并再其原有的功能上增加了新功能。

func (*Session) Begin

func (it *Session) Begin(p *tx.Propagation) error

func (*Session) Close

func (it *Session) Close()

func (*Session) Commit

func (it *Session) Commit() error

func (*Session) Exec

func (it *Session) Exec(args string) (*Result, error)

func (*Session) ExecPrepare

func (it *Session) ExecPrepare(sqlPrepare string, args ...interface{}) (*Result, error)

func (*Session) Id

func (it *Session) Id() string

func (*Session) LastPropagation added in v1.0.3

func (it *Session) LastPropagation() *tx.Propagation

func (Session) New added in v1.0.3

func (it Session) New(driverType string, driverLink string, db *sql.DB, logSystem ILog) Session

func (*Session) Query

func (it *Session) Query(args string) ([]map[string][]byte, error)

func (*Session) QueryPrepare

func (it *Session) QueryPrepare(sqlPrepare string, args ...interface{}) ([]map[string][]byte, error)

func (*Session) Rollback

func (it *Session) Rollback() error

func (*Session) StmtConvert

func (it *Session) StmtConvert() (stmt.IConvert, error)

type SessionFactory

type SessionFactory struct {
	Engine     IEngine
	SessionMap sync.Map //map[string]Session
}

func NewSessionFactory

func NewSessionFactory(Engine IEngine) SessionFactory

func (*SessionFactory) Close

func (it *SessionFactory) Close(id string)

func (*SessionFactory) CloseAll

func (it *SessionFactory) CloseAll(id string)

func (*SessionFactory) GetSession

func (it *SessionFactory) GetSession(id string) ISession

func (*SessionFactory) NewSession

func (it *SessionFactory) NewSession(mapperName string, sessionType SessionType) ISession

func (*SessionFactory) SetSession

func (it *SessionFactory) SetSession(id string, session ISession)

type SessionFactorySession

type SessionFactorySession struct {
	Session ISession
	Factory *SessionFactory
}

func (*SessionFactorySession) Begin

func (it *SessionFactorySession) Begin(p *tx.Propagation) error

func (*SessionFactorySession) Close

func (it *SessionFactorySession) Close()

func (*SessionFactorySession) Commit

func (it *SessionFactorySession) Commit() error

func (*SessionFactorySession) Exec

func (it *SessionFactorySession) Exec(sqlOrArg string) (*Result, error)

func (*SessionFactorySession) ExecPrepare

func (it *SessionFactorySession) ExecPrepare(sqlOrArg string, args ...interface{}) (*Result, error)

func (*SessionFactorySession) Id

func (it *SessionFactorySession) Id() string

func (*SessionFactorySession) LastPropagation added in v1.0.2

func (it *SessionFactorySession) LastPropagation() *tx.Propagation

func (*SessionFactorySession) Query

func (it *SessionFactorySession) Query(sqlOrArg string) ([]map[string][]byte, error)

func (*SessionFactorySession) QueryPrepare

func (it *SessionFactorySession) QueryPrepare(sqlOrArg string, args ...interface{}) ([]map[string][]byte, error)

func (*SessionFactorySession) Rollback

func (it *SessionFactorySession) Rollback() error

func (*SessionFactorySession) StmtConvert

func (it *SessionFactorySession) StmtConvert() (stmt.IConvert, error)

type SessionMap added in v1.1.5

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

(原GoroutineSessionMap)

func (*SessionMap) Delete added in v1.1.5

func (it *SessionMap) Delete(k int64)

func (*SessionMap) Get added in v1.1.5

func (it *SessionMap) Get(k int64) ISession

func (SessionMap) New added in v1.1.5

func (it SessionMap) New() SessionMap

func (*SessionMap) Put added in v1.1.5

func (it *SessionMap) Put(k int64, session ISession)

type SessionType

type SessionType = int
const (
	SessionTypeDefault SessionType = iota //默认session类型
	SessionTypeLocal                      //本地session
)

type SqlArgTypeConvert added in v1.0.4

type SqlArgTypeConvert struct{}

Sql内容类型转换器 (原GoMybatisSqlArgTypeConvert)

func (SqlArgTypeConvert) Convert added in v1.0.4

func (it SqlArgTypeConvert) Convert(argValue interface{}) string

Sql内容类型转换器

type SqlBuilder

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

func NewSqlBuilder

func NewSqlBuilder(expressionEngine ExpressionProxy, log ILog, enableLog bool) SqlBuilder

func (*SqlBuilder) BuildSql

func (it *SqlBuilder) BuildSql(args map[string]interface{}, node []ast.Node, array *[]interface{}, stmtConvert stmt.IConvert) (string, error)

func (*SqlBuilder) EnableLog

func (it *SqlBuilder) EnableLog() bool

func (*SqlBuilder) ExpressionEngineProxy

func (it *SqlBuilder) ExpressionEngineProxy() *ExpressionProxy

func (*SqlBuilder) NodeParser

func (it *SqlBuilder) NodeParser() ast.NodeParser

func (*SqlBuilder) SetSqlLog

func (it *SqlBuilder) SetSqlLog(enable bool)

type SqlResultDecoder

type SqlResultDecoder struct {
	ISqlResultDecoder
}

func (SqlResultDecoder) Decode

func (it SqlResultDecoder) Decode(resultMap map[string]*ResultProperty, sqlResult []map[string][]byte, result interface{}) error

type TagArg

type TagArg struct {
	Name  string
	Index int
}

type TplDecoder added in v1.0.3

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

这个文件里各个方法中,函数中的字符串不要随便改,因为这些字符串与 ("gitee.com/gopher2011/mbt/pkg/etree"中的一一对应!) * TODO sqlTemplate解析器,目前直接操作*etree.Element实现,后期应该改成操作xml,换取更好的维护性

GoMybatisTemplateDecoder

func (*TplDecoder) Decode added in v1.0.3

func (it *TplDecoder) Decode(method *reflect.StructField, mapper *etree.Element, tree map[string]etree.Token) (bool, error)

Decode 该方法只对 <selectTemplate/> <insertTemplate/> <updateTemplate/> <deleteTemplate/> 这四个标签解码。

func (*TplDecoder) DecodeCollectionName added in v1.0.3

func (it *TplDecoder) DecodeCollectionName(method *reflect.StructField) string

反射解码得到 集合名词

func (*TplDecoder) DecodeSets added in v1.0.3

func (it *TplDecoder) DecodeSets(arg string, mapper *etree.Element, logic LogicDeleteData, versionData *VersionData)

func (*TplDecoder) DecodeTree added in v1.0.3

func (it *TplDecoder) DecodeTree(tree map[string]etree.Token, beanType reflect.Type) error

对 tree进行解码 参数 beanType 是被解析的 mapperPtr,例如 :example_test.go中的 ActivityDao 结构体!

func (*TplDecoder) DecodeWheres added in v1.0.3

func (it *TplDecoder) DecodeWheres(arg string, mapper *etree.Element, logic LogicDeleteData, versionData *VersionData)

解码逗号分隔的where

func (*TplDecoder) PrintElement added in v1.0.3

func (it *TplDecoder) PrintElement(print bool)

type Tx added in v1.0.2

type Tx struct {
	Session func() (ISession, error)
}

事务

type VersionData

type VersionData struct {
	Column   string
	Property string
	LangType string
}

Directories

Path Synopsis
internal
ast
etree
软件包etree通过元素树抽象提供XML服务。
软件包etree通过元素树抽象提供XML服务。
tx
pkg
ids
Package snowflake provides a very simple Twitter snowflake generator and parser.
Package snowflake provides a very simple Twitter snowflake generator and parser.
uuid
Package uuid generates and inspects UUIDs.
Package uuid generates and inspects UUIDs.

Jump to

Keyboard shortcuts

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