Installation & Usage
First install the module via yarn
or npm
and do not forget to install the database driver as well:
or
Next you will need to enable support for decorators
in tsconfig.json
via:
Then call MikroORM.init
as part of bootstrapping your app:
You can also provide paths where you store your entities via entitiesDirs
array. Internally
it uses globby
so you can use
globbing patterns.
You should provide list of directories, not paths to entities directly. If you want to do that
instead, you should use entities
array and use globby
manually:
#
Entity discovery in TypeScriptInternally, MikroORM
uses performs analysis of source files of entities
to sniff types of all properties. This process can be slow if your project contains lots of
files. To speed up the discovery process a bit, you can provide more accurate paths where your
entity source files are:
#
Request contextThen you will need to fork entity manager for each request so their identity maps will not
collide. To do so, use the RequestContext
helper:
More info about RequestContext
is described here.
Now you can start defining your entities (in one of the entitiesDirs
folders).