package comms import gocloud "github.com/mgr9525/go-cloud" // columns 第一个参数为where条件,(可选:第二个参数为表结构体或名称,第三个参数为单独获取的列名) func XormOne(id, data interface{}, columns ...interface{}) bool { return XormOneDb(DbSysHelper, id, data, columns...) } func XormOneDb(db *gocloud.DBHelper, id, data interface{}, columns ...interface{}) bool { if id == nil { return false } col := "id" cols := "" okkey := false if len(columns) > 0 && columns[0] != "" { cols, okkey = columns[0].(string) if okkey { col = cols } } 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 } if !has { return false } return true }