1 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊
最佳答案我已經(jīng)遇到是使用bigint你的架構(gòu),并實(shí)現(xiàn)Value與Scan上一個(gè)包裝類型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
}
不幸的是,您將犧牲在查詢中進(jìn)行區(qū)間算術(shù)的能力 - 除非一些聰明的人想要發(fā)布bigint=>的類型轉(zhuǎn)換interval。
- 1 回答
- 0 關(guān)注
- 181 瀏覽
添加回答
舉報(bào)