Node.js 需要将psql查询转换为typeorm

Node.js 需要将psql查询转换为typeorm,node.js,database,typescript,postgresql,typeorm,Node.js,Database,Typescript,Postgresql,Typeorm,我需要每天/每周/每月获取数据。所以我使用date_trunc函数来获取这种类型的记录。我进行了psql查询,但我需要将其转换为typeorm代码,因为我不熟悉typeorm堆栈。下面是查询 select date_trunc('day', e."createdAt") as production_to_month, count(id) as count from events e where e."createdAt" between '2021-05

我需要每天/每周/每月获取数据。所以我使用date_trunc函数来获取这种类型的记录。我进行了psql查询,但我需要将其转换为typeorm代码,因为我不熟悉typeorm堆栈。下面是查询

select date_trunc('day', e."createdAt") as production_to_month, count(id) as count from events e 
where e."createdAt" between '2021-05-10' and '2021-05-17' and e."type" = 'LOGIN'
group by date_trunc('day', e."createdAt") 
order by date_trunc('day', e."createdAt") asc

需要转换此值

您需要使用查询生成器来实现所需的结果

问题是-

  return await getRepository(Events)
  .createQueryBuilder("e")
  .select("date_trunc('day',`e`.`createdAt`)","production_to_month")
  .addSelect("count(`id`)","count")
  .where("`e`.`createdAt` between '2021-05-10' and '2021-05-17'")
  .andWhere("`e`.`type` = 'LOGIN'")
  .groupBy("date_trunc('day',`e`.`createdAt`)").
  .orderBy("date_trunc('day',`e`.`createdAt`)","ASC")
  .printSql()
  .getRawMany()

您好,Soham使用此查询,我得到了在该日期存在的数据,例如->如果我在2021-05-13没有数据,那么使用上述查询,我没有该日期的行,但我需要计数为0的行。您能帮助我吗this@Rochit你准备好SQL查询了吗?我准备了SQL查询,请将其转换为typeorm查询选择顺序日期。日期,事件。计数从选择日期开始,月份作为日期从生成日期系列'2021-05-03'::日期,'2021-05-31'::日期,'1天'作为月份顺序日期左连接选择日期,事件。创建日期作为日期,countevents.id作为事件组中的计数,按连续日期的日期事件。日期=事件。日期