Reference
?

db.sql

Read-only raw SQL escape hatch for joins, subqueries, and window functions the typed API can’t express.
db.sql<T>(query, params?) → Query<T[]>

A read-only raw SQL escape hatch for the joins, subqueries, and window functions the typed API cannot express. Only SELECT and WITH run — writes throw — and values bind through positional ? parameters. Reach for it last: the typed queries and db.aggregate cover most needs and stay type-checked, and rows come back close to how SQLite stores them rather than in the SDK's parsed representations.

Parameters
query
string
RequiredA SELECT or WITH statement.
params
any[]
Positional bind params.
Raw SQL
const rows = await db.sql(
  'SELECT questionId, COUNT(*) AS n FROM answers GROUP BY questionId',
);