add return ErrMultiRows

This commit is contained in:
maxin[马鑫] 2016-04-25 15:51:12 +08:00
parent 9ce6dc4cdf
commit 56dc9bf622
2 changed files with 6 additions and 0 deletions

View File

@ -200,6 +200,10 @@ func (o *querySet) One(container interface{}, cols ...string) error {
if num == 0 {
return ErrNoRows
}
if num > 1 {
return ErrMultiRows
}
return nil
}

View File

@ -975,11 +975,13 @@ func TestOne(t *testing.T) {
err = qs.OrderBy("Id").Limit(1).One(&user)
throwFailNow(t, err)
throwFail(t, AssertIs(user.UserName, "slene"))
throwFail(t, AssertNot(err, ErrMultiRows))
user = User{}
err = qs.OrderBy("-Id").Limit(100).One(&user)
throwFailNow(t, err)
throwFail(t, AssertIs(user.UserName, "nobody"))
throwFail(t, AssertNot(err, ErrMultiRows))
err = qs.Filter("user_name", "nothing").One(&user)
throwFail(t, AssertIs(err, ErrNoRows))