SQLite json_each
Hi. I wandted to use the json_each function in sqlite, but I dont think the query is building correctly, could someone please guide me in the right direction?
My table:
My query:
The sql that ends up running is:
There doesnt seem to be any columns selected (I tried defining the cols manually as well but didnt work)
Any help would be much appricated!!
12 Replies
You can only use
.select()
if your from clause is a table, a subquery or a view. It's the only way drizzle can infer your selection
What was the problem when you selected the columns?if I select a col:
I get the error
Your "id" field references a column "channels"."id", but the table "channels" is not part of the query! Did you forget to join it
I don't think you'll be able to construct your query this way unfortunately.
The from method doesn't support more than one parameter
Oh wait, try this:
If i do this:
I get the following error:
but with
no error it goes thru, but no results either
Maybe like this?
I can't test this right now, so I'm just throwing out ideas
Ok I got it to work like this:
Still cannot use
id: channels.id
or id: sql<string>'${channels.id}'
wierdly. Only throwing ambiguous id error only for id field.
Thanks for all your help @Angelelz !
Hi Team, a new issue regarding this type of query. It seems the query params are not being passed in properly.
With the following query:
The sql generated is:
This query is returning an empty result []
But if I manually substitute the string in the query, it works:
Generated SQL
Result is:
Is this a bug or is there something I am doing wrong with respect to params?Your problem is that you need to pass the parameter with the % already in
oh interesting. let me try
Query: select distinct ch.value from "channels", json_each("channels"."participants") ch where ch.value like '?' -- params: ["%some-id%"]
Still giving me empty result
sorry missed out no single quotes
It works now. thanks!
Although isn't this approach a bit inorganic?There is no way for drizzle to detect that you have
%
around your parameters
I mean, there is, but it would add a lot of complexity
For now it has to be done in user land. Maybe later we could offer some nice helpersthanks @Angelelz