LinsRuis.HW1 3 months ago
parent
commit
748ea6b41b
  1. 39
      core/comms/xorms.go

39
core/comms/xorms.go

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

Loading…
Cancel
Save