How to use JSON field in query

Ccody4/26/2023
I've already made an issue on GitHub kind of pertaining to this issue, but I don't know if its actually a bug or if I'm just not using it correctly. Reference: https://github.com/drizzle-team/drizzle-orm/issues/463 Basically, I have a JSON field and I'm trying to find a user with a field in that JSON object. I've tried
const userId = 'fake_id';
db.select().from(users).where(sql`discord->>'id' = '${userId}'`)
const userId = 'fake_id';
db.select().from(users).where(sql`discord->>'id' = '${userId}'`)
and
const userId = 'fake_id';
db.select().from(users).where(sql`${users.discord}->>'id' = '${userId}'`)
const userId = 'fake_id';
db.select().from(users).where(sql`${users.discord}->>'id' = '${userId}'`)
But always got this issue.
...\node_modules\pg\lib\utils.js:81
return JSON.stringify(val)
^


TypeError: Converting circular structure to JSON
--> starting at object with constructor 'PgTable'
| property 'id' -> object with constructor 'PgText'
--- property 'table' closes the circle
at JSON.stringify (<anonymous>)
...\node_modules\pg\lib\utils.js:81
return JSON.stringify(val)
^


TypeError: Converting circular structure to JSON
--> starting at object with constructor 'PgTable'
| property 'id' -> object with constructor 'PgText'
--- property 'table' closes the circle
at JSON.stringify (<anonymous>)
Any idea? Thanks for your time in advance ❤️ !
GitHub
[BUG]: Can't have a WHERE clause with JSON fields · Issue #463 · dr...
What version of drizzle-orm are you using? 0.23.13 What version of drizzle-kit are you using? No response Describe the Bug I can't seem to get a successful query going with trying to select thi...
Bbloberenober4/26/2023
sorry for the long reply - you probably have multiple instances of drizzle-orm installed in your project if you're using a monorepo, try installing drizzle-orm in the monorepo root using -w
Ccody4/26/2023
yep! that solved it, thank you so much for the quick response ❤️ I'll close the issue with a response
Eeatmoose11/22/2023
2023 bump installing in monorepo root doesn't help, and it shouldn't have to be

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
MySQL, PG proxy driver@Andrii Sherman Hi, Andrew! I noticed that the April milestone for drizzle-orm includes MySQL and PHow to create tables?So my understanding is that running a "migration" means creating the table with the schema in your donUpdateNow usageis onUpdateNow simlar to prisma's @updatedAt ? I.e., updated_at col is auto-updated. If so, is thereUPSERT many ?I have a table called `crmCompanies` containing companies from my client's CRMs. Each day, I recemissing type declarations in mysql-core imports (>v0.25.1)after upgrading drizzle-orm to v0.25.1 i get some errors in my schema telling me that `drizzle-orm/mdrizzle-orm@0.25.0 broke edge supportSeems like the ESM Support broke some stuff in the edge runtime land. This my vercel build output wiDoes Drizzle support type CUID?In Prisma i can use: id String @id @default(cuid()) Do we have similar solutions?Get column name in error messagesIs there a way to get column names exactly where the query is failing, for example when the FOREIGN Using Drizzle as a package in Turborepo doesn't work ?I have a monorepo (Turborepo) with a shared package called @mono/database in which I put my drizzle Argument of type 'Database' is not assignable to parameter of type 'D1Database'.I'm trying to use drizzle with cloudflare d1 but getting this error. Any help?drizzle-zod update schema?is there any plan for `createUpdateSchema` from `drizzle-zod`?How to reproduce a Prisma `include` statement for arrays of related entities without SQL?Hello, I'm trying to translate this SQL query to DrizzleORM; ``` SELECT channels.id, channelsmany-to-one selection as arrayHi, Let's say I have a user table, and the user can have multiple profiles. When I select using joiAlias in from() change? (SQLite)Did something change wrt using aliases in `from()`? Until recently I've been using aliases to affect