File tree Expand file tree Collapse file tree 3 files changed +12
-19
lines changed
Expand file tree Collapse file tree 3 files changed +12
-19
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11module github.com/moznion/go-optional
22
3- go 1.21
3+ go 1.22
44
55require (
66 github.com/mattn/go-sqlite3 v1.14.22
Original file line number Diff line number Diff line change 11package optional
22
33import (
4+ "database/sql"
45 "database/sql/driver"
56)
67
78// Scan assigns a value from a database driver.
89// This method is required from database/sql.Scanner interface.
910func (o * Option [T ]) Scan (src any ) error {
10- if src == nil {
11- * o = None [T ]()
12- return nil
13- }
14-
15- var v T
16- err := sqlConvertAssign (& v , src )
11+ // The detour through sql.Null[T] allows us to access the standard rules for
12+ // assigning scanned values into builtin types and std types like *sql.Rows,
13+ // which are not exported from std directly.
14+ var v sql.Null [T ]
15+ err := v .Scan (src )
1716 if err != nil {
1817 return err
1918 }
20-
21- * o = Some [T ](v )
19+ if v .Valid {
20+ * o = Some [T ](v .V )
21+ } else {
22+ * o = None [T ]()
23+ }
2224 return nil
2325}
2426
You can’t perform that action at this time.
0 commit comments