ποΈ Usage with SQL Drivers
To use mikro-orm with MySQL database, install the @mikro-orm/mysql dependency and set the type option to mysql when initializing ORM. Since v4 it is no longer needed to install the mysql2 package manually.
ποΈ Usage with MongoDB
To use MikroORM with mongo database, do not forget to install @mikro-orm/mongodb dependency. Then call MikroORM.init() as part of bootstrapping your app:
ποΈ Usage with NestJS
Installation
ποΈ Usage with Vanilla JS
Since MikroORM 3.2, we can use EntitySchema helper to define own entities without decorators, which works also for Vanilla JavaScript.
ποΈ Usage with transpilers
Babel
ποΈ Usage with AdminJS
Installation
ποΈ Usage with Jest
When testing your own code that uses Jest for the tests, and MikroORM for the database, there are some things to consider.
ποΈ Using Entity Constructors
Internally, MikroORM never calls entity constructor on managed entities (those loaded via EntityManager), so you are free to use it as you wish. The constructor will be called only when you instantiate the class yourself via new operator (or when using em.create() to create new entity instance), so it is a handy place to require your data when creating new entity.
ποΈ Using Multiple Schemas
In MySQL and PostgreSQL it is possible to define your entities in multiple schemas. In MySQL terminology, it is called database, but from an implementation point of view, it is a schema.
ποΈ Using native BigInt PKs (MySQL and PostgreSQL)
Since v6, bigints are represented by the native BigInt type, and as such, they don't require explicit type in the decorator options:
ποΈ Creating Custom Driver
If you want to use database that is not currently supported, you can implement your own driver. To do so, you will need to design 4 classes: