Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
1596aa7a
authored
2013-09-13 18:06:44 +0800
by
slene
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
orm support use any numeric type set QuerySeter.Limit value
1 parent
8e8d39d3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
16 deletions
orm/db_tables.go
orm/orm_queryset.go
orm/types.go
orm/utils.go
orm/db_tables.go
View file @
1596aa7
...
...
@@ -360,9 +360,9 @@ func (d *dbTables) getOrderSql(orders []string) (orderSql string) {
return
}
func
(
d
*
dbTables
)
getLimitSql
(
mi
*
modelInfo
,
offset
int64
,
limit
int
)
(
limits
string
)
{
func
(
d
*
dbTables
)
getLimitSql
(
mi
*
modelInfo
,
offset
int64
,
limit
int
64
)
(
limits
string
)
{
if
limit
==
0
{
limit
=
DefaultRowsLimit
limit
=
int64
(
DefaultRowsLimit
)
}
if
limit
<
0
{
// no limit
...
...
orm/orm_queryset.go
View file @
1596aa7
...
...
@@ -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
int
64
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
int
erface
{}
,
args
...
interface
{})
QuerySeter
{
o
.
limit
=
ToInt64
(
limit
)
if
len
(
args
)
>
0
{
o
.
setOffset
(
args
[
0
])
}
...
...
orm/types.go
View file @
1596aa7
...
...
@@ -45,7 +45,7 @@ type QuerySeter interface {
Filter
(
string
,
...
interface
{})
QuerySeter
Exclude
(
string
,
...
interface
{})
QuerySeter
SetCond
(
*
Condition
)
QuerySeter
Limit
(
int
,
...
interface
{})
QuerySeter
Limit
(
int
erface
{}
,
...
interface
{})
QuerySeter
Offset
(
interface
{})
QuerySeter
OrderBy
(
...
string
)
QuerySeter
RelatedSel
(
...
interface
{})
QuerySeter
...
...
orm/utils.go
View file @
1596aa7
...
...
@@ -2,6 +2,7 @@ package orm
import
(
"fmt"
"reflect"
"strconv"
"strings"
"time"
...
...
@@ -133,6 +134,19 @@ func ToStr(value interface{}, args ...int) (s string) {
return
s
}
func
ToInt64
(
value
interface
{})
(
d
int64
)
{
val
:=
reflect
.
ValueOf
(
value
)
switch
value
.
(
type
)
{
case
int
,
int8
,
int16
,
int32
,
int64
:
d
=
val
.
Int
()
case
uint
,
uint8
,
uint16
,
uint32
,
uint64
:
d
=
int64
(
val
.
Uint
())
default
:
panic
(
fmt
.
Errorf
(
"ToInt64 need numeric not `%T`"
,
value
))
}
return
}
func
snakeString
(
s
string
)
string
{
data
:=
make
([]
byte
,
0
,
len
(
s
)
*
2
)
j
:=
false
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment