Skip to content

Commit

Permalink
Merge pull request #658 from upper/issue-655_json-rawmessage-panic
Browse files Browse the repository at this point in the history
fix json.RawMessage panic
  • Loading branch information
xiam committed Jul 4, 2022
2 parents 2147806 + a54cb1e commit 889ce39
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions adapter/postgresql/helper_test.go
Expand Up @@ -194,6 +194,7 @@ func (h *Helper) TearUp() error {
, integer_array integer[]
, string_array text[]
, jsonb_map jsonb
, raw_jsonb_map jsonb
, integer_array_ptr integer[]
, string_array_ptr text[]
Expand Down
7 changes: 7 additions & 0 deletions adapter/postgresql/postgresql_test.go
Expand Up @@ -25,6 +25,7 @@ import (
"context"
"database/sql"
"database/sql/driver"
"encoding/json"
"fmt"
"math/rand"
"strings"
Expand Down Expand Up @@ -229,6 +230,8 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) {
StringArray StringArray `db:"string_array,stringarray"`
JSONBMap JSONBMap `db:"jsonb_map"`

RawJSONBMap *json.RawMessage `db:"raw_jsonb_map,omitempty"`

PGTypeInline `db:",inline"`

PGTypeAutoInline `db:",inline"`
Expand Down Expand Up @@ -275,6 +278,7 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) {
integerArrayValue := Int64Array{1, 2, 3, 4}
stringArrayValue := StringArray{"a", "b", "c"}
jsonbMapValue := JSONBMap{"Hello": "World"}
rawJSONBMap := json.RawMessage(`{"foo": "bar"}`)

testValue := "Hello world!"

Expand Down Expand Up @@ -329,6 +333,9 @@ func testPostgreSQLTypes(t *testing.T, sess db.Session) {
AutoJSONBMapInteger: map[string]interface{}{"a": 12.0, "b": 13.0},
},
},
PGType{
RawJSONBMap: &rawJSONBMap,
},
PGType{
IntegerValue: integerValue,
StringValue: stringValue,
Expand Down
2 changes: 1 addition & 1 deletion internal/sqlbuilder/convert.go
Expand Up @@ -57,7 +57,7 @@ func toInterfaceArguments(value interface{}) (args []interface{}, isSlice bool)

// Byte slice gets transformed into a string.
if v.Type().Elem().Kind() == reflect.Uint8 {
return []interface{}{string(value.([]byte))}, false
return []interface{}{string(v.Bytes())}, false
}

total = v.Len()
Expand Down

0 comments on commit 889ce39

Please sign in to comment.