diff options
| author | Joris | 2017-11-28 09:11:19 +0100 | 
|---|---|---|
| committer | Joris | 2017-11-28 09:11:19 +0100 | 
| commit | 49426740e8e0c59040f4f3721a658f225572582b (patch) | |
| tree | 43e3cf19f35d672734a92648b0038bf48dace778 /server/src/Job/Model.hs | |
| parent | 554880727d833befab00666c7a4f95611e8370b9 (diff) | |
Add search for payments
Diffstat (limited to 'server/src/Job/Model.hs')
| -rw-r--r-- | server/src/Job/Model.hs | 14 | 
1 files changed, 9 insertions, 5 deletions
| diff --git a/server/src/Job/Model.hs b/server/src/Job/Model.hs index a5fa62b..1dd6c63 100644 --- a/server/src/Job/Model.hs +++ b/server/src/Job/Model.hs @@ -5,7 +5,6 @@ module Job.Model    , actualizeLastCheck    ) where -import           Data.Maybe             (isJust)  import           Data.Time.Clock        (UTCTime, getCurrentTime)  import           Database.SQLite.Simple (Only (Only))  import qualified Database.SQLite.Simple as SQLite @@ -24,15 +23,20 @@ data Job = Job  getLastExecution :: Kind -> Query (Maybe UTCTime)  getLastExecution jobKind =    Query (\conn -> do -    [Only time] <- SQLite.query conn "SELECT last_execution FROM job WHERE kind = ?" (Only jobKind) :: IO [Only (Maybe UTCTime)] -    return time +    result <- SQLite.query conn "SELECT last_execution FROM job WHERE kind = ?" (Only jobKind) :: IO [Only UTCTime] +    return $ case result of +      [Only time] -> Just time +      _           -> Nothing    )  actualizeLastExecution :: Kind -> UTCTime -> Query ()  actualizeLastExecution jobKind time =    Query (\conn -> do -    [Only result] <- SQLite.query conn "SELECT 1 FROM job WHERE kind = ?" (Only jobKind) :: IO [Only (Maybe Int)] -    if isJust result +    result <- SQLite.query conn "SELECT 1 FROM job WHERE kind = ?" (Only jobKind) :: IO [Only Int] +    let hasJob = case result of +         [Only _] -> True +         _        -> False +    if hasJob        then SQLite.execute conn "UPDATE job SET last_execution = ? WHERE kind = ?" (time, jobKind)        else SQLite.execute conn "INSERT INTO job (kind, last_execution, last_check) VALUES (?, ?, ?)" (jobKind, time, time)    ) | 
