From 1764c8ef8f2a14a9428dd529b23ba0df78d6bf64 Mon Sep 17 00:00:00 2001 From: Harman Date: Thu, 11 Feb 2021 00:13:00 +0800 Subject: [PATCH] feat: define short function name easy to use --- chainable_api.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chainable_api.go b/chainable_api.go index 58b9336f..f09c4864 100644 --- a/chainable_api.go +++ b/chainable_api.go @@ -9,6 +9,9 @@ import ( "gorm.io/gorm/utils" ) +// Scope define short function name easy to use +type Scope func(*DB) *DB + // Model specify the model you would like to run db operations // // update all users's name to `hello` // db.Model(&User{}).Update("name", "hello") @@ -240,7 +243,7 @@ func (db *DB) Offset(offset int) (tx *DB) { // } // // db.Scopes(AmountGreaterThan1000, OrderStatus([]string{"paid", "shipped"})).Find(&orders) -func (db *DB) Scopes(funcs ...func(*DB) *DB) *DB { +func (db *DB) Scopes(funcs ...Scope) *DB { for _, f := range funcs { db = f(db) }