提交kit/model

Signed-off-by: lixxxww <941403820@qq.com>
This commit is contained in:
lixxxww
2024-01-23 11:41:29 +00:00
committed by Gitee
parent b1cdfd62f6
commit c04f3a37d0
5 changed files with 345 additions and 0 deletions

36
kit/model/jsonb.go Normal file
View File

@@ -0,0 +1,36 @@
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)
}