about summary refs log tree commit diff
path: root/users/wpcarro/assessments/tt/src/Invitations.hs
blob: 0c700470f3e2c8f98630f9b9049f137eee006c08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
--------------------------------------------------------------------------------
module Invitations where
--------------------------------------------------------------------------------
import Database.SQLite.Simple

import qualified Types as T
--------------------------------------------------------------------------------

create :: FilePath -> T.InvitationSecret -> T.Email -> T.Role -> IO ()
create dbFile secret email role = withConnection dbFile $ \conn -> do
  execute conn "INSERT INTO Invitations (email,role,secret) VALUES (?,?,?)"
    (email, role, secret)

get :: FilePath -> T.Email -> IO (Maybe T.Invitation)
get dbFile email = withConnection dbFile $ \conn -> do
  res <- query conn "SELECT email,role,secret FROM Invitations WHERE email = ?" (Only email)
  case res of
    [x] -> pure (Just x)
    _ -> pure Nothing