Skip to content

Commit

Permalink
schema fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rucsi committed Feb 7, 2024
1 parent 34f2e72 commit adc002e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pkg/content/schema.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package content

import (
"database/sql/driver"
"encoding/json"
"fmt"
"time"
)

Expand Down Expand Up @@ -41,12 +44,31 @@ type Field struct {
Schema *Schema `json:"schema,omitempty"`
}

type Fields []*Field

func (f *Fields) Scan(val interface{}) error {
switch v := val.(type) {
case []byte:
json.Unmarshal(v, f)
return nil
case string:
json.Unmarshal([]byte(v), f)
return nil
default:
return fmt.Errorf("unsupported type: %T", v)
}
}
func (f Fields) Value() (driver.Value, error) {
b, err := json.Marshal(f)
return string(b), err
}

type Schema struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
DisplayField string `json:"displayField,omitempty"`
Description string `json:"description,omitempty"`
Fields []*Field `json:"fields,omitempty"`
Fields Fields `json:"fields,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
Expand Down

0 comments on commit adc002e

Please sign in to comment.