-
🎉 Introduced a standalone query builder that can be used without a DB connection:
import { queryBuilder as qb } from 'drizzle-orm/pg-core'; const query = qb.select().from(users).where(eq(users.name, 'Dan')); const { sql, params } = query.toSQL();
-
🎉 Improved
WITH ... SELECT
subquery creation syntax to more resemble SQL:Before:
const regionalSales = db .select({ region: orders.region, totalSales: sql`sum(${orders.amount})`.as<number>('total_sales'), }) .from(orders) .groupBy(orders.region) .prepareWithSubquery('regional_sales'); await db.with(regionalSales).select(...).from(...);
After:
const regionalSales = db .$with('regional_sales') .as( db .select({ region: orders.region, totalSales: sql<number>`sum(${orders.amount})`.as('total_sales'), }) .from(orders) .groupBy(orders.region), ); await db.with(regionalSales).select(...).from(...);