Skip to content

Conversation

@adam-frisby
Copy link

This pull request adds Null* types from the database/sql package to the Hood SQL Types and adds support for the types in SetModelValue. I've tested the changes with both mysql and postgresql. Everything looks to be working as expected. This will allow hood to handle values which may be null.


Example:

type Test struct {
    Id       hood.Id
    Number   sql.NullInt64
}

// Connect and Start Transaction

a = Test{}
tx.Save(&a) //Number column is set to NULL in database (defaults to NULL)

b = Test{}
b.Number = sql.NullInt64{128, true} //Number column is set to 128 in database
tx.Save(&b)

c = Test{}
c.Number = sql.NullInt64{128, false} //Number column is set to NULL in database since valid bool is set to false
tx.Save(&c)

Retrieving the row which was inserted by tx.Save(&c) above will give you a sql.NullInt64{0, false} for Number


Question: Since normal types (int, string, etc) can't represent a null value, should the notnull keyword be removed and assumed to be not null unless the column type is of type NullBool, NullInt64, etc?

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