|
|
@@ -2,8 +2,6 @@ package xorm
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
-
|
|
|
- "github.com/Chronokeeper/anyxml"
|
|
|
)
|
|
|
|
|
|
func (engine *Engine) SqlMapClient(sqlTagName string, args ...interface{}) *Session {
|
|
|
@@ -15,8 +13,8 @@ func (engine *Engine) SqlMapClient(sqlTagName string, args ...interface{}) *Sess
|
|
|
func (engine *Engine) SqlTemplateClient(sqlTagName string, args ...interface{}) *Session {
|
|
|
session := engine.NewSession()
|
|
|
session.IsAutoClose = true
|
|
|
- map1:=args[0].(map[string]interface{})
|
|
|
- if engine.SqlTemplate.Template[sqlTagName]==nil{
|
|
|
+ map1 := args[0].(map[string]interface{})
|
|
|
+ if engine.SqlTemplate.Template[sqlTagName] == nil {
|
|
|
return session.Sql("", &map1)
|
|
|
}
|
|
|
sql, err := engine.SqlTemplate.Template[sqlTagName].Execute(map1)
|
|
|
@@ -49,104 +47,6 @@ func (engine *Engine) QueryAllByMap(sql string, paramMap interface{}) (resultsSl
|
|
|
return session.queryAllByMap(sql, paramMap)
|
|
|
}
|
|
|
|
|
|
-func (engine *Engine) QueryAllByMapToJsonString(sql string, paramMap interface{}) (string, error) {
|
|
|
- session := engine.NewSession()
|
|
|
- defer session.Close()
|
|
|
- results, err := session.queryAllByMap(sql, paramMap)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return JSONString(results, true)
|
|
|
-}
|
|
|
-
|
|
|
-func (engine *Engine) QueryAllByMapToJsonStringWithDateFormat(dateFormat string, sql string, paramMap interface{}) (string, error) {
|
|
|
- session := engine.NewSession()
|
|
|
- defer session.Close()
|
|
|
- results, err := session.queryAllByMapWithDateFormat(dateFormat, sql, paramMap)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return JSONString(results, true)
|
|
|
-}
|
|
|
-
|
|
|
-func (engine *Engine) QueryAllToJsonString(sql string, paramStr ...interface{}) (string, error) {
|
|
|
- session := engine.NewSession()
|
|
|
- defer session.Close()
|
|
|
- results, err := session.queryAll(sql, paramStr...)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return JSONString(results, true)
|
|
|
-}
|
|
|
-
|
|
|
-func (engine *Engine) QueryAllToJsonStringWithDateFormat(dateFormat string, sql string, paramStr ...interface{}) (string, error) {
|
|
|
- session := engine.NewSession()
|
|
|
- defer session.Close()
|
|
|
- results, err := session.queryAllWithDateFormat(dateFormat, sql, paramStr...)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return JSONString(results, true)
|
|
|
-}
|
|
|
-
|
|
|
-func (engine *Engine) queryAllToXmlString(sql string, paramStr ...interface{}) (string, error) {
|
|
|
- session := engine.NewSession()
|
|
|
- defer session.Close()
|
|
|
- resultSlice, err := session.queryAll(sql, paramStr...)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
-
|
|
|
- results, err := anyxml.Xml(resultSlice, "result")
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return string(results), nil
|
|
|
-}
|
|
|
-
|
|
|
-func (engine *Engine) queryAllToXmlIndentString(sql string, prefix string, indent string, paramStr ...interface{}) (string, error) {
|
|
|
- session := engine.NewSession()
|
|
|
- defer session.Close()
|
|
|
- resultSlice, err := session.queryAll(sql, paramStr...)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- results, err := anyxml.XmlIndent(resultSlice, prefix, indent, "result")
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return string(results), nil
|
|
|
-}
|
|
|
-
|
|
|
-func (engine *Engine) queryAllToXmlStringWithDateFormat(dateFormat string, sql string, paramStr ...interface{}) (string, error) {
|
|
|
- session := engine.NewSession()
|
|
|
- defer session.Close()
|
|
|
- resultSlice, err := session.queryAll(sql, paramStr...)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- results, err := anyxml.XmlWithDateFormat(dateFormat, resultSlice)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return string(results), nil
|
|
|
-}
|
|
|
-
|
|
|
-func (engine *Engine) QueryAllToXmlIndentStringWithDateFormat(dateFormat string, sql string, prefix string, indent string, paramStr ...interface{}) (string, error) {
|
|
|
- session := engine.NewSession()
|
|
|
- defer session.Close()
|
|
|
- resultSlice, err := session.queryAll(sql, paramStr...)
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- results, err := anyxml.XmlIndentWithDateFormat(dateFormat, resultSlice, "", " ", "results")
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return "", err
|
|
|
- }
|
|
|
- return string(results), nil
|
|
|
-}
|
|
|
-
|
|
|
func JSONString(v interface{}, IndentJSON bool) (string, error) {
|
|
|
var result []byte
|
|
|
var err error
|
|
|
@@ -159,7 +59,7 @@ func JSONString(v interface{}, IndentJSON bool) (string, error) {
|
|
|
return "", err
|
|
|
}
|
|
|
|
|
|
- if string(result)=="null"{
|
|
|
+ if string(result) == "null" {
|
|
|
return "", nil
|
|
|
}
|
|
|
return string(result), nil
|