SERVER ECOSYSTEM

Database (Drizzle)

@rasenganjs/drizzle connects Drizzle ORM to Rasengan Server's DI container — DrizzleModule.forRoot() registers a DataSource provider that any module can inject.

Terminal
npm install @rasenganjs/drizzle drizzle-orm pg

Connecting

app.module.ts
import { defineModule } from '@rasenganjs/server'; import { DrizzleModule } from '@rasenganjs/drizzle'; import { nodePostgresAdapter } from '@rasenganjs/drizzle/drivers/node-postgres'; import * as schema from './schema'; import userModule from './user.module'; export default defineModule({ imports: [ DrizzleModule.forRoot({ adapter: nodePostgresAdapter(), connection: { connectionString: process.env.DATABASE_URL! }, schema, }), userModule, ], });

DrizzleModule.forRoot() connects eagerly at call time — not lazily on first .db access — and is global: true by default, so DataSource is visible everywhere without importing the Drizzle module explicitly in every feature module.

Injecting DataSource

user.service.ts
import { DataSource } from '@rasenganjs/drizzle'; import { users } from './schema'; import { eq } from 'drizzle-orm'; export class UserService { constructor(private dataSource: DataSource) {} findById(id: number) { return this.dataSource.db.select().from(users).where(eq(users.id, id)); } }

dataSource.db is your normal Drizzle client — typed against whatever schema you passed to forRoot().

Driver Adapters

Driver adapters are separate subpath exports, so the core package never pulls in a driver client you're not using. Only Postgres (node-postgres) ships today:

import { nodePostgresAdapter } from '@rasenganjs/drizzle/drivers/node-postgres';

Running Migrations

runMigrations() uses a separate, short-lived connection from the module's — migration scripts run standalone, outside the DI container, and close their connection when done rather than reusing the long-lived one DrizzleModule holds:

migrate.ts (run standalone, e.g. in CI)
import { runMigrations } from '@rasenganjs/drizzle'; import { nodePostgresAdapter } from '@rasenganjs/drizzle/drivers/node-postgres'; import * as schema from './schema'; await runMigrations( nodePostgresAdapter(), { connectionString: process.env.DATABASE_URL! }, schema, './drizzle/migrations' );
Validation Adapters
ServerApp