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 support for typeorm@0.3.0 literal repositories #383 #384

Closed

Conversation

matomesc
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #383

What is the new behavior?

Check if Repository is a function to determine if typeorm@0.3.0 is being used and if so then use the literal repository object to generate repository injection token.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Tests are passing for current typeorm@0.2.24 but failing for typeorm@0.3.0 due to Repository no longer being a function. The custom repository also needs to be refactored: https://github.com/nestjs/typeorm/blob/master/tests/src/photo/photo.repository.ts#L5

entity.prototype instanceof AbstractRepository
typeof Repository === 'function' &&
(entity.prototype instanceof Repository ||
entity.prototype instanceof AbstractRepository)
Copy link
Member

Choose a reason for hiding this comment

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

Btw what about custom repositories in 0.3.0. Are they going to be deprecated/removed?

Copy link
Author

Choose a reason for hiding this comment

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

You can extend a repository with custom methods by calling extend() on a repository instance:

repository.extend({
  customMethod() {
     // ...
  }
});

https://github.com/typeorm/typeorm/blob/b177e230a6fcb11f1eb71d4d431d0297436b7f6f/src/repository/Repository.ts#L380

Copy link
Member

Choose a reason for hiding this comment

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

@kamilmysliwiec now (0.3.0) @EntityRepository() is deprecated. Here's how we should use instead: https://github.com/typeorm/typeorm/blob/master/docs/custom-repository.md

@kamilmysliwiec
Copy link
Member

This PR is 2 years old so it may contain outdated code. Let me just close it and create a new one for migrating to the latest version of TypeORM

@derekcunningham-ab
Copy link

This PR is 2 years old so it may contain outdated code. Let me just close it and create a new one for migrating to the latest version of TypeORM

@kamilmysliwiec Any luck with this? I'm starting a new project, and if NestJS is on the precipice of migrating, I'd rather commit to the latest version of TypeORM over using outdated approaches.

@kamilmysliwiec
Copy link
Member

I've started 10 days ago and I noticed that TypeORM Readme & docs were still not even updated to the latest version so I figured I'll have to wait at least a few days more before I can jump onto this issue.

@lovetodream
Copy link

This PR is 2 years old so it may contain outdated code. Let me just close it and create a new one for migrating to the latest version of TypeORM

@kamilmysliwiec Any luck with this? I'm starting a new project, and if NestJS is on the precipice of migrating, I'd rather commit to the latest version of TypeORM over using outdated approaches.

@derekcunningham-ab I've created a fork for myself, which seems to work fine as a temporary solution. Maybe you can use it until the official nestjs module is updated, if you don't want to wait.

@EdouardBougon
Copy link

It seems that the documentation is now updated

@bviala
Copy link

bviala commented Apr 2, 2022

bump

@jmcdo29
Copy link
Member

jmcdo29 commented Apr 2, 2022

#1233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants