MySQL + GORM 如何设置创建时间和更新时间
目标
正确配置 MySQL 表中的 create_time 和 update_time,自动记录行的创建时间和更新时间,精度为微秒。
如何正确配置 create_time 和 update_time (How)
一、MySQL DDL
建表时将 create_time、update_time 设为微秒精度:
CREATE TABLE `item` (
`id` int NOT NULL …正确配置 MySQL 表中的 create_time 和 update_time,自动记录行的创建时间和更新时间,精度为微秒。
建表时将 create_time、update_time 设为微秒精度:
CREATE TABLE `item` (
`id` int NOT NULL …// PtrSize is the size of a pointer in bytes - unsafe.Sizeof(uintptr(0)) but as an ideal constant.
// It is also the size of the machine's native word size (that is, 4 on 32-bit …本文以 golang thrift binary 协议为例,讲述 thrift golang client 如何设置超时时间
golang thrift client 有两个超时时间
在创建 TSocket 的时候,我们可以传入 ConnectTimeout 和 SocketTimeout 两个配置。
ConnectTimeout 表示建 …// Cond
// 条件表达式的简单实现,支持任意类型
func Cond[T any](val bool, a, b T) T {
if val {
return a
}
return b
}
// Or
// 返回 vals 中第一个不是对应类型0值的参数,如果没有,则返回对应类型的0值
func Or[T comparable](vals ...T) T …