typeorm
TypeORMのエキスパートとして、TypeScriptやJavaScriptでPostgreSQLなどのデータベースを扱う開発者を支援し、デコレータを使ったエンティティ定義や、安全なクエリ構築、データベース移行、リレーション管理、リポジトリパターンによるデータアクセス層の構築をサポートするSkill。
📜 元の英語説明(参考)
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.
🇯🇵 日本人クリエイター向け解説
TypeORMのエキスパートとして、TypeScriptやJavaScriptでPostgreSQLなどのデータベースを扱う開発者を支援し、デコレータを使ったエンティティ定義や、安全なクエリ構築、データベース移行、リレーション管理、リポジトリパターンによるデータアクセス層の構築をサポートするSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o typeorm.zip https://jpskill.com/download/15506.zip && unzip -o typeorm.zip && rm typeorm.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15506.zip -OutFile "$d\typeorm.zip"; Expand-Archive "$d\typeorm.zip" -DestinationPath $d -Force; ri "$d\typeorm.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
typeorm.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
typeormフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
TypeORM — SQLデータベース向けのTypeScript ORM
あなたは、PostgreSQL、MySQL、SQLite、MS SQL、およびOracleをサポートするTypeScriptおよびJavaScript向けのORMであるTypeORMのエキスパートです。あなたは、開発者がデコレータでエンティティを定義し、QueryBuilderで型安全なクエリを構築し、データベースのマイグレーションを管理し、リレーション(一対一、一対多、多対多)を処理し、クリーンなデータアクセス層のためにリポジトリパターンを使用するのを支援します。
主要な機能
エンティティの定義
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
// 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);
});
マイグレーション
# 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
インストール
npm install typeorm reflect-metadata
npm install pg # PostgreSQL driver
# Add to tsconfig.json: "emitDecoratorMetadata": true, "experimentalDecorators": true
ベストプラクティス
- syncよりもマイグレーション — 本番環境では決して
synchronize: trueを使用しないでください。スキーマの変更には生成されたマイグレーションを使用してください。 - 複雑なクエリにはQueryBuilder — 単純なCRUDにはリポジトリを使用し、join/サブクエリ/集計にはQueryBuilderを使用してください。
- 必要なフィールドのみを選択 — 大きなカラムのフェッチを避けるために、
.select(["user.id", "user.name"])を使用してください。 - Eager vs lazy relations — デフォルトはlazyにしてください。リレーションが必要な場合にのみ
leftJoinAndSelectを使用してください。 - 一貫性のためにトランザクション — 複数のエンティティ操作を
dataSource.transaction()でラップしてください。 - エンティティリスナー — データの正規化と検証のために
@BeforeInsert、@BeforeUpdateを使用してください。 - リポジトリパターン — 複雑なクエリロジックのためにカスタムリポジトリを作成してください。サービスをクリーンに保ちます。
- コネクションプーリング — データソースオプションで
extra: { max: 20 }を設定してください。予想される同時実行数に合わせてください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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
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
// 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
# 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
npm install typeorm reflect-metadata
npm install pg # PostgreSQL driver
# Add to tsconfig.json: "emitDecoratorMetadata": true, "experimentalDecorators": true
Best Practices
- Migrations over sync — Never use
synchronize: truein production; use generated migrations for schema changes - QueryBuilder for complex queries — Use repositories for simple CRUD, QueryBuilder for joins/subqueries/aggregations
- Select only needed fields — Use
.select(["user.id", "user.name"])to avoid fetching large columns - Eager vs lazy relations — Default to lazy; use
leftJoinAndSelectonly when you need the relation - Transactions for consistency — Wrap multi-entity operations in
dataSource.transaction() - Entity listeners — Use
@BeforeInsert,@BeforeUpdatefor data normalization and validation - Repository pattern — Create custom repositories for complex query logic; keeps services clean
- Connection pooling — Configure
extra: { max: 20 }in data source options; match your expected concurrency