Skip to content

Instantly share code, notes, and snippets.

@samlof
Created March 21, 2023 06:40
Show Gist options
  • Save samlof/d5b2f31795746bd266d5f01fe62a9292 to your computer and use it in GitHub Desktop.
Save samlof/d5b2f31795746bd266d5f01fe62a9292 to your computer and use it in GitHub Desktop.
Ogen with sql scanner
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