-
Notifications
You must be signed in to change notification settings - Fork 335
/
types.go
42 lines (32 loc) · 968 Bytes
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package postgres
import (
"database/sql"
"database/sql/driver"
"fmt"
"time"
"github.com/cortezaproject/corteza/server/pkg/dal"
"github.com/cortezaproject/corteza/server/store/adapters/rdbms/drivers"
)
type (
TypeTime struct{ *dal.TypeTime }
)
func (*TypeTime) MakeScanBuffer() any { return new(sql.NullTime) }
func (t *TypeTime) Decode(raw any) (any, bool, error) {
dec, is := raw.(*sql.NullTime)
if !is {
return nil, false, fmt.Errorf("unexpected raw type %T for Time", raw)
}
if !dec.Valid {
return time.Time{}, false, nil
}
//parsed, err := time.Parse(drivers.TimeLayout(t.Timezone, t.Precision), dec.String)
//if err != nil {
// return time.Time{}, false, err
//}
// @todo should we gracefully handle other combinations of time&precision?
// maybe with Strict flag?
return dec.Time.Format(drivers.TimeLayout(t.Timezone, t.Precision)), true, nil
}
func (t *TypeTime) Encode(val any) (driver.Value, error) {
return val, nil
}