forked from zhuxiujia/GoMybatis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqlEngine.go
103 lines (79 loc) · 2.78 KB
/
SqlEngine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package GoMybatis
import (
"database/sql"
"github.com/zhuxiujia/GoMybatis/ast"
"github.com/zhuxiujia/GoMybatis/stmt"
"github.com/zhuxiujia/GoMybatis/tx"
)
type Result struct {
LastInsertId int64
RowsAffected int64
}
type Session interface {
Id() string
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)
Rollback() error
Commit() error
Begin(p *tx.Propagation) error
Close()
LastPROPAGATION() *tx.Propagation
StmtConvert() (stmt.StmtIndexConvert, error)
}
//产生session的引擎
type SessionEngine interface {
//打开数据库
Open(driverName, dataSourceLink string) (*sql.DB, error)
//写方法到mapper
WriteMapperPtr(ptr interface{}, xml []byte)
//引擎名称
Name() string
//创建session
NewSession(mapperName string) (Session, error)
//获取数据源路由
DataSourceRouter() DataSourceRouter
//设置数据源路由
SetDataSourceRouter(router DataSourceRouter)
//是否启用日志
LogEnable() bool
//是否启用日志
SetLogEnable(enable bool)
//获取日志实现类
Log() Log
//设置日志实现类
SetLog(log Log)
//session工厂
SessionFactory() *SessionFactory
//设置session工厂
SetSessionFactory(factory *SessionFactory)
//设置sql类型转换器
SetSqlArgTypeConvert(convert ast.SqlArgTypeConvert)
//表达式执行引擎
ExpressionEngine() ast.ExpressionEngine
//设置表达式执行引擎
SetExpressionEngine(engine ast.ExpressionEngine)
//sql构建器
SqlBuilder() SqlBuilder
//设置sql构建器
SetSqlBuilder(builder SqlBuilder)
//sql查询结果解析器
SqlResultDecoder() SqlResultDecoder
//设置sql查询结果解析器
SetSqlResultDecoder(decoder SqlResultDecoder)
//模板解析器
TempleteDecoder() TempleteDecoder
//设置模板解析器
SetTempleteDecoder(decoder TempleteDecoder)
//(注意(该方法需要在多协程环境下调用)启用会从栈获取协程id,有一定性能消耗,换取最大的事务定义便捷)
GoroutineSessionMap() *GoroutineSessionMap
//是否启用goroutineIDEnable(注意(该方法需要在多协程环境下调用)启用会从栈获取协程id,有一定性能消耗,换取最大的事务定义便捷)
SetGoroutineIDEnable(enable bool)
//是否启用goroutineIDEnable(注意(该方法需要在多协程环境下调用)启用会从栈获取协程id,有一定性能消耗,换取最大的事务定义便捷)
GoroutineIDEnable() bool
LogSystem() *LogSystem
IsPrintWarning() bool
}