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
Here I would like the value for inc_id to be ignored during INSERT statements as I would like to use the column default (i.e: the next value of the serial's sequence). Unfortunately when using the Go zero value reform does the insert with the actual value 0. The result in a row with the column set to 0 instead of the result of Postgres' nextval().
Describe the solution you'd like
I would like to be able to mark a field as reform:"inc_id,omitempty", similar to what the official json package does. When the tag "omitempty" is present, reform will not pass the field during calls to Insertor Update.
Given this reform type:
//reform:filestypeFilestruct {
IDstring`reform:"id,pk"`IncIDint64`reform:"inc_id,omitempty"`// <== column of type 'serial'
}
Something equivalent to the following SQL code should be generated:
INSERT INTO (id) values (123) RETURNING id, inc_id
Describe alternatives you've considered
Other options:
We could use a tag readonly instead, that would specify that the column is never passed during UPDATE or INSERT, but is used for SELECT, without a need for logic based on zero values.
So an alternative that doesn't require to add new tags would be to add a method InsertWithout(&record, "inc_id") that would do the opposite of InsertColumns (insert everything but the specified columns).
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I have a postgres table with a column of type
serial
(which is not the primary key, if that matters).Suppose I have a reform type:
I then insert it using this way:
Here I would like the value for
inc_id
to be ignored duringINSERT
statements as I would like to use the column default (i.e: the next value of the serial's sequence). Unfortunately when using the Go zero value reform does the insert with the actual value0
. The result in a row with the column set to0
instead of the result of Postgres'nextval()
.Describe the solution you'd like
I would like to be able to mark a field as
reform:"inc_id,omitempty"
, similar to what the officialjson
package does. When the tag "omitempty" is present, reform will not pass the field during calls toInsert
orUpdate
.Given this reform type:
And this insert:
Something equivalent to the following SQL code should be generated:
Describe alternatives you've considered
Other options:
We could use a tag
readonly
instead, that would specify that the column is never passed duringUPDATE
orINSERT
, but is used forSELECT
, without a need for logic based on zero values.What I would like is currently possible this way:
So an alternative that doesn't require to add new tags would be to add a method
InsertWithout(&record, "inc_id")
that would do the opposite ofInsertColumns
(insert everything but the specified columns).The text was updated successfully, but these errors were encountered: