packages/decorators/README.md
Decorator definitions for MikroORM entity mapping. Provides both legacy (TypeScript experimental) and ES spec decorator definitions for defining entities, properties, and relations.
npm install @mikro-orm/core @mikro-orm/decorators
Note:
@mikro-orm/corere-exports all decorators, so you only need to install this package directly if you want to use decorators without pulling in the full core module.
import { Entity, PrimaryKey, Property, ManyToOne } from '@mikro-orm/core';
@Entity()
class Book {
@PrimaryKey()
id!: number;
@Property()
title!: string;
@ManyToOne(() => Author)
author!: Author;
}
For projects using the TC39 standard decorators (TypeScript 5.0+):
import { Entity, PrimaryKey, Property } from '@mikro-orm/decorators';
For projects using TypeScript experimental decorators:
import { Entity, PrimaryKey, Property } from '@mikro-orm/decorators/legacy';
@Entity() — marks a class as a persistent entity@Property(), @Enum(), @Formula(), @Index(), @Unique(), @Check()@PrimaryKey(), @SerializedPrimaryKey()@ManyToOne(), @OneToMany(), @ManyToMany(), @OneToOne()@Embeddable(), @Embedded()@BeforeCreate(), @AfterCreate(), @BeforeUpdate(), @AfterUpdate(), @BeforeDelete(), @AfterDelete()See the official MikroORM documentation and the using decorators guide.
Copyright © 2018-present Martin Adámek. Licensed under the MIT License.