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: add InjectEntityManager decorator for MikroORM and upgrade document #3114

Merged
merged 4 commits into from
Aug 5, 2023

Conversation

ghostoy
Copy link
Contributor

@ghostoy ghostoy commented Jul 27, 2023

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

mikro

Description of change

由于MikroORM从5.7开始,开始废弃Repository上的persist, flush等接口,v6计划彻底删除这些接口,导致要保存到数据库的时候要这样写:

class BookService {
  @InjectRepository(Book)
  bookRepository: EntityRepository<Book>;

  async create() {
    const book = new Book(/** 初始化 **/);
    await this.bookRepository.getEntityManager().persistAndFlush(book);
  }
}

增加InjectEntityManager直接注入EntityManager后,写法如下:

class BookService {
  @InjectEntityManager()
  em: EntityManager;

  async create() {
    const book = new Book(/** 初始化 **/);
    await this.em.persistAndFlush(book);
  }
}

@codecov-commenter
Copy link

codecov-commenter commented Jul 27, 2023

Codecov Report

Patch coverage: 91.66% and project coverage change: -0.14% ⚠️

Comparison is base (2d93592) 81.78% compared to head (ffe0c82) 81.64%.

❗ Current head ffe0c82 differs from pull request most recent head 069754e. Consider uploading reports for the commit 069754e to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3114      +/-   ##
==========================================
- Coverage   81.78%   81.64%   -0.14%     
==========================================
  Files         437      437              
  Lines       15918    15929      +11     
  Branches     3769     3773       +4     
==========================================
- Hits        13018    13005      -13     
- Misses       2631     2650      +19     
- Partials      269      274       +5     
Files Changed Coverage Δ
packages/mikro/src/configuration.ts 90.69% <88.88%> (-0.74%) ⬇️
packages/mikro/src/decorator.ts 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

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

@czy88840616 czy88840616 added the pr: new feature This PR adds a new API or behavior. label Jul 27, 2023
@czy88840616 czy88840616 changed the title 为MikroORM增加InjectEntityManager feat: add InjectEntityManager decorator for MikroORM and upgrade document Jul 27, 2023
@czy88840616 czy88840616 modified the milestones: 2.x, 3.12 Jul 30, 2023
@czy88840616 czy88840616 added pr: polish This PR adds a very minor behavior improvement that users will enjoy. and removed pr: new feature This PR adds a new API or behavior. labels Aug 5, 2023
@czy88840616 czy88840616 removed this from the 3.12.x milestone Aug 5, 2023
@czy88840616 czy88840616 merged commit dd7b48f into midwayjs:main Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Development

Successfully merging this pull request may close these issues.

3 participants