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

Error: on NULL from DB #122

Closed
efureev opened this issue Aug 2, 2019 · 4 comments
Closed

Error: on NULL from DB #122

efureev opened this issue Aug 2, 2019 · 4 comments

Comments

@efureev
Copy link

efureev commented Aug 2, 2019

Error: sql: Scan error on column index 1, name "deleted_at": unsupported Scan, storing driver.Value type into type *time.Time

type User struct {
	Id           string `json:"id" db:"id" goqu:"skipinsert,skipupdate"`
	Email        string    `json:"email" db:"email"`
	PasswordHash []byte    `json:"-" db:"password"`
	Name         string    `json:"name" db:"name"`
	Deleted      *time.Time `json:"-" db:"deleted_at"`
	CreatedAt    time.Time `json:"-" db:"created_at" goqu:"skipinsert,skipupdate"`
}
//...
item := User{}
found, err := database.From(`users`).Where(goqu.C(`email`).Eq(`simple@auth.xx`)).ScanStruct(&item)
if err != nil {
	log.Panicf(`Find: %s`, err)
}

//sql: INSERT INTO public.users (id, email, name, password, deleted_at, created_at) VALUES ('4792668f-d192-4dd7-9c47-a70e1e15c602', 'simple@auth.xx', 'Simple', '$2a$08$iNL1iAhLRNSWiJbvuwXTTeTOsBmhZMZnXIlL01twyXwmy9hZeevSi', null, '2019-08-02 11:01:57.908624');

@doug-martin
Copy link
Owner

This is most likely related to the driver you are using, which dialect are you using?

If you're using mysql you probably need to add the parseTime query arg https://stackoverflow.com/questions/45040319/unsupported-scan-storing-driver-value-type-uint8-into-type-time-time

@efureev
Copy link
Author

efureev commented Aug 3, 2019

postgres. In v6 is working =)
There isn't scan NULL from Postgres into NIL *time.Time

If add field Photo to User struct:

type User struct {
	Id           string     `json:"id" db:"id" goqu:"skipinsert,skipupdate"`
	Name         string     `json:"name" db:"name"`
	Photo        *string    `db:"photo"`}

Error will be sql: Scan error on column index 2, name "photo": unsupported Scan, storing driver.Value type <nil> into type *string if value of photo in PG - NULL

@doug-martin
Copy link
Owner

Ok I found the issue, Im working on a fix.

I should note for both of your use cases I would recommend using the Null types provided by the sql and pq modules. See https://golang.org/pkg/database/sql/#NullString and https://godoc.org/github.com/lib/pq#NullTime

doug-martin added a commit that referenced this issue Aug 3, 2019
* [FIX] Scanner errors on pointers to primitive values #122
doug-martin added a commit that referenced this issue Aug 3, 2019
* [FIX] Scanner errors on pointers to primitive values #122
doug-martin added a commit that referenced this issue Aug 3, 2019
@doug-martin
Copy link
Owner

Fix has been merged and released as v8.2.2

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

2 participants