Describe the feature
目前写scope函数是这样的
func WhereId(id uint) func(tx *gorm.DB) *gorm.DB{
// TODO
}
这样太麻烦了 每次要写很长的一串 func(tx *gorm.DB) *gorm.DB
能不能在包内增加一个
type Scope func(*DB) *DB
之后用的时候就很简单了
func WhereId(id uint) gorm.Scope{
// TODO
}
Motivation
Related Issues
Comment From: a631807682
This does not need to be provided by gorm, you can rename type by yourself.
type yourScope = func(db *gorm.DB) *gorm.DB
func WhereId(id uint) yourScope {
// TODO
}
Comment From: liyuan1125
这个不需要gorm提供,你可以自己重命名类型。
``` type yourScope = func(db gorm.DB) gorm.DB
func WhereId(id uint) yourScope { // TODO } ```
自定义的根本就不可以
func find(ctx context.Context, scopes ...Scope) {
db.Scopes(scopes...)
}
Cannot use 'scopes' (type []Scope) as the type []func(DB) DB