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

Support setting nullable fields #79

Open
wants to merge 2 commits into
base: v1
Choose a base branch
from

Conversation

cbelsole
Copy link

@cbelsole cbelsole commented Apr 6, 2018

Issue

Added support for setting a nullable field. Previously this would fail because a nil pointer cannot be set:

# Nullable  *string         `db:"nullable"`

person3 := Person{Name: "Barack", Nullable: nil}
err = s.
	InsertInto("people").
	Columns("name", "nullable").
	Record(person3).
	Returning("id", "nullable").
	QueryStruct(&person3)

Fix

The fix (discovered by @pascallouisperez) is to skip fields that !v.CanSet().

Tests

I added tests for inserting selecting and updating nullable fields.

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

Successfully merging this pull request may close these issues.

1 participant