Skip to content

Commit

Permalink
fix: support scanning string into uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Dec 27, 2021
1 parent dbb7d90 commit 73cc117
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion query_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func (q *baseQuery) GetTableName() string {
return string(b)
}
if len(q.tables) > 0 {
return q.tables[0].Query
b, _ := q.tables[0].AppendQuery(q.db.fmter, nil)
return string(b)
}
return ""
}
Expand Down
29 changes: 26 additions & 3 deletions schema/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,19 @@ func scanBool(dest reflect.Value, src interface{}) error {
dest.SetBool(src != 0)
return nil
case []byte:
if len(src) == 1 {
dest.SetBool(src[0] != '0')
return nil
f, err := strconv.ParseBool(internal.String(src))
if err != nil {
return err
}
dest.SetBool(f)
return nil
case string:
f, err := strconv.ParseBool(src)
if err != nil {
return err
}
dest.SetBool(f)
return nil
}
return fmt.Errorf("bun: can't scan %#v into %s", src, dest.Type())
}
Expand Down Expand Up @@ -189,6 +198,13 @@ func scanUint64(dest reflect.Value, src interface{}) error {
}
dest.SetUint(n)
return nil
case string:
n, err := strconv.ParseUint(src, 10, 64)
if err != nil {
return err
}
dest.SetUint(n)
return nil
}
return fmt.Errorf("bun: can't scan %#v into %s", src, dest.Type())
}
Expand All @@ -208,6 +224,13 @@ func scanFloat64(dest reflect.Value, src interface{}) error {
}
dest.SetFloat(f)
return nil
case string:
f, err := strconv.ParseFloat(src, 64)
if err != nil {
return err
}
dest.SetFloat(f)
return nil
}
return fmt.Errorf("bun: can't scan %#v into %s", src, dest.Type())
}
Expand Down

0 comments on commit 73cc117

Please # to comment.