According to the docs, Omitzero for NewUpdate is to update columns only when it does not contain an empty value. but it seems to work properly only when using a struct object (not working when using theSet method)
type User struct {
ID int64 `bun:",pk,autoincrement"`
Description string `bun:"type:text,nullzero,notnull"`
Count int64 `bun:"default:0,notnull,nullzero"`
}
Example of a struct object which contains an empty value: it works
As Golang uses zero value as nil for integer and float, the count field must not be included in the update query but it generates the query like: UPDATE "user" AS "user" SET count = 0 WHERE (id = 'id' ) RETURNING *
which seems OmitZero option is not properly applied for the empty integer value.
According to the docs,
Omitzero
forNewUpdate
is to update columns only when it does not contain an empty value. but it seems to work properly only when using a struct object (not working when using theSet
method)Example of a struct object which contains an empty value: it works
Example of using
Set
method in order to define fields to update:As
Golang
uses zero value as nil for integer and float, thecount
field must not be included in the update query but it generates the query like:UPDATE "user" AS "user" SET count = 0 WHERE (id = 'id' ) RETURNING *
which seemsOmitZero
option is not properly applied for the empty integer value.Is this by design or an issue?