forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scopes.go
38 lines (35 loc) · 903 Bytes
/
scopes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package pop
// ScopeFunc applies a custom operation on a given `Query`
type ScopeFunc func(q *Query) *Query
// Scope the query by using a `ScopeFunc`
//
// func ByName(name string) ScopeFunc {
// return func(q *Query) *Query {
// return q.Where("name = ?", name)
// }
// }
//
// func WithDeleted(q *pop.Query) *pop.Query {
// return q.Where("deleted_at is null")
// }
//
// c.Scope(ByName("mark)).Scope(WithDeleted).First(&User{})
func (q *Query) Scope(sf ScopeFunc) *Query {
return sf(q)
}
// Scope the query by using a `ScopeFunc`
//
// func ByName(name string) ScopeFunc {
// return func(q *Query) *Query {
// return q.Where("name = ?", name)
// }
// }
//
// func WithDeleted(q *pop.Query) *pop.Query {
// return q.Where("deleted_at is null")
// }
//
// c.Scope(ByName("mark)).Scope(WithDeleted).First(&User{})
func (c *Connection) Scope(sf ScopeFunc) *Query {
return Q(c).Scope(sf)
}