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!!
Angelelz•194d ago
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?VRN•193d ago
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
Angelelz•193d ago
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:
VRN•193d ago
If i do this:
I get the following error:
but with
no error it goes thru, but no results either
Angelelz•193d ago
Maybe like this?
I can't test this right now, so I'm just throwing out ideas
VRN•190d ago
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?Angelelz•190d ago
Your problem is that you need to pass the parameter with the % already in
VRN•190d ago
oh interesting. let me try
Angelelz•190d ago
VRN•190d ago
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?Angelelz•190d ago
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 helpersVRN•190d ago
thanks @Angelelz
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
7.4KMembers
View on DiscordWant results from more Discord servers?
More PostsForeign key truncated for being too long?Hi,
I have multiple warnings / notices:
`{
severity_local: 'NOTICE',
severity: 'NOTICE',
codedrizzle-zod with custom typesI have defined opaque types in my application and have implemented those in the drizzle schema (awesUsing transactions in automated testing like JestI have a testing set-up as follows:
1. Start postgres container
2. Apply migrations to db
3. Jest tTypeScript complaining about using a spread operator in partial select queryTypeScript complaining about me using a spread operator in partial select query.
I have the followiUnable to read error message when inserting withdb.insert().values()Hey there, i am using visual studio code and am developing with nuxt3. I am trying to insert an objehow to add new driver to drizzle?what is the procedure of adding a new driver to drizzle orm?`drizzle-kit --custom` is not giving me a blank migration fileI'm doing the following:
```sh
drizzle-kit generate:pg --custom
```
But it's not giving me a blankNo id returned (mysql2)```
async function create(data: NewBusiness) {
return client.insert(business).values(data)
}
```
Studio when using Turso `Error: Cannot find module 'better-sqlite3'`Error when trying to start Studio and push
`Error: Cannot find module 'better-sqlite3'`[BUG]: React Hook Form doesn't submit when using drizzle-zod to create schemes to use in zodResolverWhen using `drizzle-zod` to generate schemas from database schemas and using them in the `useForm` rAppending SQL chunks to a queryHey everyone, I'm trying to see if there is a way where I can build SQL queries conditionally (basedPostgresjs with Neon giving connnection refusal errorI am unable to connect to my neon database. I tried using `postgresjs` and the `neon serverless` drierror: column "id" cannot be cast automatically to type uuidim using drizzle, and this is my schema:
```typescript
export const tags = pgTable("tags", {
id: uinArray() using sql`` operator in JS and PostgresHey, how do I use sql operator with arrays in JS?
```javascript
const array = [1,2,3];
const sqlQuerUnable to infer relationI have the following tables and relations:
```javascript
export const platforms = pgTable('platformsmigrate with node-postgresI had migration working well with postgresjs but need to switch to node-postgres for other reasons. .all() API not availableI have two tables that I want to join, and I want to join them to get the following result:
```javasGet subquery columns in a way similar to `getTableColumns`Keeping track manually of all subquery fields can quickly become annoying, and I'm looking for a simSlow queries with relationshipsHi all, I recently moved from querying 4 tables concurrently, to using drizzle relations and using dCannot read properties of undefined (reading 'referencedTable')const result = await db.query.ads.findMany({
with: {
owner: true