Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): create context from async orm instance #4812

Merged
merged 4 commits into from Oct 24, 2023

Conversation

mehedimi
Copy link
Contributor

fixed #4805

Added support to orm instance which wraps inside of Promise to @CreateRequestContext() decorator.

It now additionally supports async callback like the below

async getOrm(): Promise<MikroORM>{
  //
}

const ORM = getOrm();

@CreateRequestContext(async () => ORM)

Or Promise instance

@CreateRequestContext(ORM)

Or async orm property

class H {
  constructor(protected orm: Promise<MikroORM>) {}

  @CreateRequestContext()
  async handle() {

  }
}

Let me know if you have any questions about this PR or need anything changed.

fixed mikro-orm#4805

Added support to orm instance which wraps inside of Promise to `@CreateRequestContext()` decorator.

It now additionally supports `async` callback like the below

```ts
async getOrm(): Promise<MikroORM>{
  //
}

const ORM = getOrm();

@CreateRequestContext(async () => ORM)
```

Or Promise instance
```ts
@CreateRequestContext(ORM)
```

Or async `orm` property

```ts
class H {
  constructor(protected orm: Promise<MikroORM>) {}

  @CreateRequestContext()
  async handle() {

  }
}
```

Let me know if you have any questions about this PR or need anything changed.
packages/core/src/decorators/CreateRequestContext.ts Outdated Show resolved Hide resolved
packages/core/src/decorators/CreateRequestContext.ts Outdated Show resolved Hide resolved
packages/core/src/decorators/CreateRequestContext.ts Outdated Show resolved Hide resolved
packages/core/src/utils/Utils.ts Outdated Show resolved Hide resolved
tests/Utils.test.ts Outdated Show resolved Hide resolved
tests/decorators.test.ts Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

All modified lines are covered by tests ✅

Files Coverage Δ
...ckages/core/src/decorators/CreateRequestContext.ts 100.00% <100.00%> (ø)

📢 Thoughts on this report? Let us know!.

@mehedimi
Copy link
Contributor Author

Updated the code as per your suggestion

@@ -86,6 +98,17 @@ class TestClass2 {

}

class TestClass3 {

constructor(private readonly orm: Promise<MikroORM>) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really weird thing to support, a bad practice in general

@B4nan B4nan merged commit fbf3a4d into mikro-orm:master Oct 24, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants