intermediate

SQL-like query builder

Build typed SQL expressions while keeping joins, filters, selected columns, and generated SQL easy to inspect.

Drizzle keeps queries close to SQL with TypeScript inference for selected columns and joins. Dynamic filters stay composable while generated SQL remains inspectable.

					await db
  .select({ id: orders.id, total: orders.total })
  .from(orders)
  .innerJoin(customers, eq(customers.id, orders.customerId))
  .where(and(eq(orders.status, 'open'), gte(orders.total, minTotal)));
				

On interviews: selected columns, joins, dynamic `where` builders, prepared statements, SQL inspection, and underlying database knowledge.

Common pitfalls: SQL-like API still allowing inefficient plans; types protecting shape but not access-path design.

The trade-off is SQL transparency and type safety versus ORM convenience.

Checklist:

  • Keep SQL readable.
  • Inspect plans for important queries.
  • Use types to protect result shape.
  • Parameterize user input.