Database Adapters — Prisma, Drizzle, TypeORM, SysMARA ORM

Generate schema, migrations, and repositories from your system specs using Prisma, Drizzle, TypeORM, or SysMARA ORM.

What is the Database Adapter System?

The database adapter system bridges the gap between your logical entity definitions in YAML specs and the physical database layer. Instead of manually writing ORM schema files that duplicate what your specs already declare, adapters read your entity specs and generate database-specific schema definitions, migration files, and typed repository classes automatically.

The system is pluggable. You choose an adapter in your sysmara.config.yaml, and all sysmara db commands route through that adapter. Switching from Prisma to Drizzle is a config change, not a rewrite.

Configuration

Add a database section to your sysmara.config.yaml:

# sysmara.config.yaml
project: my-app
specDir: system
generatedDir: generated

database:
  adapter: prisma        # prisma | drizzle | typeorm | sysmara-orm
  provider: postgresql   # postgresql | mysql | sqlite
  outputDir: generated/db
  connectionString: env(DATABASE_URL)
Field Description
adapter Which ORM/query-builder adapter to use. One of: prisma, drizzle, typeorm, sysmara-orm.
provider The target database engine. One of: postgresql, mysql, sqlite.
outputDir Optional. Where generated schema and migration files are written. Defaults to the adapter's standard location.
connectionString Optional. Database connection string or environment variable reference.

Adapter Interface

Every adapter implements the DatabaseAdapter interface with three methods:

interface DatabaseAdapter {
  name: AdapterName;
  generateSchema(specs: SystemSpecs): GeneratedFile[];
  generateMigration(prev: SystemSpecs, next: SystemSpecs): GeneratedFile[];
  generateRepository(capability: CapabilitySpec): GeneratedFile[];
}

Adapters are registered and looked up through a central registry. This makes the system extensible — third-party adapters can be registered at startup.

import { registerAdapter, getAdapter, listAdapters } from 'sysmara/database';

// Register a custom adapter
registerAdapter(myCustomAdapter);

// Look up an adapter by name
const adapter = getAdapter('prisma');

// List all registered adapters
const names = listAdapters(); // ['prisma', 'drizzle', 'typeorm', 'sysmara-orm']

Prisma Adapter

The Prisma adapter generates a complete schema.prisma file from your entity specs. It maps SysMARA field types to Prisma scalar types, detects foreign key relationships from *_id field naming conventions, and generates typed repository classes for each capability.

Generated schema

Given an entity spec like:

- name: user
  description: A registered user
  module: users
  fields:
    - name: id
      type: string
      required: true
    - name: email
      type: string
      required: true
      constraints:
        - type: unique
    - name: role
      type: string
      required: true
    - name: created_at
      type: datetime
      required: true

The Prisma adapter generates:

// GENERATED BY SYSMARA DATABASE ADAPTER (Prisma)

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id         String    @id @default(uuid())
  email      String    @unique
  role       String
  createdAt  DateTime  @default(now())
}

Generated repository

For each capability, the adapter generates a repository with typed methods:

export class CreateUserRepository {
  private prisma: any;

  constructor(prismaClient: any) {
    this.prisma = prismaClient;
  }

  async findUserById(id: string) {
    return this.prisma.user.findUnique({ where: { id } });
  }

  async createUser(data: Record<string, unknown>) {
    return this.prisma.user.create({ data });
  }

  // ... findMany, update, delete methods
}

Drizzle Adapter

The Drizzle adapter generates TypeScript-first table definitions using Drizzle ORM's builder pattern. It supports all three providers (PostgreSQL, MySQL, SQLite) with provider-specific column types and imports.

Generated schema

// GENERATED BY SYSMARA DATABASE ADAPTER (Drizzle)

import { pgTable, varchar, uuid, timestamp } from 'drizzle-orm/pg-core';

/** A registered user */
export const user = pgTable('user', {
  id: uuid('id').defaultRandom().primaryKey(),
  email: varchar('email', { length: 255 }).notNull().unique(),
  role: varchar('role', { length: 255 }).notNull(),
  createdAt: timestamp('created_at').notNull().defaultNow(),
});

Generated repository

import { eq } from 'drizzle-orm';
import * as schema from '../../drizzle/schema.js';

export class CreateUserRepository {
  private db: any;

  constructor(db: any) {
    this.db = db;
  }

  async findUserById(id: string) {
    return this.db.select().from(schema.user).where(eq(schema.user.id, id));
  }

  async createUser(data: Record<string, unknown>) {
    return this.db.insert(schema.user).values(data);
  }

  // ... findMany, update, delete methods
}

TypeORM Adapter

The TypeORM adapter generates @Entity() decorated TypeScript classes with full decorator support: @Column, @PrimaryGeneratedColumn, @CreateDateColumn, @UpdateDateColumn, @ManyToOne, and @JoinColumn. Each entity gets its own file, plus an index file re-exporting all entities.

Generated entity

// GENERATED BY SYSMARA DATABASE ADAPTER (TypeORM)

import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm';

/** A registered user */
@Entity('user')
export class User {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column({ type: 'varchar', unique: true })
  email!: string;

  @Column({ type: 'varchar' })
  role!: string;

  @CreateDateColumn()
  createdAt!: Date;
}

Relations

When a field follows the *_id naming convention and the referenced entity exists in your specs, the adapter automatically generates @ManyToOne and @JoinColumn decorators with the correct foreign key mapping.

SysMARA ORM

SysMARA ORM is a purpose-built, AI-first ORM that goes beyond schema generation. It reads the system graph directly, scopes every query to a declared capability, enforces invariants as database constraints, logs every operation as structured JSON, and runs impact-aware migrations.

SysMARA ORM is documented in detail on its own page: SysMARA ORM →

CLI Commands

All database operations are available through the sysmara db command group:

Command Description
sysmara db generate Generate schema files from entity specs using the configured adapter.
sysmara db migrate Create a migration by diffing current specs against the previous version.
sysmara db status Show migration status and whether specs have drifted from the last generated schema.

See the CLI Reference for full command details.

Choosing an Adapter

Each adapter serves a different use case:

Adapter Best For Output
Prisma Teams already using Prisma who want SysMARA to generate their schema from specs. schema.prisma + repositories
Drizzle TypeScript-first teams who prefer Drizzle's lightweight, type-safe approach. schema.ts + repositories
TypeORM Teams using TypeORM's decorator-based entity pattern. *.entity.ts + repositories
SysMARA ORM AI-first projects that want full transparency: capability-scoped queries, operation logging, and impact-aware migrations. Raw SQL + repositories + operation log