1 回答

TA貢獻1856條經驗 獲得超17個贊
最佳答案我已經遇到是使用bigint你的架構,并實現Value與Scan上一個包裝類型time.Duration。
// Duration lets us convert between a bigint in Postgres and time.Duration
// in Go
type Duration time.Duration
// Value converts Duration to a primitive value ready to written to a database.
func (d Duration) Value() (driver.Value, error) {
return driver.Value(int64(d)), nil
}
// Scan reads a Duration value from database driver type.
func (d *Duration) Scan(raw interface{}) error {
switch v := raw.(type) {
case int64:
*d = Duration(v)
case nil:
*d = Duration(0)
default:
return fmt.Errorf("cannot sql.Scan() strfmt.Duration from: %#v", v)
}
return nil
}
不幸的是,您將犧牲在查詢中進行區間算術的能力 - 除非一些聰明的人想要發布bigint=>的類型轉換interval。
- 1 回答
- 0 關注
- 183 瀏覽
添加回答
舉報