aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/uuidv7/uuidv7.go3
-rw-r--r--lib/uuidv7/uuidv7_test.go5
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