Search code examples
sqltypescriptpostgresqltypeorm

Why is query builder passing wrong parameters in my query?


I am running following query using query buider

when I print the query 2nd place parmeter is being passed where 1st paramerter should be passed please anyone can explain what am I doing wrong here?

const queryRunner: QueryRunner = getConnection().createQueryRunner();

  await queryRunner.startTransaction();

  try {
    //other queries here deleted for simplicity
    await queryRunner.manager
      .getRepository(User)
      .createQueryBuilder()
      .update(User)
      .set({ status: UserStatus.INACTIVE }) // UserStatus is enum
      .where("organizationId IN(:...ids)", { ids: organizations })
      .printSql()
      .execute();

    await queryRunner.commitTransaction();
  } catch (err) {
    await queryRunner.rollbackTransaction();
    console.log("=====Rollback=====");
  } finally {
    await queryRunner.release();
  }

output:

UPDATE "users" SET "status" = $2 WHERE "organizationId" IN($2, $3, $4, $5) -- PARAMETERS: ["INACTIVE",32,36,35,34]


Solution

  • So I found the real issue was not with the code I wrote but rather it was a bug in typeorm version 0.2.25 and it is fixed in the latest release of the library.

    For detailed overview see here: Github issues.

    Thank you.