Write initial main view query with Esqueleto

This commit is contained in:
fr33domlover 2016-02-11 20:58:40 +00:00
parent 5734e720ad
commit 552b17e219
2 changed files with 26 additions and 5 deletions

View file

@ -30,10 +30,13 @@ where
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
import Data.Text (Text) import Data.Text (Text)
import Database.Persist import Database.Esqueleto ((^.), (&&.), (==.))
import Database.Persist.Sqlite --import Database.Persist hiding ((==.))
import Database.Persist.Sqlite hiding ((==.))
import Database.Persist.TH import Database.Persist.TH
import qualified Database.Esqueleto as E
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
IrcChannel IrcChannel
@ -67,12 +70,12 @@ Project
UniqueProject ident sharer UniqueProject ident sharer
Repo Repo
name Text --CI ident Text --CI
project ProjectId project ProjectId
irc IrcChannelId Maybe irc IrcChannelId Maybe
ml Text Maybe ml Text Maybe
UniqueRepo name project UniqueRepo ident project
PersonInGroup PersonInGroup
person PersonId 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

View file

@ -38,6 +38,7 @@ library
, base >=4.8 && <5 , base >=4.8 && <5
, case-insensitive >=1 , case-insensitive >=1
, directory-tree >=0.12 , directory-tree >=0.12
, esqueleto
, filepath , filepath
, hit >=0.6.3 , hit >=0.6.3
, json-state , json-state