A json_object() function that returns a JSON-formatted object is scanned as a string instead of []byte or json.RawMessage. The return type for a :many query that does SELECT json_object() is []interface{}, while each item in the slice is of type string, therefore, when rendered as JSON, becomes an escaped JSON string. I've tried manually updating the generated code to cast strings to json.RawMessage and it worked as expected. Configuring an override of a json DB type to json.RawMessage results in "0" being returned. Configuring an override for jsonb instead results in some base64-encoded string.
I cannot find a workaround for this at the moment (apart from modifying the auto-generated code) but I think that json_object() and jsonb_object() (perhaps json_array() as well) expressions should be compiled as json.RawMessage.
Version
1.27.0
What happened?
A
json_object()
function that returns a JSON-formatted object is scanned as a string instead of[]byte
orjson.RawMessage
. The return type for a:many
query that doesSELECT json_object()
is[]interface{}
, while each item in the slice is of typestring
, therefore, when rendered as JSON, becomes an escaped JSON string. I've tried manually updating the generated code to cast strings tojson.RawMessage
and it worked as expected. Configuring an override of ajson
DB type tojson.RawMessage
results in"0"
being returned. Configuring an override forjsonb
instead results in some base64-encoded string.I cannot find a workaround for this at the moment (apart from modifying the auto-generated code) but I think that
json_object()
andjsonb_object()
(perhapsjson_array()
as well) expressions should be compiled asjson.RawMessage
.Relevant log output
Database schema
SQL queries
Configuration
Playground URL
No response
What operating system are you using?
macOS
What database engines are you using?
SQLite
What type of code are you generating?
Go