1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-07 03:40:18 +00:00

orm support use any numeric type set QuerySeter.Limit value

This commit is contained in:
slene
2013-09-13 18:06:44 +08:00
parent 8e8d39d3cb
commit 1596aa7a34
4 changed files with 21 additions and 16 deletions

View File

@ -2,7 +2,6 @@ package orm
import (
"fmt"
"reflect"
)
type querySet struct {
@ -10,7 +9,7 @@ type querySet struct {
cond *Condition
related []string
relDepth int
limit int
limit int64
offset int64
orders []string
orm *orm
@ -35,19 +34,11 @@ func (o querySet) Exclude(expr string, args ...interface{}) QuerySeter {
}
func (o *querySet) setOffset(num interface{}) {
val := reflect.ValueOf(num)
switch num.(type) {
case int, int8, int16, int32, int64:
o.offset = val.Int()
case uint, uint8, uint16, uint32, uint64:
o.offset = int64(val.Uint())
default:
panic(fmt.Errorf("<QuerySeter> offset value need numeric not `%T`", num))
}
o.offset = ToInt64(num)
}
func (o querySet) Limit(limit int, args ...interface{}) QuerySeter {
o.limit = limit
func (o querySet) Limit(limit interface{}, args ...interface{}) QuerySeter {
o.limit = ToInt64(limit)
if len(args) > 0 {
o.setOffset(args[0])
}