From f5c11dbe2298fd69e95ce9167ba8fcd37d326830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Tue, 6 Jun 2023 13:40:10 +0200 Subject: [PATCH] Properly cast temporal types so DB drivers can be more flexible --- server/store/adapters/rdbms/drivers/types.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/server/store/adapters/rdbms/drivers/types.go b/server/store/adapters/rdbms/drivers/types.go index 3159f43e9..19bb74b4e 100644 --- a/server/store/adapters/rdbms/drivers/types.go +++ b/server/store/adapters/rdbms/drivers/types.go @@ -10,6 +10,7 @@ import ( "github.com/cortezaproject/corteza/server/pkg/dal" "github.com/google/uuid" + "github.com/modern-go/reflect2" "github.com/spf13/cast" ) @@ -132,7 +133,11 @@ func (t *TypeTimestamp) Decode(raw any) (any, bool, error) { } func (t *TypeTimestamp) Encode(val any) (driver.Value, error) { - return val, nil + if reflect2.IsNil(val) { + return nil, nil + } + + return cast.ToTimeE(val) } func (t *TypeTime) Decode(raw any) (any, bool, error) { @@ -157,7 +162,11 @@ func (t *TypeTime) Decode(raw any) (any, bool, error) { } func (t *TypeTime) Encode(val any) (driver.Value, error) { - return val, nil + if reflect2.IsNil(val) { + return nil, nil + } + + return cast.ToTimeE(val) } func (t *TypeDate) Decode(raw any) (any, bool, error) { @@ -170,7 +179,11 @@ func (t *TypeDate) Decode(raw any) (any, bool, error) { } func (t *TypeDate) Encode(val any) (driver.Value, error) { - return val, nil + if reflect2.IsNil(val) { + return nil, nil + } + + return cast.ToTimeE(val) } func (t *TypeNumber) Decode(raw any) (any, bool, error) {