Skip to content

Commit

Permalink
update: update the docs about JSONType (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
asjdf authored Apr 21, 2023
1 parent 88d502b commit 03668e8
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,12 @@ type UserWithJSON struct {

var user = UserWithJSON{
Name: "hello",
Attributes: datatypes.JSONType[Attribute]{
Data: Attribute{
Age: 18,
Sex: 1,
Orgs: map[string]string{"orga": "orga"},
Tags: []string{"tag1", "tag2", "tag3"},
},
},
Attributes: datatypes.NewJSONType(Attribute{
Age: 18,
Sex: 1,
Orgs: map[string]string{"orga": "orga"},
Tags: []string{"tag1", "tag2", "tag3"},
}),
}

// Create
Expand All @@ -199,14 +197,12 @@ DB.First(&result, user.ID)

// Update
jsonMap = UserWithJSON{
Attributes: datatypes.JSONType[Attribute]{
Data: Attribute{
Age: 18,
Sex: 1,
Orgs: map[string]string{"orga": "orga"},
Tags: []string{"tag1", "tag2", "tag3"},
},
},
Attributes: datatypes.NewJSONType(Attribute{
Age: 18,
Sex: 1,
Orgs: map[string]string{"orga": "orga"},
Tags: []string{"tag1", "tag2", "tag3"},
}),
}

DB.Model(&user).Updates(jsonMap)
Expand Down

0 comments on commit 03668e8

Please sign in to comment.