forked from xormplus/xorm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
engineplus.go
78 lines (66 loc) · 2.06 KB
/
engineplus.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
package xorm
import (
"encoding/json"
)
func (engine *Engine) SetSqlMapRootDir(sqlMapRootDir string) *Engine {
engine.SqlMap.SqlMapRootDir = sqlMapRootDir
return engine
}
func (engine *Engine) SqlMapClient(sqlTagName string, args ...interface{}) *Session {
session := engine.NewSession()
session.isAutoClose = true
session.isSqlFunc = true
return session.Sql(engine.SqlMap.Sql[sqlTagName], args...)
}
func (engine *Engine) SqlTemplateClient(sqlTagName string, args ...interface{}) *Session {
session := engine.NewSession()
session.isAutoClose = true
session.isSqlFunc = true
return session.SqlTemplateClient(sqlTagName, args...)
}
func (engine *Engine) Search(beans interface{}, condiBeans ...interface{}) *ResultStructs {
session := engine.NewSession()
defer session.Close()
return session.Search(beans, condiBeans...)
}
// Get retrieve one record from table, bean's non-empty fields
// are conditions
func (engine *Engine) GetFirst(bean interface{}) *ResultBean {
session := engine.NewSession()
defer session.Close()
return session.GetFirst(bean)
}
func JSONString(v interface{}, IndentJSON bool) (string, error) {
var result []byte
var err error
if IndentJSON {
result, err = json.MarshalIndent(v, "", " ")
} else {
result, err = json.Marshal(v)
}
if err != nil {
return "", err
}
if string(result) == "null" {
return "", nil
}
return string(result), nil
}
func (engine *Engine) Sqls(sqls interface{}, parmas ...interface{}) *SqlsExecutor {
session := engine.NewSession()
session.isAutoClose = false
session.isSqlFunc = true
return session.Sqls(sqls, parmas...)
}
func (engine *Engine) SqlMapsClient(sqlkeys interface{}, parmas ...interface{}) *SqlMapsExecutor {
session := engine.NewSession()
session.isAutoClose = false
session.isSqlFunc = true
return session.SqlMapsClient(sqlkeys, parmas...)
}
func (engine *Engine) SqlTemplatesClient(sqlkeys interface{}, parmas ...interface{}) *SqlTemplatesExecutor {
session := engine.NewSession()
session.isAutoClose = false
session.isSqlFunc = true
return session.SqlTemplatesClient(sqlkeys, parmas...)
}