| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Data.Bson.Mapping
Description
This module aims to make mapping between algebraic data types and bson documents easy.
You can also generate documents with selectFields, which takes a
list of functions names that of type a -> b and returns a function
of type a -> Document.
Example:
import Data.Bson.Mapping
import Data.Time.Clock
import Data.Data (Typeable)
data Post = Post { time :: UTCTime
, author :: String
, content :: String
, votes :: Int
}
deriving (Show, Read, Eq, Ord, Typeable)
$(deriveBson ''Post)
main :: IO ()
main = do
now <- getCurrentTime
let post = Post now "francesco" "lorem ipsum" 5
(fromBson (toBson post) :: IO Post) >>= print
print $ toBson post
print $ $(selectFields ['time, 'content]) postDocumentation
selectFields :: [Name] -> Q Exp Source #
Select only certain fields in a document, see the code sample at the top.
Please note that there is no checking for the names to be actual fields of the bson document mapped to a datatype, so be careful.
getConsDoc :: Name -> Q Exp Source #
Get a document that identifies the data type - getConsDoc ''Post.
This is useful to select all documents mapped to a certain data type.