Compare commits

..

5 Commits

Author SHA1 Message Date
hoteas 65f062b860 数据库操作bug 2022-08-31 11:20:58 +08:00
hoteas 7b502fed36 数据库操作bug 2022-08-31 11:14:45 +08:00
hoteas fd6b15bdaf 修正查询bug 2022-08-30 06:21:46 +08:00
hoteas f31bf24ec2 增加mongodb驱动,简单版本 2022-08-30 04:44:37 +08:00
hoteas 30edb4d9fa 增加mongodb驱动,简单版本 2022-08-30 04:05:17 +08:00
2 changed files with 37 additions and 12 deletions
+6 -11
View File
@@ -1016,7 +1016,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
if keywordTableStr != "" { if keywordTableStr != "" {
if keywordTableStr == v.GetString("name") { if keywordTableStr == v.GetString("name") {
keyword[table+"."+keywordTableStr+"[~]"] = keywordStr data[table+"."+keywordTableStr+"[~]"] = keywordStr
} }
if keywordTableStr == v.GetString("value") { if keywordTableStr == v.GetString("value") {
@@ -1026,7 +1026,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
childIds = append(childIds, cv.GetString("id")) childIds = append(childIds, cv.GetString("id"))
} }
if len(childIds) != 0 { if len(childIds) != 0 {
keyword[v.GetString("link")+".id"] = childIds data[v.GetString("link")+".id"] = childIds
} }
} }
continue continue
@@ -1143,17 +1143,12 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
data[k] = v data[k] = v
} }
} }
if len(keyword) > 1 { if len(keyword) > 1 {
if data["OR"] != nil {
if data["AND"] != nil { data = Map{"AND": data, "OR": keyword}
and := data.GetMap("AND")
for k, v := range keyword {
and[k] = v
}
//data = Map{"AND":Map{"OR": keyword} data, }
} else { } else {
data["AND"] = keyword data["OR"] = keyword
} }
} }
+31 -1
View File
@@ -65,6 +65,32 @@ func (that *mongoDb) InsertMany(table string, data ...interface{}) Slice {
} }
func (that *mongoDb) Update(table string, data Map, where Map) int64 {
collection := that.DataBase.Collection(table)
re, err := collection.UpdateMany(that.Ctx, where, data)
if err != nil {
that.LastErr = err
return 0
}
return re.ModifiedCount
}
func (that *mongoDb) Delete(table string, where Map) int64 {
collection := that.DataBase.Collection(table)
re, err := collection.DeleteMany(that.Ctx, where)
if err != nil {
that.LastErr = err
return 0
}
return re.DeletedCount
}
func (that *mongoDb) Get(table string, where Map) Map { func (that *mongoDb) Get(table string, where Map) Map {
results := []Map{} results := []Map{}
var cursor *mongo.Cursor var cursor *mongo.Cursor
@@ -86,7 +112,11 @@ func (that *mongoDb) Get(table string, where Map) Map {
that.LastErr = err that.LastErr = err
return nil return nil
} }
return results[0] if len(results) > 0 {
return results[0]
}
return nil
} }
func (that mongoDb) Select(table string, where Map, page, pageRow int64) []Map { func (that mongoDb) Select(table string, where Map, page, pageRow int64) []Map {