Drizzle TeamDT
Drizzle Team3y ago
5 replies
cody

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}'`)

and
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>)


Any idea? Thanks for your time in advance ❤️ !
GitHub
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...
[BUG]: Can't have a WHERE clause with JSON fields · Issue #463 · dr...
Was this page helpful?