0

我有这个原始 sql 我想转换为 Esqueleto。它应该带来group用户 ID 1 未通过group_membership表注册的所有 s。

SELECT * 
FROM group
LEFT OUTER JOIN group_membership
  ON (group.id = group_membership.group_id AND group_membership.user_id=1)
  WHERE group_membership.group_id IS NULL
4

1 回答 1

0

这是我从不同问题中收集到的答案:

getGroups userId = do
    runDB
        . E.select
        . E.from $ \(group `E.LeftOuterJoin` groupMembership) -> do
            E.on $ E.just (group ^. GroupId) E.==. (groupMembership ?. GroupMembershipGroupId) &&.
                   (groupMembership ?. GroupMembershipUserId) E.==. E.just (E.val userId)
            E.where_ $ E.isNothing (groupMembership ?. GroupMembershipGroupId)
            return
              ( group ^. GroupId
              , group ^. GroupTitle
              )
于 2016-08-13T20:26:44.577 回答