Skip to main content
Turn on Postgres for a Keja project, apply migrations, generate repositories, and read rows from a route.

Prerequisites

  • A Keja project that runs with keja dev / keja start
  • A Postgres database you can reach
  • Familiarity with the OwnedObjects column list

Steps

1. Enable the database

In keja.config.ts:
In .env:
Restart the process after changing db or DATABASE_URL. The pool is fixed at boot.

2. Add a migration

Create migrations/0001_notes.sql (use the next free number if files already exist):

3. Turn on list/get and generate

keja.repositories.ts:
This writes src/db/repositories.ts from migration SQL. It does not connect to Postgres.

4. Use the repository in a route

5. Optional: seed rows

Add seed/notes.ts:
Existing _id values are skipped on re-run.

Done

Postgres is on, migrations applied, and a handler can list rows. Full API: Database. Why the row shape exists: OwnedObjects model.