2020-11-03 14:45:39 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2021-04-23 10:52:40 +01:00
|
|
|
"storj.io/private/tagsql"
|
2020-11-03 14:45:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func withRows(rows tagsql.Rows, err error) func(func(tagsql.Rows) error) error {
|
|
|
|
return func(callback func(tagsql.Rows) error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err := callback(rows)
|
|
|
|
return errs.Combine(rows.Err(), rows.Close(), err)
|
|
|
|
}
|
|
|
|
}
|
2021-06-25 09:19:32 +01:00
|
|
|
|
|
|
|
// intLimitRange defines a valid range (1,limit].
|
|
|
|
type intLimitRange int
|
|
|
|
|
|
|
|
// Ensure clamps v to a value between [1,limit].
|
|
|
|
func (limit intLimitRange) Ensure(v *int) {
|
|
|
|
if *v <= 0 || *v > int(limit) {
|
|
|
|
*v = int(limit)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Max returns maximum value for the given range.
|
|
|
|
func (limit intLimitRange) Max() int { return int(limit) }
|