Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix json.RawMessage panic #658

Merged
merged 2 commits into from Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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