Exercise 1: Enabling the Relational Query API — Possible Solution
====================================================================
// db/client.ts
import { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';
import * as schema from './schema';
const connection = await mysql.createConnection(process.env.DATABASE_URL);
export const db = drizzle(connection, { schema });
WHY PASSING schema MATTERS
------------------------------
Per this chapter, drizzle() only exposes the db.query.
relational
API when it's given the full schema module, including the
pagesRelations definition from Chapter 2 - without that second
argument, only the plain db.select()/db.insert() query builder used
in earlier chapters is available, with no db.query object at all.
CONFIRMATION
------------------------------
After this change, db.query.pages exists and accepts a with option,
where previously it would have been undefined.
WHY THIS WORKS AS AN ANSWER
------------------------------
It correctly shows schema being passed as the second argument to
drizzle(), and correctly explains why that specific argument is what
unlocks the relational query API this chapter depends on.