-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.go
More file actions
46 lines (38 loc) · 905 Bytes
/
template.go
File metadata and controls
46 lines (38 loc) · 905 Bytes
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
package engine
import (
"sync"
"text/template"
)
type Engine struct {
tempalte *template.Template
parser *SqlParser
lock sync.RWMutex
cache map[string]string
isCacheEnabled bool
}
func createEngine() *Engine {
parser := NewSqlParser()
tmpl := template.New("__rabbit__").Funcs(template.FuncMap{
"marshal": marshal,
"__sql_arg__": parser.Parse,
"__default_placeholder__": DefaultPlaceHolder,
})
return &Engine{
tempalte: tmpl,
parser: parser,
cache: make(map[string]string, 0),
isCacheEnabled: true,
}
}
func NewEngine() *Engine {
engine := createEngine()
engine.parser.placeHolder = &PostgresPlaceholder{
index: 0,
}
return engine
}
func NewEngineWithPlaceHolder(placeHolder PlaceHolder) *Engine {
engine := createEngine()
engine.parser.placeHolder = placeHolder
return engine
}