[typeOrm]Rawクエリの使用例


1
// already there
 
 querybuilder
  .[...]
  .where('LOWER(users.email) = :email', { email: email.toLowerCase() });

// unsafe via repository, since params are unescaped:
repo.findOne({
  where: {
    email: Raw(alias => `LOWER(${alias}) = '${email.toLowerCase()}'`).
  },
});

// would be nice to have:
repo.findOne({
  where: {
    email: Raw(alias => 'LOWER(${alias}) = :email', { email: email.toLowerCase() }),
  },
});
2
const [result, total] = await this.findAndCount(
    {
  where: { title: Raw(alias => `LOWER(${alias}) Like '%${value}%'`) },

take: take,
  skip: skip
}

);
  return {
    data: result,
    count: total
  }
  • Ilikeよりも、likeを小文字で置き換えると
  • が検索されます.
    ソース
    https://github.com/typeorm/typeorm/issues/1231
    https://github.com/typeorm/typeorm/blob/master/docs/find-options.md
    https://github.com/typeorm/typeorm/issues/4418
    https://github.com/typeorm/typeorm/issues/3329
    https://github.com/typeorm/typeorm/issues/2475