fix: model gen issues
This commit is contained in:
32
templates/project/database/fields/common.go.tpl
Normal file
32
templates/project/database/fields/common.go.tpl
Normal file
@@ -0,0 +1,32 @@
|
||||
package fields
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
// implement sql.Scanner interface
|
||||
type field struct{}
|
||||
|
||||
func (x *field) Scan(value interface{}) (err error) {
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
return json.Unmarshal([]byte(v), &x)
|
||||
case []byte:
|
||||
return json.Unmarshal(v, &x)
|
||||
case *string:
|
||||
return json.Unmarshal([]byte(*v), &x)
|
||||
}
|
||||
return errors.New("Unknown type for ")
|
||||
}
|
||||
|
||||
func (x field) Value() (driver.Value, error) {
|
||||
return json.Marshal(x)
|
||||
}
|
||||
|
||||
func (x field) MustValue() driver.Value {
|
||||
return lo.Must(json.Marshal(x))
|
||||
}
|
||||
Reference in New Issue
Block a user