Snap Framework support for MongoDB as Snaplet

Depends on Snap 0.7.* and <others>

Based on work of Massive Tactical

Their MongoDB helper package ( mostly used with Yesod ) is there:

Usage ( assuming you've used snap init to layout your app ):

In Application.hs:
import Snap.Snaplet.MongoDB

then add mongoDB snaplet to App state:
data App = App
    { _heist :: Snaplet (Heist App)
    , _mongoDB :: Snaplet MongoDBSnaplet

then make App an instance of HasMongoDBState:
instance HasMongoDBState App where
  getMongoDBState = with mongoDB Snap.get
  setMongoDBState s = undefined -- with mongo $ puts s

next in Site.hs ( in app = ...):
m <- nestSnaplet "mongoDB" mongoDB $ mongoDBInit (host "localhost") 12 "my_db"
and don't forget to pass this "m" to your App data constructor..

... and voila!

Now you've got "withDB" function which "lifts" your Handler Monad
so You can use db functions ( as described at mt-mongodb pages ).

some_handler :: Handler App App ()
some_handler = do
  ret <- withDB $ select [mongo| {} |][limit 10]
  case ret of
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.