mikro-orm
You are an expert in MikroORM, the TypeScript ORM built on Unit of Work and Identity Map patterns. You help developers build data layers with decorator-based entities, automatic change tracking, lazy/eager loading, embeddables, query builder, migrations, and seeding — supporting PostgreSQL, MySQL, SQLite, and MongoDB with a DDD-friendly architecture.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o mikro-orm.zip https://jpskill.com/download/15124.zip && unzip -o mikro-orm.zip && rm mikro-orm.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15124.zip -OutFile "$d\mikro-orm.zip"; Expand-Archive "$d\mikro-orm.zip" -DestinationPath $d -Force; ri "$d\mikro-orm.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
mikro-orm.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
mikro-ormフォルダができる - 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
📖 Claude が読む原文 SKILL.md(中身を展開)
この本文は AI(Claude)が読むための原文(英語または中国語)です。日本語訳は順次追加中。
MikroORM — TypeScript ORM with Unit of Work
You are an expert in MikroORM, the TypeScript ORM built on Unit of Work and Identity Map patterns. You help developers build data layers with decorator-based entities, automatic change tracking, lazy/eager loading, embeddables, query builder, migrations, and seeding — supporting PostgreSQL, MySQL, SQLite, and MongoDB with a DDD-friendly architecture.
Core Capabilities
Entity Definition
import { Entity, PrimaryKey, Property, ManyToOne, OneToMany, Collection,
Enum, Index, Unique, Embeddable, Embedded, Filter } from "@mikro-orm/core";
import { v4 } from "uuid";
@Embeddable()
class Address {
@Property()
street: string;
@Property()
city: string;
@Property()
country: string;
}
@Entity()
@Filter({ name: "active", cond: { deletedAt: null }, default: true })
export class User {
@PrimaryKey()
id: string = v4();
@Property()
name: string;
@Index()
@Unique()
@Property()
email: string;
@Enum(() => UserRole)
role: UserRole = UserRole.USER;
@Embedded(() => Address, { nullable: true })
address?: Address;
@OneToMany(() => Post, (post) => post.author)
posts = new Collection<Post>(this);
@Property()
createdAt: Date = new Date();
@Property({ onUpdate: () => new Date() })
updatedAt: Date = new Date();
@Property({ nullable: true })
deletedAt?: Date;
}
enum UserRole { USER = "user", ADMIN = "admin" }
@Entity()
export class Post {
@PrimaryKey()
id: string = v4();
@Property()
title: string;
@Property({ type: "text" })
body: string;
@Property()
published: boolean = false;
@ManyToOne(() => User)
author: User;
@Property()
createdAt: Date = new Date();
}
Unit of Work (Auto Change Tracking)
import { MikroORM, RequestContext } from "@mikro-orm/core";
const orm = await MikroORM.init({
entities: [User, Post],
dbName: "myapp",
type: "postgresql",
debug: process.env.NODE_ENV === "development",
});
// Express middleware — one EntityManager per request
app.use((req, res, next) => {
RequestContext.create(orm.em, next);
});
// Usage — automatic change tracking
app.put("/users/:id", async (req, res) => {
const em = orm.em;
const user = await em.findOneOrFail(User, req.params.id);
user.name = req.body.name; // Just modify the entity
user.email = req.body.email;
await em.flush(); // MikroORM detects changes, generates UPDATE
res.json(user);
});
// Identity Map — same entity loaded twice returns same reference
const user1 = await em.findOne(User, "abc");
const user2 = await em.findOne(User, "abc");
console.log(user1 === user2); // true — same object in memory
// QueryBuilder
const topAuthors = await em.createQueryBuilder(User, "u")
.select(["u.*", "count(p.id) as post_count"])
.leftJoin("u.posts", "p")
.where({ role: UserRole.ADMIN })
.groupBy("u.id")
.orderBy({ post_count: "DESC" })
.limit(10)
.getResultList();
Installation
npm install @mikro-orm/core @mikro-orm/postgresql @mikro-orm/cli
npx mikro-orm migration:create
npx mikro-orm migration:up
Best Practices
- Unit of Work — Modify entities directly; call
em.flush()once to batch all changes into minimal SQL - Identity Map — Same entity loaded twice returns same reference; prevents inconsistency in a request
- RequestContext — Use
RequestContext.create()middleware; gives each request its own EntityManager - Filters — Use
@Filterfor soft deletes, multi-tenancy; applied automatically to all queries - Embeddables — Use
@Embeddedfor value objects (Address, Money); stored in same table, typed as objects - Populate — Explicitly populate relations:
em.find(User, {}, { populate: ['posts'] }); no implicit lazy loading - Migrations — Use CLI to generate migrations from entity changes; review SQL before running
- Serialization — Use
wrap(entity).toJSON()or custom serializers; control what's exposed in API responses