feat(app): update
This commit is contained in:
@ -47,35 +47,35 @@ func CheckTable(c context.Context, table string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func InsertOne(c context.Context, table string, record interface{}) (*mongo.InsertOneResult, error) {
|
||||
func InsertOne(c context.Context, table string, record any) (*mongo.InsertOneResult, error) {
|
||||
if e := CheckTable(c, table); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return DB.Collection(table).InsertOne(c, record)
|
||||
}
|
||||
|
||||
func SaveOne(c context.Context, table string, filter, record interface{}) (*mongo.UpdateResult, error) {
|
||||
func SaveOne(c context.Context, table string, filter, record any) (*mongo.UpdateResult, error) {
|
||||
if e := CheckTable(c, table); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return DB.Collection(table).ReplaceOne(c, filter, record, options.Replace().SetUpsert(true))
|
||||
}
|
||||
|
||||
func DeleteOne(c context.Context, table string, record interface{}) (*mongo.DeleteResult, error) {
|
||||
func DeleteOne(c context.Context, table string, record any) (*mongo.DeleteResult, error) {
|
||||
if e := CheckTable(c, table); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return DB.Collection(table).DeleteOne(c, record)
|
||||
}
|
||||
|
||||
func UpdateByID(c context.Context, table string, id interface{}, record interface{}) (*mongo.UpdateResult, error) {
|
||||
func UpdateByID(c context.Context, table string, id any, record any) (*mongo.UpdateResult, error) {
|
||||
if e := CheckTable(c, table); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return DB.Collection(table).UpdateByID(c, id, bson.D{{Key: "$set", Value: record}})
|
||||
}
|
||||
|
||||
func Page(c context.Context, table string, page req.Page, filter bson.D, results interface{}) (int64, error) {
|
||||
func Page(c context.Context, table string, page req.Page, filter bson.D, results any) (int64, error) {
|
||||
if e := CheckTable(c, table); e != nil {
|
||||
return 0, e
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user