New to Claude Skills? Learn how to install them →

jeremylongshore on GitHub

ORM Code Generator

Free

Automate ORM code generation from your database schema.

Get this skill

Free · Opens the source repo

What ORM Code Generator does

The ORM Code Generator skill streamlines the process of generating Object-Relational Mapping (ORM) code from existing database schemas or domain specifications. This tool is particularly useful for developers working with various ORM frameworks such as Prisma, TypeORM, Sequelize, SQLAlchemy, Django ORM, and Drizzle ORM. By automating the creation of model classes, migration files, and repository patterns, it significantly reduces the manual effort typically involved in setting up ORM layers in applications.

To use the skill, you must have a database connection string and the appropriate ORM framework installed in your project. The skill introspects the database schema by querying system tables to gather details about tables, columns, data types, and constraints. It then maps these database types to the corresponding ORM field types, ensuring that the generated code is type-safe and adheres to the conventions of the selected ORM framework.

The generator not only creates model classes with the necessary decorators and attributes but also sets up relationship mappings automatically based on foreign key constraints. Additionally, it generates migration files that capture the current schema state, making it easier to manage database changes over time. Validation decorators and constraints are also included to ensure that the generated models maintain data integrity.

This skill is ideal for developers looking to quickly scaffold ORM layers in their applications, especially when dealing with complex database schemas. It helps maintain consistency between the database and application code, ultimately speeding up the development process and reducing the likelihood of errors.

When to use it

Use this skill when you need to quickly generate ORM models and migrations from an existing database schema or when starting a new project with a defined domain model.

When not to use it

This skill may not be suitable for projects with highly customized ORM implementations or where manual control over model generation is required.

What you can build with it

Generate Models for a New Project

Quickly scaffold ORM models and migrations for a new application by introspecting the existing database schema.

Maintain Consistency in Legacy Systems

Use the skill to generate ORM models that reflect the current state of a legacy database, ensuring that application code remains in sync.

Automate Database Migrations

Generate migration files automatically when changes are made to the database schema, simplifying the deployment process.

How to install ORM Code Generator

View source

1. Install with the skills CLI

npx skills add jeremylongshore/claude-code-plugins-plus-skills/generating-orm-code --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by jeremylongshore

ORM Code Generator

Overview

Generate type-safe ORM model classes, migration files, and repository patterns from existing database schemas or domain specifications. Supports Prisma, TypeORM, Sequelize, SQLAlchemy, Django ORM, and Drizzle ORM.

Prerequisites

  • Database connection string or credentials for schema introspection
  • psql or mysql CLI for querying information_schema
  • Target ORM framework already installed in the project (prisma, typeorm, sqlalchemy, etc.)
  • Node.js/Python/Go runtime matching the target ORM
  • Existing project structure to place generated models in the correct directory

Instructions

  1. Introspect the database schema by querying information_schema.COLUMNS, information_schema.TABLE_CONSTRAINTS, and information_schema.KEY_COLUMN_USAGE to extract all tables, columns, data types, nullable flags, defaults, primary keys, foreign keys, and unique constraints.

  2. For PostgreSQL, additionally query pg_catalog.pg_type for custom enum types and pg_catalog.pg_index for index definitions. For MySQL, query information_schema.STATISTICS for index details.

  3. Map database column types to ORM field types:

    • varchar/text -> String / @Column('text')
    • integer/bigint -> Int / @Column('int')
    • boolean -> Boolean / @Column('boolean')
    • timestamp/datetime -> DateTime / @Column('timestamp')
    • jsonb/json -> Json / @Column('jsonb')
    • uuid -> String with @default(uuid()) or uuid.uuid4
    • Custom enums -> Generate enum type definitions
  4. Generate model classes with proper decorators/attributes:

    • For Prisma: Generate schema.prisma with model blocks, @id, @unique, @relation, and @default directives.
    • For TypeORM: Generate entity classes with @Entity(), @Column(), @PrimaryGeneratedColumn(), @ManyToOne(), @OneToMany() decorators.
    • For SQLAlchemy: Generate model classes extending Base with Column(), ForeignKey(), relationship(), and __tablename__.
    • For Drizzle: Generate table definitions with pgTable(), serial(), varchar(), timestamp(), and relations().
  5. Generate relationship mappings from foreign key constraints. Detect one-to-one (unique FK), one-to-many, and many-to-many (junction table with two FKs) patterns automatically. Add both sides of each relationship with proper cascade options.

  6. Create migration files that capture the current schema state. For Prisma: npx prisma migrate dev --name init. For TypeORM: generate migration with typeorm migration:generate. For Alembic: alembic revision --autogenerate.

  7. Generate repository/service layer with common CRUD operations: findById, findAll with pagination, create, update, delete, and relationship-aware queries (findWithRelations).

  8. Add validation decorators or constraints matching database CHECK constraints and NOT NULL columns. Use class-validator for TypeORM, Pydantic validators for SQLAlchemy, or Zod schemas for Prisma.

  9. Generate TypeScript/Python type definitions or interfaces for API layer consumption, ensuring the ORM models and API types stay synchronized.

  10. Validate generated models by running a test migration against a temporary database or by comparing the generated schema against the live database schema with a diff tool.

Output

  • Model/entity files with full type annotations, decorators, and relationship mappings
  • Migration files capturing the initial schema state
  • Enum type definitions for database enum columns
  • Repository/service classes with typed CRUD operations
  • Validation schemas (Zod, class-validator, Pydantic) matching database constraints
  • Type definition files for API layer consumption

Error Handling

ErrorCauseSolution
Circular relationship dependencyTwo entities reference each other, causing import cyclesUse lazy loading (() => RelatedEntity) in TypeORM; use ForwardRef in SQLAlchemy; split into separate files with deferred imports
Unknown column type mappingDatabase uses custom types, extensions, or domain types not in the standard mappingAdd custom type mapping in generator config; use @Column({ type: 'text' }) as fallback; register custom transformers
Migration conflicts with existing dataGenerated migration adds NOT NULL columns without defaultsAdd default values to new columns; create a two-phase migration (add nullable, backfill, set NOT NULL)
Junction table not detected as many-to-manyJunction table has extra columns beyond the two foreign keysModel as an explicit entity with two ManyToOne relationships instead of an implicit ManyToMany
Schema drift between ORM models and databaseManual database changes not reflected in ORM codeRun introspection again; use prisma db pull or sqlacodegen to regenerate; diff against existing models

Examples

Prisma schema from PostgreSQL e-commerce database: Introspect 15 tables including users, orders, products, and categories. Generate schema.prisma with proper @relation directives, enum types for order status, and @default(autoincrement()) for serial columns. Output includes Zod validation schemas for each model.

TypeORM entities from MySQL SaaS application: Generate entity classes for a multi-tenant application with tenant isolation. Each entity includes a tenantId column with a custom @TenantAware decorator. Repository layer includes tenant-scoped query methods.

SQLAlchemy models from legacy database with naming conventions: Introspect a database with inconsistent naming (mix of camelCase and snake_case). Generate models with __tablename__ preserving original names while using Pythonic property names. Alembic migration captures the full schema.

Resources

Frequently asked questions about ORM Code Generator

Similar skills