postgresql/set.go

54 lines
728 B
Go
Raw Permalink Normal View History

2022-10-04 04:27:29 +00:00
package postgresql
2022-10-04 04:19:25 +00:00
import (
"time"
2022-11-03 03:55:31 +00:00
"github.com/shopspring/decimal"
"github.com/volatiletech/null/v8"
2022-10-04 04:19:25 +00:00
)
func SetString(val string) null.String {
return null.String{
String: val,
Valid: true,
}
}
func SetInt(val int) null.Int {
return null.Int{
Int: val,
Valid: true,
}
}
2022-10-04 08:56:34 +00:00
func SetBool(val bool) (res null.Bool) {
2022-10-04 04:19:25 +00:00
return null.Bool{
Bool: val,
Valid: true,
}
}
2022-10-04 08:56:34 +00:00
func SetTime(val time.Time) (res null.Time) {
if val.IsZero() {
return
}
2022-10-04 04:19:25 +00:00
return null.Time{
Time: val,
Valid: true,
}
}
2022-10-04 04:42:43 +00:00
2022-10-04 08:56:34 +00:00
func SetJSON(val []byte) (res null.JSON) {
if val == nil {
return
}
2022-10-04 04:42:43 +00:00
return null.JSON{
JSON: val,
Valid: true,
}
}
2022-11-03 03:55:31 +00:00
func SetFloat64(val float64) decimal.Decimal {
return decimal.NewFromFloat(val)
}