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

json.RawMessage behavior differs from byte slice #350

Open
3 tasks done
lefinal opened this issue Aug 30, 2022 · 0 comments · Fixed by XIELongDragon/goqu#12 · May be fixed by #351
Open
3 tasks done

json.RawMessage behavior differs from byte slice #350

lefinal opened this issue Aug 30, 2022 · 0 comments · Fixed by XIELongDragon/goqu#12 · May be fixed by #351

Comments

@lefinal
Copy link

lefinal commented Aug 30, 2022

Describe the bug

json.RawMessage currently gets encoded as byte list when using as value.
An example is provided below, where the content of a field with type json.RawMessage is used. The expected output would be correct JSON as with []byte.

To Reproduce

type MyType struct {
	ContentWithJSONRawMessage json.RawMessage
	ContentWithByteSlice      []byte
}

func main() {
	content := []byte(`{"hello":"world"}`)
	s := MyType{
		ContentWithJSONRawMessage: content,
		ContentWithByteSlice:      content,
	}
	q, _, err := goqu.Insert(goqu.T("my_table")).Rows(goqu.Record{
		"content_with_json_raw_message": s.ContentWithJSONRawMessage,
		"content_with_byte_slice":       s.ContentWithByteSlice,
	}).ToSQL()
	if err != nil {
		panic(err)
	}
	fmt.Println(q)
}

Output:

INSERT INTO "my_table" ("content_with_byte_slice", "content_with_json_raw_message") VALUES ('{"hello":"world"}', (123, 34, 104, 101, 108, 108, 111, 34, 58, 34, 119, 111, 114, 108, 100, 34, 125))

Expected behavior

Both values should be correct JSON as with []byte.

Dialect:

  • postgres
  • mysql
  • sqlite3
lefinal added a commit to lefinal/goqu that referenced this issue Aug 30, 2022
Fixes an issue where SQL for json.RawMessage-expressions is not generated correctly (as it is with byte slices).

Closes doug-martin#350
@lefinal lefinal linked a pull request Aug 30, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant