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

Course fix suggestion - 'Add PostgreSQL with TypeORM: Using repository to Access Database' #57

Closed
Nagell opened this issue Apr 16, 2022 · 2 comments

Comments

@Nagell
Copy link

Nagell commented Apr 16, 2022

Hi,

In the chapter 'Add PostgreSQL with TypeORM: Using repository to Access Database' after installing TypeORM in version 0.3 or above the method 'findOne' is no more correct and there is no suggestion which one should be installed. According to TypeORM changelog:

findOne() signature without parameters was dropped.
If you need a single row from the db you can use a following syntax:

const [user] = await userRepository.find()

This change was made to prevent user confusion.
See typeorm/typeorm#2500 for details.

findOne(id) signature was dropped. Use following syntax instead:

const user = await userRepository.findOneBy({
    id: id // where id is your column name
})

I can imagine that making a new video every time when something changes, would be to much, but some notice in the code below could be helpful :)

@kamilmysliwiec
Copy link
Member

We're currently working on re-recordings of the entire Postgres chapter and will update videos shortly :)

@thxv3n0lvl
Copy link

So first of all, apologies to the authors for posting this as the Postgresql bit will change as mentioned in the previous comment...

The error:

src/coffees/coffees.service.ts:20:56 - error TS2559: Type 'string' has no properties in common with type 'FindOneOptions<Coffee>'.

20     const coffee = await this.coffeeRepository.findOne(id);

I faced this today and wasn't a huge deal to fix, nevertheless I lost my focus on the course to find out the reason... not sure if this affects the rest of the samples from the course but this is the way I did it:

  1. changed the id parameters type from string to number from my coffee.controller.ts and coffee.service.ts
  2. In the coffee.service.ts::CoffeesService.findOne() I changed the use of
    findOne(id); to findOneBy({id});
    The resulting function was
  async findOne(id: number) {
    const coffee = await this.coffeeRepository.findOneBy({id});
  ... snip snip ...
  }

after that I just checked again the console and everything was working as expected again :)
BTW, nice course I love it !!!

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

No branches or pull requests

3 participants