Skip to content

Commit

Permalink
need to handle []any
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Dec 6, 2024
1 parent 3fa8eed commit da9c368
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions flow/connectors/postgres/qvalue_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,16 @@ func parseJSON(value interface{}, isArray bool) (qvalue.QValue, error) {
return qvalue.QValueJSON{Val: string(jsonVal), IsArray: isArray}, nil
}

func parseUUID(value interface{}) (qvalue.QValue, error) {
func parseUUID(value interface{}) (uuid.UUID, error) {
switch v := value.(type) {
case string:
id, err := uuid.Parse(v)
if err != nil {
return nil, fmt.Errorf("invalid UUID string: %w", err)
}
return qvalue.QValueUUID{Val: id}, nil
return uuid.Parse(v)
case [16]byte:
return qvalue.QValueUUID{Val: uuid.UUID(v)}, nil
return uuid.UUID(v), nil
case uuid.UUID:
return qvalue.QValueUUID{Val: v}, nil
return v, nil
default:
return nil, fmt.Errorf("unsupported type for UUID: %T", value)
return uuid.UUID{}, fmt.Errorf("unsupported type for UUID: %T", value)
}
}

Expand All @@ -277,6 +273,16 @@ func parseUUIDArray(value interface{}) (qvalue.QValue, error) {
return qvalue.QValueArrayUUID{Val: uuids}, nil
case []uuid.UUID:
return qvalue.QValueArrayUUID{Val: v}, nil
case []interface{}:
uuids := make([]uuid.UUID, 0, len(v))
for _, v := range v {
id, err := parseUUID(v)
if err != nil {
return nil, fmt.Errorf("invalid UUID interface{} value in array: %w", err)
}
uuids = append(uuids, id)
}
return qvalue.QValueArrayUUID{Val: uuids}, nil
default:
return nil, fmt.Errorf("unsupported type for UUID array: %T", value)
}
Expand Down Expand Up @@ -428,7 +434,7 @@ func parseFieldFromQValueKind(qvalueKind qvalue.QValueKind, value interface{}) (
if err != nil {
return nil, fmt.Errorf("failed to parse UUID: %w", err)
}
return tmp, nil
return qvalue.QValueUUID{Val: tmp}, nil
case qvalue.QValueKindArrayUUID:
tmp, err := parseUUIDArray(value)
if err != nil {
Expand Down

0 comments on commit da9c368

Please sign in to comment.