Databases
Last updated 2026-10-07
Core has no database dependency and no database adapter API yet. A database adapter interface (PostgreSQL, MySQL, MongoDB, SQLite) is planned, not implemented. Use any driver today and connect it through lifecycle hooks so it is closed on shutdown.
import { createApp } from "@rheajs/core";
// Stand-in for any client: pg, mysql2, mongodb, better-sqlite3...
const db = {
async connect() {},
async close() {},
};
export const app = createApp()
.hook("beforeStart", () => db.connect())
.hook("afterShutdown", () => db.close());beforeStartruns before the port opens. If it throws,start()rejects and the server never listens.- Shutdown hooks always all run, even if one fails. Failures are logged.
- The generated modules use an in-memory repository. Replace the repository implementation, keep the service and controller unchanged.
- Add
DATABASE_URLtosrc/config/env.tsso a missing value aborts startup.