Skip to content

Commit

Permalink
stellar#4909: convert byte[] values to string before sending to fast …
Browse files Browse the repository at this point in the history
…batch builder rows
  • Loading branch information
sreuland committed Nov 1, 2023
1 parent 2be340b commit 769a287
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (i *effectBatchInsertBuilder) Add(
"history_operation_id": operationID,
"order": order,
"type": effectType,
"details": details,
"details": string(details),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (i *operationBatchInsertBuilder) Add(
"transaction_id": transactionID,
"application_order": applicationOrder,
"type": operationType,
"details": details,
"details": string(details),
"source_account": sourceAccount,
"source_account_muxed": sourceAccountMuxed,
"is_payment": isPayment,
Expand Down
2 changes: 1 addition & 1 deletion support/db/batch_insert_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type hungerRow struct {
Name string `db:"name"`
HungerLevel string `db:"hunger_level"`
JsonValue []byte `db:"json_value"`
JsonValue string `db:"json_value"`
}

type invalidHungerRow struct {
Expand Down
10 changes: 1 addition & 9 deletions support/db/fast_batch_insert_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ func (b *FastBatchInsertBuilder) Row(row map[string]interface{}) error {
if !ok {
return errors.Errorf(`column "%s" does not exist`, column)
}

if b, ok := val.([]byte); ok {
val = string(b)
}
rowSlice = append(rowSlice, val)
}
b.rows = append(b.rows, rowSlice)
Expand Down Expand Up @@ -95,11 +91,7 @@ func (b *FastBatchInsertBuilder) RowStruct(row interface{}) error {
// convert fields values to interface{}
columnValues := make([]interface{}, len(b.columns))
for i, rval := range rvals {
if b, ok := rval.Interface().([]byte); ok {
columnValues[i] = string(b)
} else {
columnValues[i] = rval.Interface()
}
columnValues[i] = rval.Interface()
}

b.rows = append(b.rows, columnValues)
Expand Down
6 changes: 3 additions & 3 deletions support/db/fast_batch_insert_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestFastBatchInsertBuilder(t *testing.T) {
insertBuilder.Row(map[string]interface{}{
"name": "bubba",
"hunger_level": "1",
"json_value": []byte(`{"bump_to": "97"}`),
"json_value": `{"bump_to": "97"}`,
}),
)

Expand All @@ -37,7 +37,7 @@ func TestFastBatchInsertBuilder(t *testing.T) {
insertBuilder.Row(map[string]interface{}{
"name": "bubba",
"city": "London",
"json_value": []byte(`{"bump_to": "98"}`),
"json_value": `{"bump_to": "98"}`,
}),
"column \"hunger_level\" does not exist",
)
Expand All @@ -46,7 +46,7 @@ func TestFastBatchInsertBuilder(t *testing.T) {
insertBuilder.RowStruct(hungerRow{
Name: "bubba2",
HungerLevel: "9",
JsonValue: []byte(`{"bump_to": "98"}`),
JsonValue: `{"bump_to": "98"}`,
}),
)

Expand Down

0 comments on commit 769a287

Please sign in to comment.