{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TypeApplications #-} module Membership where import Database.SQLite.Simple (Connection, Only (..)) import Network.Reddit (RedditId) import qualified Database.SQLite.Simple as SQL import Database.SQLite.Simple.QQ (sql) import qualified Data.Foldable as F import Data.Monoid (Any(..)) import Data.Text (Text) recordSeen :: Connection -> RedditId -> IO () recordSeen conn rid = SQL.execute conn [sql|insert into membership (reddit_id) values (?) on conflict do nothing|] (Only rid) isSeen :: Connection -> RedditId -> IO Bool isSeen conn rid = unwrap <$> SQL.query conn [sql|select reddit_id from membership where reddit_id = ?|] (Only rid) where unwrap = getAny . F.foldMap' (Any . const @_ @Text True . fromOnly)