简体   繁体   English

Esqueleto内部选择计数

[英]Esqueleto count inside select

I have the following Entities : 我有以下Entities

Group
  name Text

GroupUser
  user UserId
  group GroupId

and I would like to do a query like this: 我想做这样的查询:

select g.* /* Everything from g */
     , count(gu.id) groupUsersCount 
  from Group g
  left outer join GroupUser gu on gu.groupId = g.id
group by g.id

Can it be done with Esqueleto ? 可以用Esqueleto完成吗?

The esqueleto docs for groupBy contain good examples of how to use it. 用于esqueleto文档groupBy包含如何使用它很好的例子。

Moreover, by reading through the Getting Started section, you'll see several example of queries including the equivalent of table.* : 此外,通过阅读“ 入门”部分,您将看到几个查询示例,包括等同于table.*的查询:

do people <- select $
             from $ \person -> do
             return person

Putting the two together means something like this should work: 将两者放在一起意味着这样的事情应该起作用:

select $ from \(g `LeftOuterJoin` gh) -> do
  on (gu ^. GroupId ==. g ^. Id)
  groupBy (g ^. Id)
  return (g, countRows)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM