Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f31bf24ec2 | |||
| 30edb4d9fa |
+31
-1
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user