I want something like:
type User struct {
ID int `sql:"default:<myfunction>"`
}
Is this possible with GORM?
If no default value is declared explicitly, the default value is the null value. This usually makes sense because a null value can be considered to represent unknown data.
you can just type " \d table_name" command , then It will displays some information about the table, such as the default value of a column. \d will show the default values of a column .
Tags are optional to use when declaring models, GORM supports the following tags: Tags are case insensitive, however camelCase is preferred.
Have you tried it? You can do
time.Time `sql:"DEFAULT:current_timestamp"`
and it will use the "current_timestamp" function. If you want the default to be the string current_timestamp
, you would do
time.Time `sql:"DEFAULT:'current_timestamp'"`
So, in short, yes, it is possible. You would just do:
type User struct {
ID int `sql:"DEFAULT:myfunction"`
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With