Source File
jsonb.go
Belonging Package
github.com/dariubs/gorm-jsonb
package gormjsonb
import (
)
// JSONB type
type JSONB map[string]interface{}
// Value for save jsonb in postgres
func ( JSONB) () (driver.Value, error) {
, := json.Marshal()
return string(),
}
// Scan unmarshal data in JSONB map
func ( *JSONB) ( interface{}) error {
var []byte
:= make(map[string]interface{})
switch .(type) {
case []uint8:
= []byte(.([]uint8))
case string:
= []byte(.(string))
case nil:
return nil
default:
return errors.New("incompatible type for StringInterfaceMap")
}
:= json.Unmarshal(, &)
if != nil {
return
}
* = JSONB()
return nil
}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |