feat(app): update

This commit is contained in:
Yangtao
2025-11-19 14:24:13 +08:00
parent 1eac66d7fd
commit 0c34585649
329 changed files with 10760 additions and 281 deletions

View File

@ -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
}