Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想要类似的东西:
type User struct { ID int `sql:"default:<myfunction>"` }
GORM可以做到这一点吗?
你试过了吗?你可以做
time.Time `sql:"DEFAULT:current_timestamp"`
它将使用“current_timestamp”函数。如果您希望默认值是字符串current_timestamp,您会这样做
current_timestamp
time.Time `sql:"DEFAULT:'current_timestamp'"`
所以,简而言之,是的,这是可能的。你会这样做:
type User struct { ID int `sql:"DEFAULT:myfunction"` }