Skip to content

Drizzle ORM

Flareforge uses Drizzle ORM as the default toolkit for interacting with your Cloudflare D1 database. It provides a type-safe query builder that makes database access simple and secure.

A core principle of Flareforge is that your database schema is not written manually. Instead, it is automatically generated from the taskDefinition object within your flareforge.jsonc configuration file.

When you run flareforge codegen, the framework reads your task groups and fields and generates the corresponding Drizzle schema in .flareforge/database/schema.ts.

Flareforge uses drizzle-kit to handle database migrations. The workflow is designed to be straightforward:

  1. Add or change a group or field within the taskDefinition section of your flareforge.jsonc file.

  2. Run the code generator to update the Drizzle schema file based on your changes.

    Terminal window
    npx flareforge codegen
  3. Run the db:generate script from your package.json. This command uses drizzle-kit to compare the updated schema with your database state and generate a new SQL migration file in the migrations/ directory.

    Terminal window
    npm run db:generate
  4. Apply the new migration to your local D1 database using the db:apply script, which executes wrangler d1 migrations apply.

    Terminal window
    npm run db:apply