Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ulid.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ func (id ULID) Compare(other ULID) int {
func (id *ULID) Scan(src interface{}) error {
switch x := src.(type) {
case nil:
*id = Zero
return nil
case string:
return id.UnmarshalText([]byte(x))
Expand Down
10 changes: 10 additions & 0 deletions ulid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,16 @@ func TestOverflowHandling(t *testing.T) {
}
}

func TestScanNilClears(t *testing.T) {
id := ulid.MustParse("01ARYZ6S410000000000000000")
if err := id.Scan(nil); err != nil {
t.Fatal(err)
}
if !id.IsZero() {
t.Fatalf("got %s, want zero", id)
}
}

func TestScan(t *testing.T) {
id := ulid.MustNew(123, crand.Reader)

Expand Down