Skip to content

Commit

Permalink
Document inline context setting with MikroORM
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Sep 20, 2024
1 parent f5a4887 commit 3969995
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion docs/docs/orms/mikro-orm.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ npx mikro-orm-esm migration:up

## Usage

Add an [Express](https://expressjs.com/) middleware to pass application context with all underlying data changes within an HTTP request:
### Express.js

Add the `setContext` [Express](https://expressjs.com/) middleware to pass application context with all underlying data changes within an HTTP request:

```ts title="src/index.ts"
import { setContext } from "@bemi-db/mikro-orm";
Expand All @@ -70,6 +72,26 @@ Application context:
* Is used only with `INSERT`, `UPDATE`, `DELETE` SQL queries performed via MikroORM. Otherwise, it is a no-op.
* Is passed directly into PG [Write-Ahead Log](https://www.postgresql.org/docs/current/wal-intro.html) with data changes without affecting the structure of the database and SQL queries.

### Inline context

It is also possible to manually set or override context by using the `bemiContext` function:

```ts title="src/lambda-function.ts"
import { bemiContext } from "@bemi-db/prisma";

export const handler = async (event) => {
const orm = await MikroORM.init(config);

bemiContext({
gqlField: `${event.typeName}.${event.fieldName}`,
gqlArguments: event.arguments,
origin: event.request.headers.origin,
})

// ...
}
```

## Database connection

Connect your PostgreSQL source database on [bemi.io](https://bemi.io) to start ingesting and storing all data changes stitched together with application-specific context.
Expand Down

0 comments on commit 3969995

Please sign in to comment.