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

encode: use sql.NullTime instead of custom type #903

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: go

go:
- 1.11.x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we support the last two versions of Go. You'll need to make some version-tagged files for this PR.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the last two versions of Go is now 1.14.x and 1.13.x as of 23 Nov 2020. Should we go with this update now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Open up a new PR that is mergeable and I'll merge it. Be sure to @ me or I won't see it.

- 1.12.x
- 1.13.x
- master

sudo: true
Expand Down
23 changes: 0 additions & 23 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pq

import (
"bytes"
"database/sql/driver"
"encoding/binary"
"encoding/hex"
"errors"
Expand Down Expand Up @@ -578,25 +577,3 @@ func encodeBytea(serverVersion int, v []byte) (result []byte) {

return result
}

// NullTime represents a time.Time that may be null. NullTime implements the
// sql.Scanner interface so it can be used as a scan destination, similar to
// sql.NullString.
type NullTime struct {
Time time.Time
Valid bool // Valid is true if Time is not NULL
}

// Scan implements the Scanner interface.
func (nt *NullTime) Scan(value interface{}) error {
nt.Time, nt.Valid = value.(time.Time)
return nil
}

// Value implements the driver Valuer interface.
func (nt NullTime) Value() (driver.Value, error) {
if !nt.Valid {
return nil, nil
}
return nt.Time, nil
}
4 changes: 2 additions & 2 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestScanTimestamp(t *testing.T) {
var nt NullTime
var nt sql.NullTime
tn := time.Now()
nt.Scan(tn)
if !nt.Valid {
Expand All @@ -24,7 +24,7 @@ func TestScanTimestamp(t *testing.T) {
}

func TestScanNilTimestamp(t *testing.T) {
var nt NullTime
var nt sql.NullTime
nt.Scan(nil)
if nt.Valid {
t.Errorf("Expected Valid=false")
Expand Down