Cleaning up null values in json
This commit is contained in:
parent
bc6e585b8d
commit
8dc07e3cc8
21 changed files with 222 additions and 92 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/lib/pq"
|
||||
"github.com/thermokarst/bactdb/models"
|
||||
)
|
||||
|
||||
func normalizeTime(t ...interface{}) {
|
||||
|
@ -15,9 +16,9 @@ func normalizeTime(t ...interface{}) {
|
|||
case *time.Time:
|
||||
x, _ := v.(*time.Time)
|
||||
*x = x.In(time.UTC)
|
||||
case *pq.NullTime:
|
||||
x, _ := v.(*pq.NullTime)
|
||||
*x = pq.NullTime{Time: x.Time.In(time.UTC), Valid: x.Valid}
|
||||
case *models.NullTime:
|
||||
x, _ := v.(*models.NullTime)
|
||||
*x = models.NullTime{pq.NullTime{Time: x.Time.In(time.UTC), Valid: x.Valid}}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ func newMeasurement(t *testing.T, tx *modl.Transaction) *models.Measurement {
|
|||
return &models.Measurement{
|
||||
StrainId: strain.Id,
|
||||
ObservationId: observation.Id,
|
||||
NumValue: sql.NullFloat64{Float64: 1.23, Valid: true},
|
||||
UnitTypeId: sql.NullInt64{Int64: unit_type.Id, Valid: true},
|
||||
NumValue: models.NullFloat64{sql.NullFloat64{Float64: 1.23, Valid: true}},
|
||||
UnitTypeId: models.NullInt64{sql.NullInt64{Int64: unit_type.Id, Valid: true}},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ func TestMeasurementsStore_Update_db(t *testing.T) {
|
|||
d := NewDatastore(tx)
|
||||
|
||||
// Tweak it
|
||||
measurement.NumValue = sql.NullFloat64{Float64: 4.56, Valid: true}
|
||||
measurement.NumValue = models.NullFloat64{sql.NullFloat64{Float64: 4.56, Valid: true}}
|
||||
updated, err := d.Measurements.Update(measurement.Id, measurement)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
Reference in a new issue