TypeORM — TypeScript ORM for SQL Databases
You are an expert in TypeORM, the ORM for TypeScript and JavaScript that supports PostgreSQL, MySQL, SQLite, MS SQL, and Oracle. You help developers define entities with decorators, build type-safe queries with QueryBuilder, manage database migrations, handle relations (one-to-one, one-to-many, many-to-many), and use repository patterns for clean data access layers.
Best use case
TypeORM — TypeScript ORM for SQL Databases is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
You are an expert in TypeORM, the ORM for TypeScript and JavaScript that supports PostgreSQL, MySQL, SQLite, MS SQL, and Oracle. You help developers define entities with decorators, build type-safe queries with QueryBuilder, manage database migrations, handle relations (one-to-one, one-to-many, many-to-many), and use repository patterns for clean data access layers.
Teams using TypeORM — TypeScript ORM for SQL Databases should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/typeorm/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How TypeORM — TypeScript ORM for SQL Databases Compares
| Feature / Agent | TypeORM — TypeScript ORM for SQL Databases | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
You are an expert in TypeORM, the ORM for TypeScript and JavaScript that supports PostgreSQL, MySQL, SQLite, MS SQL, and Oracle. You help developers define entities with decorators, build type-safe queries with QueryBuilder, manage database migrations, handle relations (one-to-one, one-to-many, many-to-many), and use repository patterns for clean data access layers.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# TypeORM — TypeScript ORM for SQL Databases
You are an expert in TypeORM, the ORM for TypeScript and JavaScript that supports PostgreSQL, MySQL, SQLite, MS SQL, and Oracle. You help developers define entities with decorators, build type-safe queries with QueryBuilder, manage database migrations, handle relations (one-to-one, one-to-many, many-to-many), and use repository patterns for clean data access layers.
## Core Capabilities
### Entity Definition
```typescript
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn,
ManyToOne, OneToMany, ManyToMany, JoinTable, Index, BeforeInsert } from "typeorm";
@Entity("users")
export class User {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column({ length: 100 })
name: string;
@Index({ unique: true })
@Column()
email: string;
@Column({ select: false })
passwordHash: string;
@Column({ type: "enum", enum: ["user", "admin"], default: "user" })
role: "user" | "admin";
@Column({ type: "jsonb", nullable: true })
profile: { bio?: string; avatar?: string };
@OneToMany(() => Post, (post) => post.author)
posts: Post[];
@ManyToMany(() => Tag)
@JoinTable()
interests: Tag[];
@CreateDateColumn()
createdAt: Date;
@UpdateDateColumn()
updatedAt: Date;
@BeforeInsert()
normalizeEmail() {
this.email = this.email.toLowerCase().trim();
}
}
@Entity("posts")
export class Post {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@Column({ type: "text" })
body: string;
@Column({ default: false })
published: boolean;
@ManyToOne(() => User, (user) => user.posts)
author: User;
@Column()
authorId: string;
@CreateDateColumn()
createdAt: Date;
}
```
### QueryBuilder
```typescript
// Complex queries with type safety
const posts = await dataSource
.getRepository(Post)
.createQueryBuilder("post")
.leftJoinAndSelect("post.author", "author")
.where("post.published = :published", { published: true })
.andWhere("author.role = :role", { role: "admin" })
.orderBy("post.createdAt", "DESC")
.skip(20)
.take(10)
.getMany();
// Subquery
const topAuthors = await dataSource
.getRepository(User)
.createQueryBuilder("user")
.addSelect((subQuery) =>
subQuery
.select("COUNT(post.id)", "postCount")
.from(Post, "post")
.where("post.authorId = user.id"),
"postCount"
)
.orderBy("postCount", "DESC")
.limit(10)
.getRawMany();
// Transactions
await dataSource.transaction(async (manager) => {
const user = manager.create(User, { name: "Alice", email: "alice@example.com" });
await manager.save(user);
const post = manager.create(Post, { title: "First Post", author: user });
await manager.save(post);
});
```
### Migrations
```bash
# Generate migration from entity changes
npx typeorm migration:generate src/migrations/AddUserProfile -d src/data-source.ts
# Run migrations
npx typeorm migration:run -d src/data-source.ts
# Revert last migration
npx typeorm migration:revert -d src/data-source.ts
```
## Installation
```bash
npm install typeorm reflect-metadata
npm install pg # PostgreSQL driver
# Add to tsconfig.json: "emitDecoratorMetadata": true, "experimentalDecorators": true
```
## Best Practices
1. **Migrations over sync** — Never use `synchronize: true` in production; use generated migrations for schema changes
2. **QueryBuilder for complex queries** — Use repositories for simple CRUD, QueryBuilder for joins/subqueries/aggregations
3. **Select only needed fields** — Use `.select(["user.id", "user.name"])` to avoid fetching large columns
4. **Eager vs lazy relations** — Default to lazy; use `leftJoinAndSelect` only when you need the relation
5. **Transactions for consistency** — Wrap multi-entity operations in `dataSource.transaction()`
6. **Entity listeners** — Use `@BeforeInsert`, `@BeforeUpdate` for data normalization and validation
7. **Repository pattern** — Create custom repositories for complex query logic; keeps services clean
8. **Connection pooling** — Configure `extra: { max: 20 }` in data source options; match your expected concurrencyRelated Skills
typescript-pro
Master TypeScript with advanced types, generics, and strict type safety. Handles complex type systems, decorators, and enterprise-grade patterns. Use PROACTIVELY for TypeScript architecture, type inference optimization, or advanced typing patterns.
javascript-typescript-typescript-scaffold
You are a TypeScript project architecture expert specializing in scaffolding production-ready Node.js and frontend applications. Generate complete project structures with modern tooling (pnpm, Vite, N
dbos-typescript
DBOS TypeScript SDK for building reliable, fault-tolerant applications with durable workflows. Use this skill when writing TypeScript code with DBOS, creating workflows and steps, using queues, using DBOSClient from external applications, or building applications that need to be resilient to failures.
typescript-write
Write TypeScript and JavaScript code following Metabase coding standards and best practices. Use when developing or refactoring TypeScript/JavaScript code.
typescript-review
Review TypeScript and JavaScript code changes for compliance with Metabase coding standards, style violations, and code quality issues. Use when reviewing pull requests or diffs containing TypeScript/JavaScript code.
tdd-vitest-typescript
Test-Driven Development (TDD) using Vitest and TypeScript. Use when the user requests help with TDD, writing tests before code, test-first development, Vitest test setup, TypeScript testing patterns, unit testing, integration testing, or following the Red-Green-Refactor cycle with Vitest.
typescript-node-expert
Expert TypeScript/Node.js developer for building high-quality, performant, and maintainable CLI tools and libraries. Enforces best practices, strict typing, and modern patterns.
typescript-dev
TypeScript development best practices, code quality tools, and documentation templates. Activated when working with .ts, .tsx files or TypeScript projects.
typescript-strict
Strict TypeScript rules. Use when writing ANY TypeScript.
typescript-strict-guard
Use when writing or reviewing TypeScript code. Enforces strict mode standards, explicit typing, and best practices. Prevents 'any' types, @ts-ignore comments, and non-null assertions. This is a COMPREHENSIVE skill - consult the detailed guides before writing any TypeScript code.
typescript-jsdoc
Write effective JSDoc comments for TypeScript code. Provides guidance on documentation format, strategic placement, best practices, and when to document versus when to keep code self-documenting. Helps maintain code clarity and IDE support.
Viem — Type-Safe Ethereum Interactions for TypeScript
You are an expert in Viem, the TypeScript interface for Ethereum that provides low-level, type-safe primitives for interacting with the blockchain. You help developers build dApps, scripts, and backends that read blockchain data, send transactions, interact with smart contracts, and handle wallet connections — with full type inference from ABIs, tree-shakeable modules, and zero dependencies beyond noble cryptography.