Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Issue #122 / Add database/sql null type support #200

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f0bb6b3
fix(constants): typo in annotationSeparator
quetzyg Mar 13, 2021
047fce9
refactor(response): split the visitModelNode() logic to make the code…
quetzyg Mar 14, 2021
4443a1f
feat(response): allow resolving a node ID from an sql.NullString, sql…
quetzyg Mar 14, 2021
2da336f
feat(response): add support for the sql.NullTime type
quetzyg Mar 14, 2021
7157d3f
feat(response): add attribute support for the remaining sql null types:
quetzyg Mar 14, 2021
dc43f12
fix(response): respect `omitempty` and ensure `null` gets returned if…
quetzyg Mar 14, 2021
f56f4a3
chore(request): use the annotation separator constant
quetzyg Apr 1, 2021
8018f1a
feat(request): return early and use switch/case in unmarshalNode()
quetzyg Apr 1, 2021
2ce5a7c
refactor(request): move ID and relation resolution logic into their o…
quetzyg Apr 1, 2021
3558086
chore(request): use the annotationJSONAPI constant
quetzyg Apr 1, 2021
c7d7a2f
refactor(request): simplify ISO8601 logic in handleTime()
quetzyg Apr 1, 2021
8f0d58a
refactor(request): simplify remaining logic in handleTime()
quetzyg Apr 1, 2021
aee8575
chore(request): rename unmarshallID() argument to structField
quetzyg Apr 2, 2021
cd458d5
feat(request): add support for sql.Null(Int32, Int64, Float64) in han…
quetzyg Apr 2, 2021
88da138
feat(request): add support for sql.NullTime in the handleTime() function
quetzyg Apr 2, 2021
44993c3
feat(request): handle sql.Null* type fields in the unmarshalAttribute…
quetzyg Apr 2, 2021
45b1839
feat(request): support sql.NullString ID field
quetzyg Apr 2, 2021
cc191bc
tests(request): add coverage for the new sql.Null* type support
quetzyg Apr 2, 2021
e7d4300
fix(response): sql.NullTime field omission logic
quetzyg Apr 2, 2021
e038f2b
chore(request): cleanup switch/cases
quetzyg Apr 2, 2021
2dccc85
feat(response): support sql.NullFloat64 ID field type
quetzyg Apr 2, 2021
300c9b8
chore(request): rename resolveNodeID() argument to structField
quetzyg Apr 2, 2021
f368930
refactor(response): simplify sql.Null* type handling logic in resolve…
quetzyg Apr 2, 2021
6e06742
fix(response): typo
quetzyg Apr 2, 2021
516918a
tests(response): add coverage for the new sql.Null* type support
quetzyg Apr 2, 2021
25eb602
tests(NullStringID): remove ComputedAtISO field
quetzyg Apr 2, 2021
963e8ff
fix(response): ensure sql.Null* type values are set to `nil` if they'…
quetzyg Apr 2, 2021
1e54991
tests(response): add coverage for invalid sql.Null* types when the om…
quetzyg Apr 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const (
annotationRelation = "relation"
annotationOmitEmpty = "omitempty"
annotationISO8601 = "iso8601"
annotationSeperator = ","
annotationSeparator = ","

iso8601TimeFormat = "2006-01-02T15:04:05Z"

Expand Down
40 changes: 37 additions & 3 deletions models_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jsonapi

import (
"database/sql"
"fmt"
"time"
)
Expand All @@ -26,9 +27,42 @@ type WithPointer struct {
}

type Timestamp struct {
ID int `jsonapi:"primary,timestamps"`
Time time.Time `jsonapi:"attr,timestamp,iso8601"`
Next *time.Time `jsonapi:"attr,next,iso8601"`
ID int `jsonapi:"primary,timestamps"`
Time time.Time `jsonapi:"attr,timestamp,iso8601"`
Next *time.Time `jsonapi:"attr,next,iso8601"`
Null sql.NullTime `jsonapi:"attr,null,iso8601"`
}

type NullStringID struct {
ID sql.NullString `jsonapi:"primary,null-string-id"`
Periodic sql.NullBool `jsonapi:"attr,periodic,omitempty"`
Name sql.NullString `jsonapi:"attr,name,omitempty"`
Value sql.NullFloat64 `jsonapi:"attr,value,omitempty"`
Decimal sql.NullInt32 `jsonapi:"attr,decimal,omitempty"`
Fractional sql.NullInt64 `jsonapi:"attr,fractional,omitempty"`
ComputedAt sql.NullTime `jsonapi:"attr,computed_at,omitempty,iso8601"`
}

type NullInt32ID struct {
ID sql.NullInt32 `jsonapi:"primary,null-int32-id"`
}

type NullInt64ID struct {
ID sql.NullInt64 `jsonapi:"primary,null-int64-id"`
}

type NullFloat64ID struct {
ID sql.NullFloat64 `jsonapi:"primary,null-float64-id"`
}

type Float struct {
ID sql.NullString `jsonapi:"primary,float"`
Periodic sql.NullBool `jsonapi:"attr,periodic"`
Name sql.NullString `jsonapi:"attr,name"`
Value sql.NullFloat64 `jsonapi:"attr,value"`
Decimal sql.NullInt32 `jsonapi:"attr,decimal"`
Fractional sql.NullInt64 `jsonapi:"attr,fractional"`
ComputedAt sql.NullTime `jsonapi:"attr,computed_at"`
}

type Car struct {
Expand Down
Loading