我有这个片段描述Notification
和Notified
实体:
Notification
type NotiType
release ReleaseId
date UTCTime
Notified
aboutWhat NotificationId
unread Bool
user UserId
现在我想写这个:
-- | Mark specified notification as already seen by specific user. Note that
-- we use 'ReleaseId' to select notification, so this may result in several
-- notifications marked as “read” if they happen to be about the same
-- release. This is generally what you want.
markAsRead
:: ReleaseId -- ^ Release in question
-> UserId -- ^ User who has seen mentioned release
-> SqlPersistM ()
markAsRead release user = do
ns <- selectKeysList [ NotificationRelease ==. release ] []
updateWhere [ NotifiedAboutWhat <-. ns
, NotifiedUnread ==. True
, NotifiedUser ==. user ]
[ NotifiedUnread =. False ]
这可行,但是将通知列表提取为列表,然后使用它来选择另一个表中的内容……这并不完全正确。显然我需要在这里加入,然后我将能够有效地更新所有内容。
如何在纯中做到这一点persistent
?是否有可能,在这种情况下继续persistent
执行此类任务是否是个好主意?我应该esqueleto
改用吗?看来我需要学习不同的 DSL 才能使用它,所以我不确定是否要切换。
如何markAsRead
正确书写persistent
(如果可能)?