KyselyK
Kysely2y ago
virk

Using raw SQL with `or` where

I have been using the raw SQL template tag to work with certain JSON columns and wanted to add a orWhere clause using it. Here is a simple example of what I am trying to achieve.

const result = await db
  .selectFrom('users')
  .where((eb) => {
    return eb.or([
      sql`address ->> 'street' = ${street}`,
      sql`address ->> 'street' = ${street1}`
    ])
  })
  .executeTakeFirst()


I can pass sql literal to the where clause directly, but in this case I want to write or where
Solution
And you're right, eb.or expects a list of Expression<SqlBool> where SqlBool is boolean | 0 | 1
Was this page helpful?