You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,17 +13,25 @@ Install the module to your Nuxt application with one command:
13
13
npx nuxi module add nuxt-mikro-orm-module
14
14
```
15
15
16
-
After that, a plugin needs to be created, which calls the "mikroOrm:create" hook.
17
-
If multiple MikroORM instances are required, this hook may be called multiple times, with different names.
18
-
The plugin should ideally call this hook before the server is ready.
16
+
After that, ideally in a Nitro plugin, call initOrm() with the instance's config.
19
17
20
-
The hook "mikroOrm:init" will be called for every new instance.
18
+
Call useEntityManager() in a request context to get a forked EntityManager you can immediately use.
19
+
If you are working in a different context, such as a cron job, you may call useOrm(), and manually call `fork()` to get a locally scoped EntityManager.
21
20
22
-
## Helper functions
21
+
## API
23
22
24
-
-`getEntityManager(name?: string)` - Get an entity manager with the current request context. Intended for use in server components.
25
-
-`useOrm(name?: string)` - Get the MikroORM instance. Intended for use in server components.
23
+
-`initOrm<T extends MikroOrmInstance = MikroOrmInstance>(config: ReturnType<typeof defineConfig>, name: string = 'default', forkOptionsFactory?: (event: H3Event<EventHandlerRequest>, name: string) => ForkOptions|undefined): Promise<T>` - Initialize a MikroORM instance with the given config. Optionally provide a name and fork options callback (called on each request where EntityManager is used; must not be async). Returns a promise that resolves with the initialized MikroORM instance.
24
+
-`useEntityManager<T extends EntityManager = EntityManager>(event: H3Event<EventHandlerRequest>, name: string = 'default'): T` - Get an entity manager with the current request context.
25
+
-`useOrm<T extends MikroOrmInstance = MikroOrmInstance>(name: string = 'default'): T` - Get the MikroORM instance.
26
+
-`closeOrm(name: string = 'default', force: boolean = false)` - Close an existing MikroORM instance. The name also becomes available for reuse after close.
26
27
28
+
## Module options / Runtime options
29
+
30
+
This module's options are used as defaults for runtime options, under the `mikroOrm` key.
31
+
32
+
Available options:
33
+
34
+
-`forkOptions` - Default fork options when calling initOrm() without a `forkOptionsFactory`, or when the `forkOptionsFactory` function returns undefined.
0 commit comments