我有这个原始 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
这是我从不同问题中收集到的答案:
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
)