How to use JSON field in query

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...
3 Replies
bloberenober
bloberenober14mo ago
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
cody
cody14mo ago
yep! that solved it, thank you so much for the quick response ❤️ I'll close the issue with a response
eatmoose
eatmoose7mo ago
2023 bump installing in monorepo root doesn't help, and it shouldn't have to be