Drizzle foundations
Run and inspect the first query
Execute a small SQL expression through Drizzle and inspect generated queries instead of treating the ORM as an invisible layer.
8 minute lesson
Before creating tables, let’s prove the complete path works. Drizzle can run a typed SQL template when the query builder is not the right tool.
Use the sql template to keep values separate from SQL text. It is not the same as string concatenation: interpolated values become bound parameters. Drizzle query builders also expose their generated SQL, which is useful when debugging a filter or reviewing a surprising query.
import { sql } from 'drizzle-orm'
import { db } from './db'
const result = await db.execute(sql`select sqlite_version() as version`)
console.log(result)
A successful result proves the TypeScript entry point, Drizzle driver, SQLite library, environment, and database file can work together. When this fails, inspect those layers in that order instead of rewriting schema code that has not run yet.
Raw SQL is useful for database-specific features and diagnostics. Keep it narrow, bind every value, and return to the query builder when its types make the application clearer.
Print the SQLite version and one bound value containing a quote. Save the output and the generated SQL representation, then prove the quoted value remains data rather than changing the statement.
Lesson completed