public
Created

  • Download Gist
mongoApp.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
 
import Yesod
import Database.Persist
import Database.Persist.MongoDB
import Database.MongoDB.Connection (ConnPool)
 
mkPersist [persist|
Person
name String
age Int
|]
 
runMongo :: MongoDBReader t (GGHandler M M IO) a -> GHandler M M a
runMongo x = liftIOHandler $ runMongoDBConn x getConnection
 
getConnection :: (ConnPool t, HostName)
getConnection = undefined
 
someAction :: Monad m => MongoDBReader t m (Key Person)
someAction = insert $ Person "Bob" 20
-- selectList [PersonIdIn [1,2]] [] 0 0
 
data M = M
instance Yesod M where approot _ = ""
 
mkYesod "M" [parseRoutes|/ RootR GET|]
 
getRootR :: GHandler M M RepHtml
getRootR = do
_ <- runMongo someAction
defaultLayout [hamlet|<h1>HELLO WORLD|]
 
main :: IO ()
main = warpDebug 3000 M

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.