wheb-mongo: MongoDB plugin for Wheb

[ bsd3, database, library ] [ Propose Tags ]

Wheb plugin for MongoDB.

  • Implements SessionBackend and AuthBackend instances using MongoDB and Wheb.

  • Creates simple interface for arbitrary MongoDB actions using Wheb

  • Creates simple interface for arbitrary MongoDB actions using mongoDB

For a complete example, see the examples folder at github

You can override the collection names for the Auth and Session documents by using addSetting and setting keys for "session-collection" and "auth-collection"

opts <- generateOptions $ do
   addSetting "session-collection" "my-collection"

Reimplimentation of official example below. Use with language extensions OvererloadedStrings & ExtendedDefaultRules.

 import qualified Data.Text.Lazy as T

 import           Web.Wheb
 import           Web.Wheb.Plugins.Mongo

 data MyApp = MyApp MongoContainer
 data MyRequestState = MyRequestState

 instance MongoApp MyApp where
     getMongoContainer (MyApp mc) = mc

 homePage :: WhebHandler MyApp MyRequestState
 homePage = do
     teams <- runAction $ rest =<< find (select [] "team")
     text $ T.intercalate " | " $ map spack teams

 main :: IO ()
 main = do
   opts <- generateOptions $ do
     addGET "." rootPat $ homePage
     mongo <- initMongo "127.0.0.1:27017" "master"
     return (MyApp mongo, MyRequestState)

   runRawHandler opts $ do
     runAction $ do
         delete (select [] "team")
         insertMany "team" [
             ["name" =: "Yankees", "home" =: ["city" =: "New York", "state" =: "NY"], "league" =: "American"],
             ["name" =: "Mets", "home" =: ["city" =: "New York", "state" =: "NY"], "league" =: "National"],
             ["name" =: "Phillies", "home" =: ["city" =: "Philadelphia", "state" =: "PA"], "league" =: "National"],
             ["name" =: "Red Sox", "home" =: ["city" =: "Boston", "state" =: "MA"], "league" =: "American"] ]

   runWhebServer opts

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1.0, 0.0.2.0, 0.0.3.0
Dependencies base (>=4.7 && <4.8), bson (>=0.3 && <0.4), mongoDB (>=2.0 && <2.1), mtl (>=2.1 && <2.3), text (>=1.0 && <1.2), Wheb (>=0.3 && <0.4) [details]
License BSD-3-Clause
Author Kyle Hanson
Maintainer hanooter@gmail.com
Category Database
Home page https://github.com/hansonkd/Wheb-Framework
Uploaded by hansonkd at 2014-08-27T04:45:43Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 2368 total (12 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]