Files
PandaX/kit/model/jsonb.go
lixxxww c04f3a37d0 提交kit/model
Signed-off-by: lixxxww <941403820@qq.com>
2024-01-23 11:41:29 +00:00

37 lines
695 B
Go

package model
import (
"database/sql/driver"
"encoding/json"
"errors"
)
type JSONB map[string]interface{}
func (a JSONB) Value() (driver.Value, error) {
return json.Marshal(a)
}
func (a *JSONB) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &a)
}
// JSONBS Interface for JSONB Field of yourTableName Table
type JSONBS []interface{}
func (a JSONBS) Value() (driver.Value, error) {
return json.Marshal(a)
}
func (a *JSONBS) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &a)
}