Replies: 1 comment 2 replies
-
This is the first time we've run into an issue where the value returned from selecting the column isn't correct. First, I'll say it's a pretty strange decision by SQLite to even return this internal-only bytes representation, but it is what is. Second, a solution to this could be generalized to allow for a whole host of features. I think it's a mistake to try and design that now. Instead, the only decent solution I see is to recognize when a SQLite blob columns is stored as jsonb and always generate |
Beta Was this translation helpful? Give feedback.
-
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