diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2025-01-06 13:11:33 +0100 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2025-01-06 13:11:34 +0100 |
| commit | 49a7790edc4ec9526a7b846399339068990ce7de (patch) | |
| tree | 23e38b74d89469086b49d7780d2c2f1aabcbfc21 | |
| parent | b7a59fec37be7982f35ee8c431829709b3ba2563 (diff) | |
| download | go-gg-49a7790edc4ec9526a7b846399339068990ce7de.tar.gz | |
remove go:linkname usage
| -rw-r--r-- | internal/hack/convert_assign.go | 17 | ||||
| -rw-r--r-- | option/option.go | 23 |
2 files changed, 10 insertions, 30 deletions
diff --git a/internal/hack/convert_assign.go b/internal/hack/convert_assign.go deleted file mode 100644 index f1cb3d8..0000000 --- a/internal/hack/convert_assign.go +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* -* Copyright 2025 Stefan Majewsky <majewsky@gmx.net> -* SPDX-License-Identifier: Apache-2.0 -* Refer to the file "LICENSE" for details. -*******************************************************************************/ - -package hack - -import ( - _ "database/sql" - _ "unsafe" -) - -//go:linkname ConvertAssign database/sql.convertAssign -func ConvertAssign(dest, src any) error - -// ^ NOTE: This is needed because of <https://github.com/golang/go/issues/62146> diff --git a/option/option.go b/option/option.go index e8d7fb4..992c7b7 100644 --- a/option/option.go +++ b/option/option.go @@ -118,8 +118,6 @@ import ( "encoding/json" "fmt" "iter" - - "github.com/majewsky/gg/internal/hack" ) // Option is a type that contains either one or no instances of T. @@ -328,19 +326,18 @@ type yamlMarshaler interface { // Scan implements the database/sql.Scanner interface. func (o *Option[T]) Scan(src any) error { - switch src := src.(type) { - case nil: + var data sql.Null[T] + err := data.Scan(src) + if err != nil { + return err + } + + if data.Valid { + *o = Some(data.V) + } else { *o = None[T]() - return nil - default: - var data T - err := hack.ConvertAssign(&data, src) - if err != nil { - return err - } - *o = Some(data) - return nil } + return nil } // Value implements the database/sql/driver.Valuer interface. |
