Как добавить mongodb в приложение Snap?

Учитывая это:

main :: IO ()
main = do
    (conf, site, cleanup) <- $(loadSnapTH [| getConf |]
                                          'getActions
                                          ["snaplets/heist/templates"])


    _ <- try $ httpServe conf site :: IO (Either SomeException ())
    cleanup


------------------------------------------------------------------------------
-- | This action loads the config used by this application. The loaded config
-- is returned as the first element of the tuple produced by the loadSnapTH
-- Splice. The type is not solidly fixed, though it must be an IO action that
-- produces the same type as 'getActions' takes. It also must be an instance of
-- Typeable. If the type of this is changed, a full recompile will be needed to
-- pick up the change, even in development mode.
--
-- This action is only run once, regardless of whether development or
-- production mode is in use.
getConf :: IO (Config Snap AppConfig)
getConf = commandLineConfig defaultConfig


------------------------------------------------------------------------------
-- | This function generates the the site handler and cleanup action from the
-- configuration. In production mode, this action is only run once. In
-- development mode, this action is run whenever the application is reloaded.
--
-- Development mode also makes sure that the cleanup actions are run
-- appropriately before shutdown. The cleanup action returned from loadSnapTH
-- should still be used after the server has stopped handling requests, as the
-- cleanup actions are only automatically run when a reload is triggered.
--
-- This sample doesn't actually use the config passed in, but more
-- sophisticated code might.
getActions :: Config Snap AppConfig -> IO (Snap (), IO ())
getActions conf = do
    (msgs, site, cleanup) <- runSnaplet
        (appEnvironment =<< getOther conf) app
    hPutStrLn stderr $ T.unpack msgs
    return (site, cleanup)

с чего мне вообще начать, если я хочу добавить функциональность базы данных mongodb (здесь хороший пример)???

У Snap всего два примера:

  1. Один очень простой (здесь бесполезен): http://snapframework.com/docs/tutorials/snap-api
  2. И тот, что выше, который генерируется с помощью snap (я уже забыл, как я его сгенерировал, и, кажется, не могу найти его в документах?)

person Andriy Drozdyuk    schedule 03.08.2012    source источник


Ответы (1)


Вы можете использовать пакет snaplet-mongodb-minimalistic и есть использование пример на github.

person Fedor Gogolev    schedule 03.08.2012
comment
Огромное спасибо! Кстати, вот исправление для примера, чтобы он работал с snap 0.9 (если кому интересно): github.com/Palmik/snaplet-mongodb-minimalistic/pull/7 - person Andriy Drozdyuk; 17.08.2012