From b940afa6b0d34f448f784aef891a821f14011ee3 Mon Sep 17 00:00:00 2001 From: hoteas Date: Mon, 15 Aug 2022 05:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/hotimedb.go | 92 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 7 deletions(-) diff --git a/db/hotimedb.go b/db/hotimedb.go index 6292c4c..a63a8a1 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -70,7 +70,21 @@ func (that *HotimeDBBuilder) Select(qu ...interface{}) []Map { return that.HoTimeDB.Select(that.table, that.join, qu, that.where) } -func (that *HotimeDBBuilder) Update(data Map) int64 { +func (that *HotimeDBBuilder) Update(qu ...interface{}) int64 { + lth := len(qu) + if lth == 0 { + return 0 + } + data := Map{} + if lth == 1 { + data = ObjToMap(qu[0]) + } + if lth > 1 { + for k := 1; k < lth; k++ { + data[ObjToStr(k-1)] = qu[k] + k++ + } + } return that.HoTimeDB.Update(that.table, data, that.where) } @@ -101,19 +115,51 @@ func (that *HotimeDBBuilder) FullJoin(table, joinStr string) *HotimeDBBuilder { return that } -func (that *HotimeDBBuilder) Join(join Map) *HotimeDBBuilder { +func (that *HotimeDBBuilder) Join(qu ...interface{}) *HotimeDBBuilder { + lth := len(qu) + if lth == 0 { + return that + } + data := Map{} + if lth == 1 { + data = ObjToMap(qu[0]) + } + if lth > 1 { + for k := 1; k < lth; k++ { + data[ObjToStr(k-1)] = qu[k] + k++ + } + } + if that.join == nil { that.join = Slice{} } - if join == nil { + if data == nil { return that } - that.join = append(that.join, join) + that.join = append(that.join, data) return that } -func (that *HotimeDBBuilder) And(where Map) *HotimeDBBuilder { +func (that *HotimeDBBuilder) And(qu ...interface{}) *HotimeDBBuilder { + + lth := len(qu) + if lth == 0 { + return that + } + var where Map + if lth == 1 { + where = ObjToMap(qu[0]) + } + if lth > 1 { + where = Map{} + for k := 1; k < lth; k++ { + where[ObjToStr(k-1)] = qu[k] + k++ + } + } + if where == nil { return that } @@ -129,7 +175,22 @@ func (that *HotimeDBBuilder) And(where Map) *HotimeDBBuilder { return that } -func (that *HotimeDBBuilder) Or(where Map) *HotimeDBBuilder { +func (that *HotimeDBBuilder) Or(qu ...interface{}) *HotimeDBBuilder { + lth := len(qu) + if lth == 0 { + return that + } + var where Map + if lth == 1 { + where = ObjToMap(qu[0]) + } + if lth > 1 { + where = Map{} + for k := 1; k < lth; k++ { + where[ObjToStr(k-1)] = qu[k] + k++ + } + } if where == nil { return that } @@ -144,7 +205,24 @@ func (that *HotimeDBBuilder) Or(where Map) *HotimeDBBuilder { return that } -func (that *HotimeDBBuilder) Where(where Map) *HotimeDBBuilder { +func (that *HotimeDBBuilder) Where(qu ...interface{}) *HotimeDBBuilder { + + lth := len(qu) + if lth == 0 { + return that + } + var where Map + if lth == 1 { + where = ObjToMap(qu[0]) + } + if lth > 1 { + where = Map{} + for k := 1; k < lth; k++ { + where[ObjToStr(k-1)] = qu[k] + k++ + } + } + if where == nil { return that }