diff options
| author | Shulhan <ms@kilabit.info> | 2026-04-04 02:30:09 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-04-04 02:32:01 +0700 |
| commit | fd54f7be5969204b6845c4aa7dd332d31c96c59f (patch) | |
| tree | f24e06c0aa98ebe6d1c61e152b0f4d8cf8c79ec3 /lib | |
| parent | f18f08e554ed9f93f31641d974448923099ac892 (diff) | |
| download | pakakeh.go-fd54f7be5969204b6845c4aa7dd332d31c96c59f.tar.xz | |
lib/uuidv7: detect nil value on Scan
Column with NULL value will returns no error but zero UUID.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/uuidv7/uuidv7.go | 3 | ||||
| -rw-r--r-- | lib/uuidv7/uuidv7_test.go | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/uuidv7/uuidv7.go b/lib/uuidv7/uuidv7.go index e35e684b..21277e55 100644 --- a/lib/uuidv7/uuidv7.go +++ b/lib/uuidv7/uuidv7.go @@ -165,6 +165,7 @@ func (id *UUIDv7) UnmarshalText(data []byte) (err error) { // Scan scans the raw database value into id. // This method implement [database/sql.Scanner] interface. +// Column with NULL value will returns no error but zero UUID. func (id *UUIDv7) Scan(src any) (err error) { switch v := src.(type) { case []byte: @@ -172,6 +173,8 @@ func (id *UUIDv7) Scan(src any) (err error) { if err != nil { return err } + case nil: + return nil default: return fmt.Errorf(`uuidv7: Scan: invalid type %T`, src) } diff --git a/lib/uuidv7/uuidv7_test.go b/lib/uuidv7/uuidv7_test.go index 70ca315c..f9d90226 100644 --- a/lib/uuidv7/uuidv7_test.go +++ b/lib/uuidv7/uuidv7_test.go @@ -14,6 +14,7 @@ func TestUUIDv7_Scan(t *testing.T) { desc string data any expError string + exp UUIDv7 }{{ desc: `With empty data`, data: `017F22E2-79B0-7CC3-98C4-DC0C0C07398F`, @@ -22,6 +23,10 @@ func TestUUIDv7_Scan(t *testing.T) { desc: `With invalid version`, data: []byte(`5c146b14-3c52-4afd-938a-375d0df1fbf6`), expError: `uuidv7: invalid version 2`, + }, { + desc: `With nil`, + data: nil, + expError: ``, }} for _, tc := range listCase { var id UUIDv7 |
