From 23d12a6d6fa234ea39e6031854e1088607bc2acb Mon Sep 17 00:00:00 2001 From: "LinsRuis.HW1" Date: Tue, 4 Mar 2025 21:29:33 +0800 Subject: [PATCH] ... --- core/comms/xorms.go | 52 ++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/core/comms/xorms.go b/core/comms/xorms.go index 36d06e3..98fe50c 100644 --- a/core/comms/xorms.go +++ b/core/comms/xorms.go @@ -1,6 +1,9 @@ package comms -import gocloud "github.com/mgr9525/go-cloud" +import ( + gocloud "github.com/mgr9525/go-cloud" + "github.com/sirupsen/logrus" +) // columns 第一个参数为where条件,(可选:第二个参数为表结构体或名称,第三个参数为单独获取的列名) 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 { return false } + ses := db.GetDB().NewSession() 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 + } 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 { + logrus.Errorf("XormOneDb db err:%v", err) return false } if !has {