|
@ -1,6 +1,9 @@ |
|
|
package comms |
|
|
package comms |
|
|
|
|
|
|
|
|
import gocloud "github.com/mgr9525/go-cloud" |
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
gocloud "github.com/mgr9525/go-cloud" |
|
|
|
|
|
"github.com/sirupsen/logrus" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
// columns 第一个参数为where条件,(可选:第二个参数为表结构体或名称,第三个参数为单独获取的列名)
|
|
|
// columns 第一个参数为where条件,(可选:第二个参数为表结构体或名称,第三个参数为单独获取的列名)
|
|
|
func XormOne(id, data interface{}, columns ...interface{}) bool { |
|
|
func XormOne(id, data interface{}, columns ...interface{}) bool { |
|
@ -10,47 +13,28 @@ func XormOneDb(db *gocloud.DBHelper, id, data interface{}, columns ...interface{ |
|
|
if id == nil { |
|
|
if id == nil { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
ses := db.GetDB().NewSession() |
|
|
col := "id" |
|
|
col := "id" |
|
|
cols := "" |
|
|
|
|
|
okkey := false |
|
|
|
|
|
if len(columns) > 0 && columns[0] != "" { |
|
|
|
|
|
cols, okkey = columns[0].(string) |
|
|
|
|
|
if okkey { |
|
|
|
|
|
|
|
|
if len(columns) > 0 { |
|
|
|
|
|
cols, ok := columns[0].(string) |
|
|
|
|
|
if ok { |
|
|
col = cols |
|
|
col = cols |
|
|
|
|
|
} else { |
|
|
|
|
|
ses = ses.Table(columns[0]) |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
ses := db.GetDB().Where(col+" = ?", id) |
|
|
|
|
|
|
|
|
|
|
|
var tb interface{} |
|
|
|
|
|
var tbcol interface{} |
|
|
|
|
|
if okkey { |
|
|
|
|
|
if len(columns) > 2 { |
|
|
|
|
|
if columns[1] != nil && columns[2] != nil { |
|
|
|
|
|
tb = columns[1] |
|
|
|
|
|
tbcol = columns[2] |
|
|
|
|
|
|
|
|
if len(columns) > 1 { |
|
|
|
|
|
for _, v := range columns[1:] { |
|
|
|
|
|
cols, ok := v.(string) |
|
|
|
|
|
if ok { |
|
|
|
|
|
ses = ses.Cols(cols) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} else if len(columns) > 1 { |
|
|
|
|
|
if columns[1] != nil { |
|
|
|
|
|
tbcol = columns[1] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
if len(columns) > 1 && columns[1] != nil { |
|
|
|
|
|
tb = columns[0] |
|
|
|
|
|
tbcol = columns[1] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if tb != nil { |
|
|
|
|
|
ses = ses.Table(tb) |
|
|
|
|
|
} |
|
|
|
|
|
if tbcol != nil { |
|
|
|
|
|
cols, ok := tbcol.(string) |
|
|
|
|
|
if ok { |
|
|
|
|
|
ses = ses.Cols(cols) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
has, err := ses.Get(data) |
|
|
|
|
|
|
|
|
has, err := ses.Where(col+" = ?", id).Get(data) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
|
|
|
logrus.Errorf("XormOneDb db err:%v", err) |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
if !has { |
|
|
if !has { |
|
|