sqltemplate.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package xorm
  2. import (
  3. "html/template"
  4. "os"
  5. "github.com/CloudyKit/jet"
  6. "gopkg.in/flosch/pongo2.v3"
  7. )
  8. type FuncMap map[string]interface{}
  9. type SqlTemplate interface {
  10. WalkFunc(path string, info os.FileInfo, err error) error
  11. paresSqlTemplate(filename string, filepath string) error
  12. ReadTemplate(filepath string) ([]byte, error)
  13. Execute(key string, args ...interface{}) (string, error)
  14. RootDir() string
  15. Extension() string
  16. SetSqlTemplateCipher(cipher Cipher)
  17. LoadSqlTemplate(filepath string) error
  18. BatchLoadSqlTemplate(filepathSlice []string) error
  19. ReloadSqlTemplate(filepath string) error
  20. BatchReloadSqlTemplate(filepathSlice []string) error
  21. AddSqlTemplate(key string, sqlTemplateStr string) error
  22. UpdateSqlTemplate(key string, sqlTemplateStr string) error
  23. RemoveSqlTemplate(key string)
  24. BatchAddSqlTemplate(key string, sqlTemplateStrMap map[string]string) error
  25. BatchUpdateSqlTemplate(key string, sqlTemplateStrMap map[string]string) error
  26. BatchRemoveSqlTemplate(key []string)
  27. SetFuncs(key string, funcMap FuncMap)
  28. }
  29. func Pongo2(directory, extension string) *Pongo2Template {
  30. template := make(map[string]*pongo2.Template, 100)
  31. funcs := make(map[string]FuncMap, 20)
  32. return &Pongo2Template{
  33. SqlTemplateRootDir: directory,
  34. extension: extension,
  35. Template: template,
  36. Funcs: funcs,
  37. }
  38. }
  39. func Default(directory, extension string) *HTMLTemplate {
  40. template := make(map[string]*template.Template, 100)
  41. funcs := make(map[string]FuncMap, 20)
  42. return &HTMLTemplate{
  43. SqlTemplateRootDir: directory,
  44. extension: extension,
  45. Template: template,
  46. Funcs: funcs,
  47. }
  48. }
  49. func Jet(directory, extension string) *JetTemplate {
  50. template := make(map[string]*jet.Template, 100)
  51. funcs := make(map[string]FuncMap, 20)
  52. return &JetTemplate{
  53. SqlTemplateRootDir: directory,
  54. extension: extension,
  55. Template: template,
  56. Funcs: funcs,
  57. }
  58. }