Search code examples
javascriptpostgresqlnestjsethereumtypeorm

Don`t insert at postgreSQL


I have a problem. I'm trying insert value on table, but he don't insert

    const oldBlockNumber = await this.walletForCheckRepository.createQueryBuilder().getOne();
    await this.walletForCheckRepository
    .createQueryBuilder()
      .update()
      .set({ block_number: newBlockNumber })
      .where('block_number =:block_number', { block_number: oldBlockNumber })
      .execute();
  }

And I have error

TypeError: Cannot read property 'block_number' of undefined

I use postgreSQL, NestJS, typeorm


Solution

  • You need to pass the TypeORM model to the update() function. See the documentation for more info.

    So if your model containing the property block_number is named MyModel, your code is going to be

    .update(MyModel)
    

    instead of

    .update()