mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-29 14:31:26 +08:00
37 lines
695 B
Go
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)
|
|
}
|