Merge pull request #7 from lbryio/guard_null_mod

Allow null query mods for dynamic queries
This commit is contained in:
Mark 2019-07-01 23:56:28 -04:00 committed by GitHub
commit 3f035a9fe2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,7 +8,9 @@ type QueryMod func(q *queries.Query)
// Apply the query mods to the Query object // Apply the query mods to the Query object
func Apply(q *queries.Query, mods ...QueryMod) { func Apply(q *queries.Query, mods ...QueryMod) {
for _, mod := range mods { for _, mod := range mods {
mod(q) if mod != nil {
mod(q)
}
} }
} }
@ -123,13 +125,12 @@ func From(from string) QueryMod {
} }
} }
func ForceIndex( index string) QueryMod { func ForceIndex(index string) QueryMod {
return func(q *queries.Query) { return func(q *queries.Query) {
queries.SetForceIndex(q, index) queries.SetForceIndex(q, index)
} }
} }
// Limit the number of returned rows // Limit the number of returned rows
func Limit(limit int) QueryMod { func Limit(limit int) QueryMod {
return func(q *queries.Query) { return func(q *queries.Query) {