mgutz / dat

Go Postgres Data Access Toolkit
Other
612 stars 62 forks source link

Support setting nullable fields #79

Open cbelsole opened 6 years ago

cbelsole commented 6 years ago

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.