Skip to content

Commit

Permalink
Nil time (#82)
Browse files Browse the repository at this point in the history
* Handle nil *time.Time Literal (PR #52) + test

* Added sql to test
  • Loading branch information
doug-martin authored Jun 8, 2019
1 parent 3f720fc commit f388abd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v6.1.0

* Handle nil *time.Time Literal [#73](https://github.com/doug-martin/goqu/pull/73) and [#52](https://github.com/doug-martin/goqu/pull/52) - [@RoarkeRandall](https://github.com/RoarkeRandall) and [@quetz](https://github.com/quetz)

## v6.0.0

* Updated go support to `1.10`, `1.11` and `1.12`
Expand Down
3 changes: 3 additions & 0 deletions dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ func (me *Dataset) Literal(buf *SqlBuilder, val interface{}) error {
} else if v, ok := val.(time.Time); ok {
return me.adapter.LiteralTime(buf, v)
} else if v, ok := val.(*time.Time); ok {
if v == nil {
return me.adapter.LiteralNil(buf)
}
return me.adapter.LiteralTime(buf, *v)
} else if v, ok := val.(driver.Valuer); ok {
dVal, err := v.Value()
Expand Down
11 changes: 11 additions & 0 deletions dataset_insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import (
"time"
)

func (me *datasetTest) TestInsertNullTime() {
t := me.T()
ds1 := From("items")
type item struct {
CreatedAt *time.Time `db:"created_at"`
}
sql, _, err := ds1.ToInsertSql(item{CreatedAt: nil})
assert.NoError(t, err)
assert.Equal(t, sql, `INSERT INTO "items" ("created_at") VALUES (NULL)`)
}

func (me *datasetTest) TestInsertSqlNoReturning() {
t := me.T()
mDb, _, _ := sqlmock.New()
Expand Down

0 comments on commit f388abd

Please sign in to comment.