You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When inserting/updating by struct, I couldn't find a way to force the column DEFAULT.
INSERT into table (column_with_default) values (DEFAULT);
UPDATE table SET column_with_default = DEFAULT;
Some ideas:
1: Add a tag like defaultifempty. This would work well for most use-cases, but wouldn't allow you to set the column to the "zero value" if desired (you would need to use a map).
typePersonstruct {
FirstNamestring`goqu:defaultifempty`LastNameNullString`goqu:defaultifempty`
}
p:=Person {
FirstName: "",
LastName: NullString {
String: "",
Valid: true
}
} //both would use database default when inserted/updated
2: Add a Default interface. This would require you to wrap things like NullString. I don't particularly like this idea. NullString is verbose/confusing as-is; adding another boolean for default makes it worse, but it would handle all use-cases.
typePersonstruct {
NameNullStringWithDefault
}
p:=Person {
Name: NullStringWithDefault("", false, true)
} //would insert as DEFAULTp2:=Person {
Name: NullStringWithDefault("", false, false)
} //would insert as NULLp3:=Person {
Name: NullStringWithDefault("", true, true)
} //would this insert as NULL, DEFAULT, or error?
If anything, I think I like _option 1_ since it is simple and it would work for most use-cases. For cases where you want the zero value, you can always use a map. Let me know what you think. Maybe there are better solutions I'm missing.
The text was updated successfully, but these errors were encountered:
I went with option 1 for now because it was fairly trivial to implement. If we end up needing the WithOverride type functionality later we can consider it.
When inserting/updating by struct, I couldn't find a way to force the column
DEFAULT
.Some ideas:
1: Add a tag like
defaultifempty
. This would work well for most use-cases, but wouldn't allow you to set the column to the "zero value" if desired (you would need to use a map).2: Add a
Default
interface. This would require you to wrap things likeNullString
. I don't particularly like this idea. NullString is verbose/confusing as-is; adding another boolean for default makes it worse, but it would handle all use-cases.If anything, I think I like _option 1_ since it is simple and it would work for most use-cases. For cases where you want the zero value, you can always use a map. Let me know what you think. Maybe there are better solutions I'm missing.
The text was updated successfully, but these errors were encountered: