souplesse

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 1bb2fe921883ef1670963acca84c0a3b825e692a
parent e58b250024aed23d725dcc75e0fcfe42bb15d154
Author: Daniel Barlow <dan@telent.net>
Date:   Mon, 11 Nov 2024 18:43:16 +0000

add Session.refreshDrafts

hides some gnarly raw sql inside the module

Diffstat:
Mlib/Session.hs | 11++++++++---
Mlib/Store.hs | 2+-
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/Session.hs b/lib/Session.hs @@ -16,7 +16,7 @@ module Session ( Session (..), recents, - updateSessions, + refreshDrafts, migrateSession, ) where @@ -31,6 +31,7 @@ import Database.Persist import Database.Persist.Postgresql ( PgInterval, SqlBackend, + rawExecute ) import Database.Persist.TH import Text.RawString.QQ (r) @@ -45,8 +46,8 @@ Session notes String Maybe |] -updateSessions :: Text -updateSessions = +updateSql :: Text +updateSql = [r| -- delete existing drafts as new data may extend one of them delete from session where draft; @@ -62,6 +63,10 @@ insert into session(start_time, duration, draft) (select time as start_time, mak where draft; |] +refreshDrafts :: (MonadIO m) => ReaderT SqlBackend m () +refreshDrafts = + rawExecute updateSql [] + recents :: (MonadIO m) => ReaderT SqlBackend m [Session] recents = do s <- selectList [SessionDraft !=. True] [Desc SessionStartTime, LimitTo 10] diff --git a/lib/Store.hs b/lib/Store.hs @@ -89,7 +89,7 @@ save track = do then return $ Left (OverlapExists "track overlaps with existing data") else do mapM_ (insert . fromPoint) track - rawExecute Session.updateSessions [] + Session.refreshDrafts return $ Right track fetch :: (MonadIO m) => UTCTime -> NominalDiffTime -> ReaderT SqlBackend m [Point]