Permalink
Browse files

* Add instances to Val to enable conversions to/from ByteString and […

…Word8]. Reliability to be tested.
  • Loading branch information...
1 parent 92bad96 commit 7f00b9701543d9a523075473aa45bfc798553b1d @ozataman committed Dec 8, 2010
Showing with 25 additions and 7 deletions.
  1. +2 −6 README.md
  2. +2 −1 snap-extension-mongodb.cabal
  3. +21 −0 src/Snap/Extension/MongoDB.hs
View
@@ -1,14 +1,10 @@
-README
-======
-
-
Snap Extension for MongoDB
---------------------------
+==========================
This package provides a straightforward way to integrate MongoDB database
connectivity into Snap applications.
-This is a very crude initial realease, to be refined on an ongoing basis. The
+This is a very crude initial realease to be refined on an ongoing basis. The
API may change, so please use at your own risk for the time being.
@@ -1,5 +1,5 @@
Name: snap-extension-mongodb
-Version: 0.1
+Version: 0.1.1
Synopsis: MongoDB extension for Snap Framework
Homepage: https://github.com/ozataman/snap-extension-mongodb
License: BSD3
@@ -32,3 +32,4 @@ Library
, Rank2Types
, MultiParamTypeClasses
, UndecidableInstances
+ , FlexibleInstances
@@ -22,6 +22,11 @@ module Snap.Extension.MongoDB
import Control.Monad.Trans
import Control.Monad.Reader
+import Data.ByteString.Internal (c2w, w2c)
+import qualified Data.ByteString as B
+import qualified Data.ByteString.Char8 as B8
+import Data.Word (Word8)
+
import Database.MongoDB
import Snap.Types
@@ -34,3 +39,19 @@ class MonadSnap m => MonadMongoDB m where
----------------------------------------------------------------------------
-- |
withDB :: ReaderT Database (Action m) a -> m (Either Failure a)
+
+
+------------------------------------------------------------------------------
+-- | Get strict ByteString to work directly with BSON auto-casting
+instance Val B8.ByteString where
+ val = val . B8.unpack
+ cast' x = fmap B8.pack . cast' $ x
+ cast' _ = Nothing
+
+
+------------------------------------------------------------------------------
+-- | Get [Octet] to work directly with BSON auto-casting
+instance Val [Word8] where
+ val = val . fmap w2c
+ cast' x = fmap (fmap c2w) . cast' $ x
+ cast' _ = Nothing

0 comments on commit 7f00b97

Please sign in to comment.