type Example1 struct {
TableName struct{} sql:"example_table"
Name string sql:"name"
Amount int sql:"amount"
}
type Example2 struct {
TableName struct{} sql:"example_table"
Name string sql:"name"
}
Now when I create row using Example1 without passing any amount for a row then in postgres db it automatically fills amount as 0, but when I use Example2 - amount column remains NULL.
I want to use Example1 and fill amount as NULL if I don’t pass any value. I don’t want it to fill 0 for amount column automatically.
I made Name and Amount’s types sql.NullString and sql.NullInt64, respectively. If you check the documentation of these types, you’ll see that they’re structs. Because they’re structs, you have to either assign structs to them: