-
Notifications
You must be signed in to change notification settings - Fork 223
/
Copy pathengineplus.go
111 lines (93 loc) · 2.78 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
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
104
105
106
107
108
109
110
111
package xorm
import (
"encoding/json"
"gopkg.in/flosch/pongo2.v3"
)
func (engine *Engine) SetSqlMapRootDir(sqlMapRootDir string) *Engine {
engine.sqlMap.SqlMapRootDir = sqlMapRootDir
return engine
}
func (engine *Engine) SetSqlTemplateRootDir(sqlTemplateRootDir string) *Engine {
engine.sqlTemplate.SqlTemplateRootDir = sqlTemplateRootDir
return engine
}
func (engine *Engine) SqlMapClient(sqlTagName string, args ...interface{}) *Session {
session := engine.NewSession()
session.IsAutoClose = true
session.IsSqlFuc = 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.IsSqlFuc = true
if engine.sqlTemplate.Template[sqlTagName] == nil {
if len(args) == 0 {
return session.Sql("")
} else {
map1 := args[0].(*map[string]interface{})
return session.Sql("", map1)
}
}
if len(args) == 0 {
parmap := &pongo2.Context{"1": 1}
sql, err := engine.sqlTemplate.Template[sqlTagName].Execute(*parmap)
if err != nil {
engine.logger.Error(err)
}
return session.Sql(sql)
} else {
map1 := args[0].(*map[string]interface{})
sql, err := engine.sqlTemplate.Template[sqlTagName].Execute(*map1)
if err != nil {
engine.logger.Error(err)
}
return session.Sql(sql, map1)
}
}
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 = true
session.IsSqlFuc = true
return session.Sqls(sqls, parmas...)
}
func (engine *Engine) SqlMapsClient(sqlkeys interface{}, parmas ...interface{}) *SqlMapsExecutor {
session := engine.NewSession()
session.IsAutoClose = true
session.IsSqlFuc = true
return session.SqlMapsClient(sqlkeys, parmas...)
}
func (engine *Engine) SqlTemplatesClient(sqlkeys interface{}, parmas ...interface{}) *SqlTemplatesExecutor {
session := engine.NewSession()
session.IsAutoClose = true
session.IsSqlFuc = true
return session.SqlTemplatesClient(sqlkeys, parmas...)
}