Skip to content

Commit

Permalink
Merge pull request #447 from sgotti/testutil_db_export_col_type_bool
Browse files Browse the repository at this point in the history
testutils/db: handle col type bool on export
  • Loading branch information
sgotti authored Oct 11, 2023
2 parents 1326c5d + af30a55 commit fa56bad
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/testutil/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,24 @@ func (c *DBContext) Export(ctx context.Context, tables []string, w io.Writer) er
return errors.WithStack(err)
}
switch colType {
case ColTypeBool:
switch vt := v.(type) {
case bool:
data.Values[col] = vt
case int64:
if vt != 0 && vt != 1 {
return errors.Errorf("unknown type int64 value %d for bool column type", vt)
}
data.Values[col] = vt != 0
case []uint8:
bv, err := strconv.ParseBool(string(vt))
if err != nil {
return errors.WithStack(err)
}
data.Values[col] = bv
default:
return errors.Errorf("unknown type %T for bool column type", v)
}
case ColTypeJSON:
var vj any
if err := json.Unmarshal(v.([]byte), &vj); err != nil {
Expand Down

0 comments on commit fa56bad

Please sign in to comment.