PACKAGES

Rasengan Drizzle

@rasenganjs/drizzle connects Drizzle ORM to Rasengan Server's dependency-injection container — DrizzleModule.forRoot() registers a DataSource provider that any module can inject, the same way you'd inject any other service.

Installation

Terminal
npm install @rasenganjs/drizzle drizzle-orm pg

Usage

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 and is global: true by default, so DataSource is visible to every module without importing the Drizzle module explicitly each time. Call it exactly once per process — a second call throws.

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 — migration scripts run standalone, outside the DI container:

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' );

Full Documentation

For the complete API — DrizzleModuleOptions, DataSource, and how this fits into Rasengan Server's module/DI system — see Database (Drizzle) under the Server docs.

Community

Join the Rasengan.js community to get support, ask questions, and share your projects:

Let's build something amazing with Rasengan.js! 🚀

License

This package is MIT licensed.