Run Raw SQL with sql``

Hi all, is it possible to run unsafe SQL from an API. We have a use-case on some devices that we manage. const res = db.run(sql(${statement})); Thanks!
1 Reply
Anton Sidelnikov
@LUCKY That's await db.execute(".....") - you can run arbitrary queries with that. If you want to do some parameter embeddings, it's best to use it with sql operator you've mentioned like this:
import { sql } from 'drizzle-orm'
const id = 22
await db.execute(sql`select * from users where id = ${id}`) - that will handle safe escaping
import { sql } from 'drizzle-orm'
const id = 22
await db.execute(sql`select * from users where id = ${id}`) - that will handle safe escaping
Want results from more Discord servers?
Add your server