You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to use the combination of sqlc + SQLite. I've run into a number of smaller issues so far, but have managed to work through most of them via various workarounds. One that I've not been able to find a workaround for (despite trying everything I could think of), is the use of jsonb, and I'm wondering whether I'm missing something or if it's fairly broken right now (I suspect the latter, but wanted to gut check it).
I have a table with a jsonb field like (see metadata):
The problem is that the data is actually coming back as SQLite's jsonb binary format rather than usable JSON.
According to SQLite's docs on jsonb, the format is meant to be internal only, so even if we could deserialize it in our Go code, we should make no attempt to do that:
JSONB is not intended as an external format to be used by applications. JSONB is designed for internal use by SQLite only. Programmers do not need to understand the JSONB format in order to use it effectively. Applications should access JSONB only through the JSON SQL functions, not by looking at individual bytes of the BLOB.
So what should ideally be happening here is that jsonb is run through json(...) before being sent back through sqlc, but I don't know how to pull this off.
I thought about replacing RETURNING * with RETURNING sqlc.embed(river_job), json(metadata) AS metadata, but this isn't great (it breaks all our normal sqlc conventions), and leads to even more problems: (1) sqlc + SQLite doesn't support sqlc.embed here, and (2) sqlc + SQLite doesn't support renaming columns here with AS so you end up with a bunch of position results.
I'm not sure what the best approach here would be, but possibly something like sqlc recognizing a jsonb "sentinel" type in a table definition (there is no jsonb type; these are all stored as blob), and knows to json(...) it before returning.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey all,
I've been trying to use the combination of sqlc + SQLite. I've run into a number of smaller issues so far, but have managed to work through most of them via various workarounds. One that I've not been able to find a workaround for (despite trying everything I could think of), is the use of jsonb, and I'm wondering whether I'm missing something or if it's fairly broken right now (I suspect the latter, but wanted to gut check it).
I have a table with a jsonb field like (see
metadata
):I've inserting to it using this query (this is an
INSERT
, but the same applies for aSELECT *
and every other type of query):I'm running a test where I insert a row and then assert on the result:
It fails with an error like this:
The problem is that the data is actually coming back as SQLite's jsonb binary format rather than usable JSON.
According to SQLite's docs on jsonb, the format is meant to be internal only, so even if we could deserialize it in our Go code, we should make no attempt to do that:
So what should ideally be happening here is that jsonb is run through
json(...)
before being sent back through sqlc, but I don't know how to pull this off.I thought about replacing
RETURNING *
withRETURNING sqlc.embed(river_job), json(metadata) AS metadata
, but this isn't great (it breaks all our normal sqlc conventions), and leads to even more problems: (1) sqlc + SQLite doesn't supportsqlc.embed
here, and (2) sqlc + SQLite doesn't support renaming columns here withAS
so you end up with a bunch of position results.I'm not sure what the best approach here would be, but possibly something like sqlc recognizing a
jsonb
"sentinel" type in a table definition (there is nojsonb
type; these are all stored asblob
), and knows tojson(...)
it before returning.Any thoughts/ideas?
Beta Was this translation helpful? Give feedback.
All reactions