【问题标题】:Postgres to TypeORMPostgres 到 TypeORM
【发布时间】:2021-04-16 03:38:46
【问题描述】:

任何人都可以为以下查询提供 TypeORM 解决方案,

select upr.active, pr.preference from user_preferences upr
left join preferences pr
on upr.preferenceid = pr.id
where upr.userid = 1

输出是,

active  preference
TRUE    update
TRUE    insert

我的 TypeORM 存储库名称是 preferenceRepo、userPreferenceRepo

谢谢。

【问题讨论】:

  • 你自己试过什么?

标签: node.js postgresql nestjs typeorm


【解决方案1】:

你只需要这样做:

return  this.userPreferenceRepo.createQueryBuilder('upr') 
    .leftJoin("upr.preferenceid", "pr") // replace preferenceid with the name of the colmun that relate user and Preference entity 
   .select(["upr.active","pr.preference"])
   .where("upr.userid = :id ", { id: id }) 
   .getRawMany();

【讨论】:

  • 不错。是的,它工作正常。非常感谢你 ! - @Youba
猜你喜欢
  • 2021-04-18
  • 2021-09-04
  • 2021-05-23
  • 2017-12-11
  • 1970-01-01
  • 2019-12-27
  • 2021-07-21
  • 2020-01-03
  • 1970-01-01
相关资源
最近更新 更多