Spraxium logoSpraxium

CLI Database

How spraxium database scaffolds a complete ORM integration module in seconds. Choose your ORM and database engine through the interactive wizard, then start writing queries immediately.

What it does

spraxium database (alias spraxium db) generates a fully wired database module inside your project. It walks you through an interactive wizard where you select an ORM and a database engine, then scaffolds the module files, patches your environment config with the required keys, installs the necessary packages, and optionally registers the module in your AppModule. By the end of the wizard your project is ready to run queries with no manual configuration.

The command accepts an optional ORM argument to skip the first selection step. When you already know what you want, spraxium database prisma jumps directly to the database engine prompt.

When to use

Use this command at the beginning of a project or when adding database access to an existing Spraxium application. It is the equivalent of manually installing packages, writing connection boilerplate, and registering the module, all collapsed into a single interactive flow. Run it once per database integration; for schema changes or migrations, use the ORM tooling directly after setup.

Supported ORMs

What the wizard does

ORM selection

If you did not pass an ORM as a CLI argument, the wizard presents an interactive list of the five supported ORMs with a short description for each. Navigate with the arrow keys and press Enter to confirm.

Database engine selection

For ORMs that support multiple engines (Prisma, Drizzle, TypeORM, Mikro-ORM), the wizard asks which engine to target. Mongoose skips this step because it only targets MongoDB.

Module name

The wizard prompts for a module name with database as the default. The name is converted to kebab-case for the folder and PascalCase for the class names. A name like user-db produces a UserDbModule and a src/modules/user-db/ directory.

File scaffolding

The CLI downloads the template for your ORM and engine combination and writes the module, service, schema, and config files into src/modules/ {name}/. A root-level config file (such as drizzle.config.ts or prisma/schema.prisma) is also added if the ORM requires it.

Environment key injection

The required environment variables (DATABASE_URL, DATABASE_PATH, etc.) are appended to your app.env.ts automatically if they are not already present. No manual editing needed.

Package installation

The wizard asks if you want to install packages immediately. Confirming runs the detected package manager to add runtime dependencies (such as the ORM client and database driver) and dev dependencies (CLI tools, type definitions). Post-install commands like npx prisma generate are also run automatically.

AppModule registration

If an app.module.ts is found in your src/ directory, the wizard offers to add the generated module to the imports array automatically. This connects the module to the DI container so you can inject the DatabaseService anywhere in the application.

Generated file structure

The exact files vary by ORM but the layout follows the same convention for every combination.

project structure
database.module.ts
database.service.ts
database.schema.ts

Root-level config files are also created

Some ORMs require a configuration file at the project root. Prisma generates a prisma/ directory with schema.prisma. Drizzle generates drizzle.config.ts. These files are written alongside the module files and should be committed to version control.

After the wizard

Once the command finishes, you can inject DatabaseService into any handler, guard, or service within the same module scope. The service is exported from the database module, so importing DatabaseModule in any other module gives you access to it through the DI container.

src/modules/hello/hello.service.ts
import { Injectable } from '@spraxium/common';
import { DatabaseService } from '../database/database.service';

@Injectable()
export class HelloService {
  constructor(private readonly db: DatabaseService) {}

  async getCount(): Promise<number> {
    // Use the ORM client returned by the service
    return this.db
      .getDb()
      .select()
      .from(table)
      .then((rows) => rows.length);
  }
}