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): allow extending EntityManager #5064

Merged
merged 1 commit into from Jan 1, 2024
Merged

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Jan 1, 2024

To extend the EntityManager with your own custom methods, you can use the entityManager ORM option:

import { MikroORM, EntityManager } from '@mikro-orm/sqlite';

class MyEntityManager extends EntityManager {

  myCustomMethod(base: number): number {
    return base * Math.random();
  }

}

const orm = await MikroORM.init({
  entities: [...],
  dbName: ':memory:',
  entityManager: MyEntityManager,
});
console.log(orm.em instanceof MyEntityManager); // true
const res = orm.em.myCustomMethod(123);

To extend the EntityManager with your own custom methods, you can use the `entityManager` ORM option:

```ts
import { MikroORM, EntityManager } from '@mikro-orm/sqlite';

class MyEntityManager extends EntityManager {

  myCustomMethod(base: number): number {
    return base * Math.random();
  }

}

const orm = await MikroORM.init({
  entities: [...],
  dbName: ':memory:',
  // highlight-next-line
  entityManager: MyEntityManager,
});
console.log(orm.em instanceof MyEntityManager); // true
const res = orm.em.myCustomMethod(123);
```
@B4nan B4nan mentioned this pull request Jan 1, 2024
Copy link

codecov bot commented Jan 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (66a6b75) 99.79% compared to head (3038a9f) 99.79%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5064   +/-   ##
=======================================
  Coverage   99.79%   99.79%           
=======================================
  Files         221      221           
  Lines       16383    16386    +3     
  Branches     3954     3954           
=======================================
+ Hits        16349    16352    +3     
  Misses         34       34           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@B4nan B4nan merged commit 6c363e7 into master Jan 1, 2024
11 checks passed
@B4nan B4nan deleted the extend-entity-manager branch January 1, 2024 21:38
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

1 participant