Skip to content

Commit

Permalink
Merge pull request #620 from upper/issue-616_add-limit-to-one
Browse files Browse the repository at this point in the history
Set "LIMIT 1" when using One()
  • Loading branch information
xiam authored Jan 9, 2021
2 parents bc21d72 + d3f71bb commit 0f7146a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/sqladapter/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ func (r *Result) All(dst interface{}) error {

// One fetches only one Result from the set.
func (r *Result) One(dst interface{}) error {
query, err := r.buildPaginator()
one := r.Limit(1).(*Result)
query, err := one.buildPaginator()
if err != nil {
r.setErr(err)
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/testsuite/sql_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *SQLTestSuite) TestPreparedStatementsCache() {

// This query is different on each iteration and generates a new
// prepared statement everytime it's called.
res := sess.Collection("artist").Find().Select(db.Raw(fmt.Sprintf("count(%d)", i)))
res := sess.Collection("artist").Find().Select(db.Raw(fmt.Sprintf("count(%d) AS c", i)))

var count map[string]uint64
err := res.One(&count)
Expand Down

0 comments on commit 0f7146a

Please sign in to comment.