Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DbMap.Get() returns (nil, nil) if no row is found. Is this a bug? #395

Open
takumi-n opened this issue May 6, 2019 · 2 comments
Open

DbMap.Get() returns (nil, nil) if no row is found. Is this a bug? #395

takumi-n opened this issue May 6, 2019 · 2 comments

Comments

@takumi-n
Copy link

takumi-n commented May 6, 2019

Example:

package main

import (
	"database/sql"
	"fmt"

	_ "github.com/lib/pq"

	"gopkg.in/gorp.v2"
)

type Foo struct {
	ID  int64  `db:"id,primarykey"`
	Bar string `db:"bar"`
}

func main() {
	db, _ := sql.Open("postgres", "postgresql://...")

	dbMap := gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}}
	dbMap.AddTableWithName(Foo{}, "foo").SetKeys(true, "ID")
	foo, err := dbMap.Get(Foo{}, 999) // There is no row corresponding to id = 999
	fmt.Println(foo, err) // The output will be nil, nil
}

DbMap.Get() returns (nil, nil) if no row is found.
I think it should returns (nil, error) if gorp cannot find any record.

Is this a bug?
or is there any reason?

@nelsam
Copy link
Member

nelsam commented May 6, 2019

I don't know the history, but it does seem that this is explicitly handled: https://github.com/go-gorp/gorp/blob/master/gorp.go#L427-L429

@coopernurse it looks like you were the last to touch that explicit line. Is there any chance that you remember the context around why we're avoiding returning sql.ErrNoRows in dbmap.Get?

@MasterDimmy
Copy link

ensure your connection is ok.
this happens if connection failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants