Created
March 21, 2023 06:40
-
-
Save samlof/d5b2f31795746bd266d5f01fe62a9292 to your computer and use it in GitHub Desktop.
Ogen with sql scanner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package oasapi | |
import ( | |
"database/sql" | |
"fmt" | |
"time" | |
"github.com/google/uuid" | |
) | |
func (s *OptString) Scan(src interface{}) error { | |
switch value := src.(type) { | |
case string: | |
s.Value = value | |
s.Set = true | |
case nil: | |
default: | |
return fmt.Errorf("incompatible type %T for OptString", src) | |
} | |
return nil | |
} | |
func (s *OptDateTime) Scan(src interface{}) error { | |
switch value := src.(type) { | |
case time.Time: | |
s.Value = value | |
s.Set = true | |
case nil: | |
default: | |
return fmt.Errorf("incompatible type %T for OptDateTime", src) | |
} | |
return nil | |
} | |
func (s *OptUUID) Scan(src interface{}) error { | |
switch value := src.(type) { | |
case uuid.UUID: | |
s.Value = value | |
s.Set = true | |
case nil: | |
default: | |
return fmt.Errorf("incompatible type %T for OptUUID", src) | |
} | |
return nil | |
} | |
func (s OptString) Sql() sql.NullString { | |
return sql.NullString{ | |
String: s.Value, | |
Valid: s.Set, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment