mongo.hs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env stack
  2. -- stack --resolver lts-9.21 script
  3. {-# LANGUAGE EmptyDataDecls #-}
  4. {-# LANGUAGE FlexibleContexts #-}
  5. {-# LANGUAGE GADTs #-}
  6. {-# LANGUAGE GeneralizedNewtypeDeriving #-}
  7. {-# LANGUAGE MultiParamTypeClasses #-}
  8. {-# LANGUAGE OverloadedStrings #-}
  9. {-# LANGUAGE QuasiQuotes #-}
  10. {-# LANGUAGE TemplateHaskell #-}
  11. {-# LANGUAGE TypeFamilies #-}
  12. import Control.Monad.Logger (runStdoutLoggingT)
  13. import Control.Monad.IO.Class (liftIO)
  14. import Database.Persist
  15. import Database.Persist.MongoDB
  16. import Database.Persist.TH
  17. import Control.Monad.Reader
  18. import Language.Haskell.TH.Syntax
  19. let mongoSettings = (mkPersistSettings (ConT ''MongoContext))
  20. in share [mkPersist mongoSettings]
  21. [persistUpperCase|
  22. Person
  23. name String
  24. age Int Maybe
  25. deriving Show Eq
  26. BlogPost
  27. title String
  28. authorId PersonId
  29. deriving Show Eq
  30. |]
  31. main :: IO ()
  32. main = withMongoPool (defaultMongoConf "persistent") $ runMongoDBPool master $ do
  33. johnId <- insert $ Person "John Doe" $ Just 35
  34. delete johnId