goqu
goqu copied to clipboard
Provide DEFAULT on update capability
Is your feature request related to a problem? Please describe.
Ideally, timestamps are database-managed.
If you have a struct like this:
type User struct {
Name string `db:"name"`
CreatedAt time.Time `db:"created_at" goqu:"skipinsert,skipupdate"`
ModifiedAt time.Time `db:"modified_at" goqu:"skipinsert"`
}
created_at
is taken care of and is a write-once, update-never column, assuming the schema defaults it to now()
.
modified_at
works well on insert, but thereafter either must be set to a zero-value and used with goqu:"defaultifempty"
on update, or be set to time.Now()
which is sub-optimal.
Describe the solution you'd like
I'd like to implement goqu:"defaultonupdate"
in order to always set the column's value to DEFAULT on update - thoughts? I can't think of a circumstance where I'd want this aside from "last modified" timestamp values but that's something that most people care about, and which currently requires per-update boilerplate.
defaultonupdate
would be lower-precedence than skipupdate
, as well.
@doug-martin thoughts?