Skip to content

Null values from results cannot map on scan #1

Description

@rahulrumalla

Currently, null values from the query results do not map and rather error out when trying to map to a struct's value type field. This however works if the target field is a pointer.

If the resulting value is null and the target is a value type field, resort to the default value
i.e., if the record 1, John, doe, john@doe.com, null is being mapped to the following struct

type struct User {
   ID int64 `db:"id"`
   FirstName string `db:"first_name"`
   LastName string `db:"last_name"`
   Email string `db:"email"`
   Phone string `db:"string"`
}

Phone should be set to an empty string. Currently this errors out.
However, we must retain the functionality of the value being set to null if the target is a pointer
i.e.,

Phone *string `db:"string"`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions