Перейти к содержимому

28. ORMs: TypeORM vs Mongoose

Сравнение популярных ORM/ODM.

FeatureTypeORMMongoosePrisma
DBSQLMongoDBSQL + MongoDB
Type Safety⚠️ Partial✅✅ Best
Migrations
Relations
Active Record
Query Builder⚠️
@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') } });
const userSchema = new Schema({
email: { type: String, required: true },
name: String
});
const User = model('User', userSchema);
const users = await User.find({ email: /@example\.com/ });
const users = await prisma.user.findMany({
where: { email: { contains: '@example.com' } },
include: { posts: true }
});

Рекомендация: Prisma для новых проектов (лучший DX).


Следующий урок: Schema Migrations