File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // This is not autogenerated.
2+ package core
3+
4+ import (
5+ "database/sql/driver"
6+ "encoding/json"
7+ "fmt"
8+ )
9+
10+ // GormDataType returns the data type for GORM to use when creating the database column.
11+ func (m MapObject ) GormDataType () string {
12+ return "text"
13+ }
14+
15+ // Value implements the driver.Valuer interface, serializing MapObject as a JSON string.
16+ func (m MapObject ) Value () (driver.Value , error ) {
17+ if m == nil {
18+ return nil , nil
19+ }
20+ b , err := json .Marshal (m )
21+ if err != nil {
22+ return nil , err
23+ }
24+ return string (b ), nil
25+ }
26+
27+ // Scan implements the sql.Scanner interface, deserializing a JSON string into MapObject.
28+ func (m * MapObject ) Scan (value interface {}) error {
29+ if value == nil {
30+ * m = nil
31+ return nil
32+ }
33+ var bytes []byte
34+ switch v := value .(type ) {
35+ case []byte :
36+ bytes = v
37+ case string :
38+ bytes = []byte (v )
39+ default :
40+ return fmt .Errorf ("cannot scan type %T into MapObject" , value )
41+ }
42+ result := make (MapObject )
43+ if err := json .Unmarshal (bytes , & result ); err != nil {
44+ return err
45+ }
46+ * m = result
47+ return nil
48+ }
You can’t perform that action at this time.
0 commit comments