28. ORMs: TypeORM vs Mongoose
Сравнение популярных ORM/ODM.
Feature Comparison
Заголовок раздела «Feature Comparison»| Feature | TypeORM | Mongoose | Prisma |
|---|---|---|---|
| DB | SQL | MongoDB | SQL + MongoDB |
| Type Safety | ✅ | ⚠️ Partial | ✅✅ Best |
| Migrations | ✅ | ❌ | ✅ |
| Relations | ✅ | ❌ | ✅ |
| Active Record | ✅ | ✅ | ❌ |
| Query Builder | ✅ | ⚠️ | ✅ |
TypeORM (SQL)
Заголовок раздела «TypeORM (SQL)»@Entity()class User { @PrimaryGeneratedColumn() id: number;
@Column() email: string;
@OneToMany(() => Post, post => post.author) posts: Post[];}
const users = await userRepository.find({ where: { email: Like('%@example.com') } });Mongoose (MongoDB)
Заголовок раздела «Mongoose (MongoDB)»const userSchema = new Schema({ email: { type: String, required: true }, name: String});
const User = model('User', userSchema);
const users = await User.find({ email: /@example\.com/ });Prisma (Universal)
Заголовок раздела «Prisma (Universal)»const users = await prisma.user.findMany({ where: { email: { contains: '@example.com' } }, include: { posts: true }});Рекомендация: Prisma для новых проектов (лучший DX).
Следующий урок: Schema Migrations →