____ ____ ___ _____ _____ ___ ____
| \ | \ / _]/ ___// ___/ / \ | \
| o )| D ) / [_( \_( \_ | || _ |
| || / | _]\__ |\__ || O || | |
| O || \ | [_ / \ |/ \ || || | |
| || . \| |\ |\ || || | |
|_____||__|\_||_____| \___| \___| \___/ |__|__|
bresson
is an implementation of BSON bson, a binary format for storing
objects, used by MongoDB mongodb.
Why is bresson
better than the official [bson-haskell
] bson-haskell
driver? Here's why:
- Stores document in a hash table, instead of a list, which obviously improves lookup time for large documents.
- Uses [
text
] text for string-like data, instead of an unsupported [compact-string
] ustring. - Provides separate classes
ToBson
andFromBson
, instead of a singleVal
class. - Well tested () and community maintained!
If you ever used [bson-haskell
] bson-haskell, the API should look
familiar, except for the !?
operator, which allows retrieving nested
labels:
{-# LANGUAGE OverloadedStrings #-}
import Data.Binary (encode, decode)
import Data.Bson (Document, document, (=:), (!?))
import qualified Data.ByteString.Lazy as L
buffer :: L.ByteString
buffer = encode $ document [ "foo" =: "bar"
, "bar" =: document [ "boo" =: 42 ]
]
doc :: Document
doc = decode buffer
value :: Int
value = doc !? "foo.bar.boo" -- ==> 42
Documentation for latest successful build is available [here] docs. Stable documentation will be available as soon as first stable version will be released.
There are two benchmarks currently:
fromBson . toBson
benchmarks on various types, [latest build] benchmarkencode . decode
benchmark against [bson
] bson-hackage library, [latest build] benchmark-against-bson