diff --git a/string_array.go b/string_array.go index 1273ec1..3f81458 100644 --- a/string_array.go +++ b/string_array.go @@ -7,6 +7,7 @@ import ( pg "github.com/lib/pq" "gorm.io/gorm" "gorm.io/gorm/schema" + "reflect" ) type StringArray struct { @@ -100,6 +101,17 @@ func (StringArray) GormDBDataType(db *gorm.DB, field *schema.Field) string { return "" } +func (StringArray) FiberConverter(value string) reflect.Value { + var tmp pg.StringArray + s := StringArray{true, false, pg.StringArray{}} + + if err := json.Unmarshal([]byte(value), &tmp); err != nil { + s = NewStringArray(tmp, true, true) + } + + return reflect.ValueOf(s) +} + //func (d StringArray) GormValue(_ context.Context, db *gorm.DB) clause.Expr { // data, _ := d.MarshalJSON() // switch db.Dialector.Name() { diff --git a/type.go b/type.go index e828837..a74a0da 100644 --- a/type.go +++ b/type.go @@ -9,6 +9,7 @@ import ( "encoding/json" "errors" "fmt" + "reflect" "gorm.io/datatypes" "gorm.io/gorm" @@ -114,6 +115,17 @@ func (Type[D]) GormDBDataType(db *gorm.DB, field *schema.Field) string { return "" } +func (Type[D]) FiberConverter(value string) reflect.Value { + var tmp D + s := Type[D]{true, false, tmp} + + if err := json.Unmarshal([]byte(value), &tmp); err != nil { + s = NewType(tmp, true, true) + } + + return reflect.ValueOf(s) +} + //func (js Type[T]) GormValue(ctx context.Context, db *gorm.DB) clause.Expr { // if !js.Valid { // return clause.Expr{SQL: "?", Vars: []any{"NULL"}, WithoutParentheses: true}