-
-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): allow using
AsyncLocalStorage
for request context
Closes #575
- Loading branch information
Showing
8 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: Using `AsyncLocalStorage` | ||
--- | ||
|
||
By default, `domain` api use used in the `RequestContext` helper. Since v4.0.3, | ||
you can use the new `AsyncLocalStorage` too, if you are on up to date node version: | ||
|
||
```typescript | ||
const storage = new AsyncLocalStorage<EntityManager>(); | ||
|
||
const orm = await MikroORM.init({ | ||
context: () => storage.getStore(), | ||
// ... | ||
}); | ||
|
||
app.use((req, res, next) => { | ||
storage.run(orm.em.fork(true, true), next); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: Using `AsyncLocalStorage` | ||
--- | ||
|
||
By default, `domain` api use used in the `RequestContext` helper. Since v4.0.3, | ||
you can use the new `AsyncLocalStorage` too, if you are on up to date node version: | ||
|
||
```typescript | ||
const storage = new AsyncLocalStorage<EntityManager>(); | ||
|
||
const orm = await MikroORM.init({ | ||
context: () => storage.getStore(), | ||
// ... | ||
}); | ||
|
||
app.use((req, res, next) => { | ||
storage.run(orm.em.fork(true, true), next); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters