Documentation ¶
Index ¶
- Constants
- func AopProxyService(service interface{}, engine sessions.SessionEngine)
- func AopProxyServiceValue(service reflect.Value, engine sessions.SessionEngine)
- func InjectSession(ctx context.Context, session Session) context.Context
- func Proxy(proxyPtr interface{}, buildFunc build)
- func ProxyValue(mapperValue reflect.Value, buildFunc build)
- func WriteMapper(bean reflect.Value, xmlBuffer []byte, sessionEngine sessions.SessionEngine)
- func WriteMapperByValue(value reflect.Value, xmlBuffer []byte, sessionEngine sessions.SessionEngine)
- func WriteMapperPtrByEngine(ptr interface{}, xmlBuffer []byte, sessionEngine sessions.SessionEngine)
- type CallBack
- type GoMybatisDataSourceRouter
- func (it *GoMybatisDataSourceRouter) Name() string
- func (it GoMybatisDataSourceRouter) New(routerFunc func(mapperName string) *string) GoMybatisDataSourceRouter
- func (it *GoMybatisDataSourceRouter) Router(mapperName string, engine sessions.SessionEngine) (sessions.Session, error)
- func (it *GoMybatisDataSourceRouter) SetDB(driver string, url string, db *sql.DB)
- type GoMybatisEngine
- func (it *GoMybatisEngine) DataSourceRouter() sessions.DataSourceRouter
- func (it *GoMybatisEngine) ExpressionEngine() ast.ExpressionEngine
- func (it *GoMybatisEngine) GetObj(name string) interface{}
- func (it *GoMybatisEngine) GoroutineIDEnable() bool
- func (it *GoMybatisEngine) GoroutineSessionMap() *sessions.GoroutineSessionMap
- func (it *GoMybatisEngine) Log() logger.Log
- func (it *GoMybatisEngine) LogEnable() bool
- func (it *GoMybatisEngine) LogSystem() *logger.LogSystem
- func (it *GoMybatisEngine) Name() string
- func (it GoMybatisEngine) New() GoMybatisEngine
- func (it *GoMybatisEngine) NewSession(mapperName string) (sessions.Session, error)
- func (it *GoMybatisEngine) NewSessionWithContext(ctx context.Context, mapperName string) (sessions.Session, error)
- func (it *GoMybatisEngine) Open(driverName, dataSourceName string) (*sql.DB, error)
- func (it *GoMybatisEngine) RegisterObj(ptr interface{}, name string)
- func (it *GoMybatisEngine) SessionFactory() *sessions.SessionFactory
- func (it *GoMybatisEngine) SetDataSourceRouter(router sessions.DataSourceRouter)
- func (it *GoMybatisEngine) SetExpressionEngine(engine ast.ExpressionEngine)
- func (it *GoMybatisEngine) SetGoroutineIDEnable(enable bool)
- func (it *GoMybatisEngine) SetLog(log logger.Log)
- func (it *GoMybatisEngine) SetLogEnable(enable bool)
- func (it *GoMybatisEngine) SetSessionFactory(factory *sessions.SessionFactory)
- func (it *GoMybatisEngine) SetSqlBuilder(builder sessions.SqlBuilder)
- func (it *GoMybatisEngine) SetSqlResultDecoder(decoder sessions.SqlResultDecoder)
- func (it *GoMybatisEngine) SetTempleteDecoder(decoder sessions.TempleteDecoder)
- func (it *GoMybatisEngine) SqlBuilder() sessions.SqlBuilder
- func (it *GoMybatisEngine) SqlResultDecoder() sessions.SqlResultDecoder
- func (it *GoMybatisEngine) TempleteDecoder() sessions.TempleteDecoder
- func (it *GoMybatisEngine) WriteMapperPtr(ptr interface{}, xml []byte)
- type Mapper
- type ProxyArg
- type ReturnType
- type Session
- type SessionSupport
- type TagArg
Constants ¶
const GoMybatis_Context = "context.Context"
const GoMybatis_Session = `GoMybatisV2.Session`
const GoMybatis_Session_Ptr = `*GoMybatisV2.Session`
const GoMybatis_Time = `time.Time`
const GoMybatis_Time_Ptr = `*time.Time`
const (
NewSessionFunc = "NewSession" // NewSession method,auto write implement body code
)
Variables ¶
This section is empty.
Functions ¶
func AopProxyService ¶
func AopProxyService(service interface{}, engine sessions.SessionEngine)
使用AOP切面 代理目标服务,如果服务painc()它的事务会回滚 默认为单协程模型,如果是多协程调用的情况请开启engine.SetGoroutineIDEnable(true)
func AopProxyServiceValue ¶
func AopProxyServiceValue(service reflect.Value, engine sessions.SessionEngine)
使用AOP切面 代理目标服务,如果服务painc()它的事务会回滚
func InjectSession ¶ added in v0.0.6
注入session到ctx里面去,这样就可以方便的使用session了
func Proxy ¶
func Proxy(proxyPtr interface{}, buildFunc build)
AopProxy 可写入每个函数代理方法.proxyPtr:代理对象指针,buildFunc:构建代理函数
func WriteMapper ¶
func WriteMapper(bean reflect.Value, xmlBuffer []byte, sessionEngine sessions.SessionEngine)
写入方法内容,例如
type ExampleActivityMapperImpl struct { SelectAll func(result *[]Activity) error SelectByCondition func(name string, startTime time.Time, endTime time.Time, page int, size int, result *[]Activity) error `mapperParams:"name,startTime,endTime,page,size"` UpdateById func(session *GoMybatis.Session, arg Activity, result *int64) error //只要参数中包含有*GoMybatis.Session的类型,框架默认使用传入的session对象,用于自定义事务 Insert func(arg Activity, result *int64) error CountByCondition func(name string, startTime time.Time, endTime time.Time, result *int) error `mapperParams:"name,startTime,endTime"` }
func的基本类型的参数(例如string,int,time.Time,int64,float....)个数无限制(并且需要用Tag指定参数名逗号隔开,例如`mapperParams:"id,phone"`),返回值必须有error func的结构体参数无需指定mapperParams的tag,框架会自动扫描它的属性,封装为map处理掉 使用WriteMapper函数设置代理后即可正常使用。
func WriteMapperByValue ¶
func WriteMapperByValue(value reflect.Value, xmlBuffer []byte, sessionEngine sessions.SessionEngine)
推荐默认使用单例传入 根据sessionEngine写入到mapperPtr,value:指向mapper指针反射对象,xml:xml数据,sessionEngine:session引擎,enableLog:是否允许日志输出,log:日志实现
func WriteMapperPtrByEngine ¶
func WriteMapperPtrByEngine(ptr interface{}, xmlBuffer []byte, sessionEngine sessions.SessionEngine)
推荐默认使用单例传入 根据sessionEngine写入到mapperPtr,ptr:指向mapper指针,xml:xml数据,sessionEngine:session引擎,enableLog:是否允许日志输出,log:日志实现
Types ¶
type CallBack ¶
type CallBack struct { //sql 查询之前执行,可以写指针改变sql内容(func 可以为nil) BeforeQuery func(args []reflect.Value, sqlorArgs *string) //sql 查询之前执行,可以写指针改变sql内容(func 可以为nil) BeforeExec func(args []reflect.Value, sqlorArgs *string) //sql 查询之后执行,可以写指针改变返回结果(func 可以为nil) AfterQuery func(args []reflect.Value, sqlorArgs string, result *[]map[string][]byte, err *error) //sql 查询之后执行,可以写指针改变返回结果(func 可以为nil) AfterExec func(args []reflect.Value, sqlorArgs string, result *sessions.Result, err *error) }
sql 运行时 回调
type GoMybatisDataSourceRouter ¶
type GoMybatisDataSourceRouter struct {
// contains filtered or unexported fields
}
动态数据源路由
func (*GoMybatisDataSourceRouter) Name ¶
func (it *GoMybatisDataSourceRouter) Name() string
func (GoMybatisDataSourceRouter) New ¶
func (it GoMybatisDataSourceRouter) New(routerFunc func(mapperName string) *string) GoMybatisDataSourceRouter
初始化路由,routerFunc为nil或者routerFunc返回nil,则框架自行选择第一个数据库作为数据源
func (*GoMybatisDataSourceRouter) Router ¶
func (it *GoMybatisDataSourceRouter) Router(mapperName string, engine sessions.SessionEngine) (sessions.Session, error)
type GoMybatisEngine ¶
type GoMybatisEngine struct {
// contains filtered or unexported fields
}
func New ¶
func New() GoMybatisEngine
func (*GoMybatisEngine) DataSourceRouter ¶
func (it *GoMybatisEngine) DataSourceRouter() sessions.DataSourceRouter
func (*GoMybatisEngine) ExpressionEngine ¶
func (it *GoMybatisEngine) ExpressionEngine() ast.ExpressionEngine
表达式执行引擎
func (*GoMybatisEngine) GetObj ¶
func (it *GoMybatisEngine) GetObj(name string) interface{}
func (*GoMybatisEngine) GoroutineIDEnable ¶
func (it *GoMybatisEngine) GoroutineIDEnable() bool
func (*GoMybatisEngine) GoroutineSessionMap ¶
func (it *GoMybatisEngine) GoroutineSessionMap() *sessions.GoroutineSessionMap
func (*GoMybatisEngine) LogSystem ¶
func (it *GoMybatisEngine) LogSystem() *logger.LogSystem
func (*GoMybatisEngine) Name ¶
func (it *GoMybatisEngine) Name() string
func (GoMybatisEngine) New ¶
func (it GoMybatisEngine) New() GoMybatisEngine
func (*GoMybatisEngine) NewSession ¶
func (it *GoMybatisEngine) NewSession(mapperName string) (sessions.Session, error)
func (*GoMybatisEngine) NewSessionWithContext ¶ added in v0.0.6
func (*GoMybatisEngine) Open ¶
func (it *GoMybatisEngine) Open(driverName, dataSourceName string) (*sql.DB, error)
打开数据库 driverName: 驱动名称例如"mysql", dataSourceName: string 数据库url
func (*GoMybatisEngine) RegisterObj ¶
func (it *GoMybatisEngine) RegisterObj(ptr interface{}, name string)
func (*GoMybatisEngine) SessionFactory ¶
func (it *GoMybatisEngine) SessionFactory() *sessions.SessionFactory
session工厂
func (*GoMybatisEngine) SetDataSourceRouter ¶
func (it *GoMybatisEngine) SetDataSourceRouter(router sessions.DataSourceRouter)
func (*GoMybatisEngine) SetExpressionEngine ¶
func (it *GoMybatisEngine) SetExpressionEngine(engine ast.ExpressionEngine)
设置表达式执行引擎
func (*GoMybatisEngine) SetGoroutineIDEnable ¶
func (it *GoMybatisEngine) SetGoroutineIDEnable(enable bool)
func (*GoMybatisEngine) SetLogEnable ¶
func (it *GoMybatisEngine) SetLogEnable(enable bool)
设置日志实现类,是否启用日志
func (*GoMybatisEngine) SetSessionFactory ¶
func (it *GoMybatisEngine) SetSessionFactory(factory *sessions.SessionFactory)
设置session工厂
func (*GoMybatisEngine) SetSqlBuilder ¶
func (it *GoMybatisEngine) SetSqlBuilder(builder sessions.SqlBuilder)
设置sql构建器
func (*GoMybatisEngine) SetSqlResultDecoder ¶
func (it *GoMybatisEngine) SetSqlResultDecoder(decoder sessions.SqlResultDecoder)
设置sql查询结果解析器
func (*GoMybatisEngine) SetTempleteDecoder ¶
func (it *GoMybatisEngine) SetTempleteDecoder(decoder sessions.TempleteDecoder)
设置模板解析器
func (*GoMybatisEngine) SqlBuilder ¶
func (it *GoMybatisEngine) SqlBuilder() sessions.SqlBuilder
sql构建器
func (*GoMybatisEngine) SqlResultDecoder ¶
func (it *GoMybatisEngine) SqlResultDecoder() sessions.SqlResultDecoder
sql查询结果解析器
func (*GoMybatisEngine) TempleteDecoder ¶
func (it *GoMybatisEngine) TempleteDecoder() sessions.TempleteDecoder
模板解析器
func (*GoMybatisEngine) WriteMapperPtr ¶
func (it *GoMybatisEngine) WriteMapperPtr(ptr interface{}, xml []byte)