QRM returns sql.ErrNoRows when scanning into struct destination and query result set is empty.

This commit is contained in:
go-jet 2019-10-12 18:45:09 +02:00
parent 3544977d7f
commit f9efee77ff
7 changed files with 103 additions and 90 deletions

View file

@ -1,6 +1,7 @@
package postgres
import (
"database/sql"
"fmt"
"github.com/go-jet/jet/internal/testutils"
. "github.com/go-jet/jet/postgres"
@ -694,6 +695,35 @@ func TestScanToSlice(t *testing.T) {
})
}
func TestStructScanErrNoRows(t *testing.T) {
query := SELECT(Customer.AllColumns).
FROM(Customer).
WHERE(Customer.CustomerID.EQ(Int(-1)))
customer := model.Customer{}
err := query.Query(db, &customer)
assert.Error(t, err, sql.ErrNoRows.Error())
}
func TestStructScanAllNull(t *testing.T) {
query := SELECT(NULL.AS("null1"), NULL.AS("null2"))
dest := struct {
Null1 *int
Null2 *int
}{}
err := query.Query(db, &dest)
assert.NilError(t, err)
assert.DeepEqual(t, dest, struct {
Null1 *int
Null2 *int
}{})
}
var address256 = model.Address{
AddressID: 256,
Address: "1497 Yuzhou Drive",