On Fri, Dec 03, 2010 at 07:19:16AM -0500, MightyByte wrote:
> First of all, if you haven't already done so I would recommend
> checking out the snap-website package on github [0]. That provides an
> example of how we've used Snap and Heist on a real site. It doesn't
> use a database, but it should give you some semblance of a starting
> point.
>
> I should interject here that some of the more generic boilerplate code
> you see there (and in the template created by snap init) will be
> merged into Snap in the future, so you won't always have to carry that
> along with your app.
Cool. This was a problem for me when I was a Rails user, staying
up-to-date with the generated files.
> Using monad transformers and your own database will get a lot easier
> in Snap 0.3. It's in development right now and we're planning to
> release it in January. So if your project can tolerate working on a
> development branch I'd suggest getting it from github and basing your
> work around that. (Then you also won't have to worry about migrating
> after we do release.)
>
> If you decide to use 0.3 then I would also suggest using duairc's
> snap-extensions package. It's not on hackage, but you can get it from
> github [1]. It provides some infrastructure for working with Snap 0.3
> This code will be merged into the snap package before the 0.3
> release. Assuming you use snap-0.3 + snap-extensions, here's what
> some of your app might look like.
This looks like a good way to go, thanks! This project is strictly a
hobby, so I don't mind dealing with the development version for the
time being.
> data AppState = AppState {
> dbConnection :: Connection
> }
>
> withDB f = f =<< asks dbConnection
>
> trivialHandler :: SnapExtend AppState
> trivialHandler = do
> num <- withDB (liftIO trivialQuery)
> writeBS $ pack $ show num
>
> I haven't tried to compile this, but it should give you the idea. The
> SnapExtend monad (provided by snap-extensions) is just a reader monad
> that is also an instance of MonadSnap (only available in Snap 0.3).
This looks much cleaner than I was expecting for the amount of
effort. I am glad I asked! Are you planning on integrating
snap-extensions into Snap later on?
I'm currently having trouble building snap-extensions, by the way:
[11 of 12] Compiling Snap.Extension.Server (
src/Snap/Extension/Server.hs, dist/build/Snap/Extension/Server.o )
src/Snap/Extension/Server.hs:135:26: Not in scope: `getAddress'
src/Snap/Extension/Server.hs:136:26: Not in scope: `getPort'
cabal: Error: some packages failed to install:
snap-extensions-0.1 failed during the building phase. The exception was:
ExitFailure 1
Otherwise, I think this is going to go well. Thanks for all your help!
--
Daniel
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap