good morning!!!!

Skip to content
Snippets Groups Projects
Commit 62638779 authored by José Carlos's avatar José Carlos
Browse files

Merge pull request #179 from upper/issue-173

Renaming Skip() and Sort() into Offset() and OrderBy()
parents 72c8b455 9c1c8675
No related branches found
No related tags found
No related merge requests found
......@@ -424,16 +424,16 @@ type Result interface {
// Limit defines the maximum number of results in this set. It only has
// effect on `One()`, `All()` and `Next()`.
Limit(uint) Result
Limit(int) Result
// Skip ignores the first *n* results. It only has effect on `One()`, `All()`
// Offset ignores the first *n* results. It only has effect on `One()`, `All()`
// and `Next()`.
Skip(uint) Result
Offset(int) Result
// Sort receives field names that define the order in which elements will be
// OrderBy receives field names that define the order in which elements will be
// returned in a query, field names may be prefixed with a minus sign (-)
// indicating descending order, ascending order will be used otherwise.
Sort(...interface{}) Result
OrderBy(...interface{}) Result
// Select defines specific columns to be returned from the elements of the
// set.
......@@ -446,15 +446,15 @@ type Result interface {
// or columns.
Group(...interface{}) Result
// Remove deletes all items within the result set. `Skip()` and `Limit()` are
// Remove deletes all items within the result set. `Offset()` and `Limit()` are
// not honoured by `Remove()`.
Remove() error
// Update modifies all items within the result set. `Skip()` and `Limit()`
// Update modifies all items within the result set. `Offset()` and `Limit()`
// are not honoured by `Update()`.
Update(interface{}) error
// Count returns the number of items that match the set conditions. `Skip()`
// Count returns the number of items that match the set conditions. `Offset()`
// and `Limit()` are not honoured by `Count()`
Count() (uint64, error)
......
......@@ -711,11 +711,11 @@ func TestFibonacci(t *testing.T) {
// Testing sort by function.
switch wrapper {
case `postgresql`:
res = res.Sort(db.Raw(`RANDOM()`))
res = res.OrderBy(db.Raw(`RANDOM()`))
case `sqlite`:
res = res.Sort(db.Raw(`RANDOM()`))
res = res.OrderBy(db.Raw(`RANDOM()`))
case `mysql`:
res = res.Sort(db.Raw(`RAND()`))
res = res.OrderBy(db.Raw(`RAND()`))
}
total, err = res.Count()
......@@ -729,7 +729,7 @@ func TestFibonacci(t *testing.T) {
}
// Find() with IN/$in
res = col.Find(db.Cond{"input IN": []int{3, 5, 6, 7}}).Sort("input")
res = col.Find(db.Cond{"input IN": []int{3, 5, 6, 7}}).OrderBy("input")
total, err = res.Count()
......@@ -741,7 +741,7 @@ func TestFibonacci(t *testing.T) {
t.Fatalf(`Expecting a count of 4.`)
}
res = res.Skip(1).Limit(2)
res = res.Offset(1).Limit(2)
for {
var item fibonacci
......@@ -773,7 +773,7 @@ func TestFibonacci(t *testing.T) {
),
db.Cond{"input": 3},
),
).Sort("-input")
).OrderBy("-input")
if total, err = res.Count(); err != nil {
t.Fatalf(`%s: %q`, wrapper, err)
......@@ -784,7 +784,7 @@ func TestFibonacci(t *testing.T) {
}
// Skipping.
res = res.Skip(1).Limit(2)
res = res.Offset(1).Limit(2)
for {
var item fibonacci
......
......@@ -61,15 +61,15 @@ func (r *Result) Where(conds ...interface{}) db.Result {
}
// Limit determines the maximum limit of Results to be returned.
func (r *Result) Limit(n uint) db.Result {
r.limit = int(n)
func (r *Result) Limit(n int) db.Result {
r.limit = n
return r
}
// Skip determines how many documents will be skipped before starting to grab
// Offset determines how many documents will be skipped before starting to grab
// Results.
func (r *Result) Skip(n uint) db.Result {
r.offset = int(n)
func (r *Result) Offset(n int) db.Result {
r.offset = n
return r
}
......@@ -80,10 +80,10 @@ func (r *Result) Group(fields ...interface{}) db.Result {
return r
}
// Sort determines sorting of Results according to the provided names. Fields
// OrderBy determines sorting of Results according to the provided names. Fields
// may be prefixed by - (minus) which means descending order, ascending order
// would be used otherwise.
func (r *Result) Sort(fields ...interface{}) db.Result {
func (r *Result) OrderBy(fields ...interface{}) db.Result {
r.orderBy = fields
return r
}
......
......@@ -64,22 +64,22 @@ func (r *result) Where(terms ...interface{}) db.Result {
}
// Limit determines the maximum limit of results to be returned.
func (r *result) Limit(n uint) db.Result {
r.queryChunks.Limit = int(n)
func (r *result) Limit(n int) db.Result {
r.queryChunks.Limit = n
return r
}
// Skip determines how many documents will be skipped before starting to grab
// Offset determines how many documents will be skipped before starting to grab
// results.
func (r *result) Skip(n uint) db.Result {
r.queryChunks.Offset = int(n)
func (r *result) Offset(n int) db.Result {
r.queryChunks.Offset = n
return r
}
// Sort determines sorting of results according to the provided names. Fields
// OrderBy determines sorting of results according to the provided names. Fields
// may be prefixed by - (minus) which means descending order, ascending order
// would be used otherwise.
func (r *result) Sort(fields ...interface{}) db.Result {
func (r *result) OrderBy(fields ...interface{}) db.Result {
ss := make([]string, len(fields))
for i, field := range fields {
ss[i] = fmt.Sprintf(`%v`, field)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment