From 552b17e219aafbd0c158b6c6a2728c46aa92c1de Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Thu, 11 Feb 2016 20:58:40 +0000 Subject: [PATCH] Write initial main view query with Esqueleto --- src/Vervis/Persist.hs | 30 +++++++++++++++++++++++++----- vervis.cabal | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Vervis/Persist.hs b/src/Vervis/Persist.hs index 39b0e0c..11c89bb 100644 --- a/src/Vervis/Persist.hs +++ b/src/Vervis/Persist.hs @@ -30,10 +30,13 @@ where import Control.Monad.IO.Class (liftIO) import Data.Text (Text) -import Database.Persist -import Database.Persist.Sqlite +import Database.Esqueleto ((^.), (&&.), (==.)) +--import Database.Persist hiding ((==.)) +import Database.Persist.Sqlite hiding ((==.)) import Database.Persist.TH +import qualified Database.Esqueleto as E + share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| IrcChannel @@ -67,12 +70,12 @@ Project UniqueProject ident sharer Repo - name Text --CI + ident Text --CI project ProjectId irc IrcChannelId Maybe ml Text Maybe - UniqueRepo name project + UniqueRepo ident project PersonInGroup person PersonId @@ -82,4 +85,21 @@ PersonInGroup |] ---mainViewQuery = --TODO +mainViewQuery :: IO () +mainViewQuery = runSqlite ":memory:" $ do + runMigration migrateAll + rows <- E.select $ E.from $ \ (sharer, project, repo) -> do + E.where_ $ + project ^. ProjectSharer ==. sharer ^. SharerId &&. + repo ^. RepoProject ==. project ^. ProjectId + E.orderBy + [ E.asc $ sharer ^. SharerIdent + , E.asc $ project ^. ProjectIdent + , E.asc $ repo ^. RepoIdent + ] + return + ( sharer ^. SharerIdent + , project ^. ProjectIdent + , repo ^. RepoIdent + ) + liftIO $ mapM_ print rows diff --git a/vervis.cabal b/vervis.cabal index 6d1c575..509f3e0 100644 --- a/vervis.cabal +++ b/vervis.cabal @@ -38,6 +38,7 @@ library , base >=4.8 && <5 , case-insensitive >=1 , directory-tree >=0.12 + , esqueleto , filepath , hit >=0.6.3 , json-state