From e6cc7251af76f15521fcf0d69107fc4dbb4fa731 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Tue, 4 Mar 2025 07:28:58 -0600 Subject: [PATCH] Adding sql integration for Map type --- gobwebs.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gobwebs.go b/gobwebs.go index 6c595a5..aedb437 100644 --- a/gobwebs.go +++ b/gobwebs.go @@ -1,5 +1,11 @@ package gobwebs +import ( + "database/sql/driver" + "encoding/json" + "errors" +) + const ( // LoginTypeAuth use normal email/password auth LoginTypeAuth int = iota @@ -9,3 +15,17 @@ const ( // Map is a global mapping type type Map map[string]any + +// Value for sql integration +func (m Map) Value() (driver.Value, error) { + return json.Marshal(m) +} + +// Scan for sql integration +func (m *Map) Scan(value interface{}) error { + b, ok := value.([]byte) + if !ok { + return errors.New("type assertion to []byte failed") + } + return json.Unmarshal(b, &m) +} -- 2.45.3