Skip to content

Commit

Permalink
Add Json field support (#3)
Browse files Browse the repository at this point in the history
* use go modules

* do not use dep for travis

* Use github.com/putdotio/pas as module name

* run inside docker containers

* move go-mod files above to prevent download modules for each run

* Add Json field support
  • Loading branch information
muraty authored Oct 15, 2020
1 parent 49755a7 commit 8ad43fc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ email = "string"

[Events.page_viewed]
path = "string"

[Events.event_foo]
name = "string"
data = "json"
28 changes: 28 additions & 0 deletions internal/property/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package property

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

type Json struct{}

func newJson(args []string) (typeInterface, error) {
if len(args) > 0 {
return nil, fmt.Errorf("invalid arguments: %q", args)
}
return Json{}, nil
}

func (j Json) ColumnType() string {
return "json"
}

func (j Json) ConvertValue(v interface{}) (driver.Value, error) {
b, err := json.Marshal(v)
if err != nil {
return nil, fmt.Errorf("value is not json: %v", v)
}
return b, nil
}
1 change: 1 addition & 0 deletions internal/property/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var types = map[string]func([]string) (typeInterface, error){
"date": newDate,
"datetime": newDateTime,
"decimal": newDecimal,
"json": newJson,
}

func (t2 *Type) UnmarshalText(text []byte) error {
Expand Down

0 comments on commit 8ad43fc

Please sign in to comment.