Safe Haskell | None |
---|
A BSON document is a JSON-like object with a standard binary encoding defined at bsonspec.org. This implements version 1.0 of that spec.
Use the GHC language extension OverloadedStrings to automatically convert String literals to Text
- type Document = [Field]
- (!?) :: Val a => Document -> Label -> Maybe a
- look :: Monad m => Label -> Document -> m Value
- lookup :: (Val v, Monad m) => Label -> Document -> m v
- valueAt :: Label -> Document -> Value
- at :: Val v => Label -> Document -> v
- include :: [Label] -> Document -> Document
- exclude :: [Label] -> Document -> Document
- merge :: Document -> Document -> Document
- data Field = := {}
- (=:) :: Val v => Label -> v -> Field
- (=?) :: Val a => Label -> Maybe a -> Document
- type Label = Text
- data Value
- class (Typeable a, Show a, Eq a) => Val a where
- fval :: (forall a. Val a => a -> b) -> Value -> b
- cast :: (Val a, Monad m) => Value -> m a
- typed :: Val a => Value -> a
- typeOfVal :: Value -> TypeRep
- newtype Binary = Binary ByteString
- newtype Function = Function ByteString
- newtype UUID = UUID ByteString
- newtype MD5 = MD5 ByteString
- newtype UserDefined = UserDefined ByteString
- data Regex = Regex Text Text
- data Javascript = Javascript Document Text
- newtype Symbol = Symbol Text
- newtype MongoStamp = MongoStamp Int64
- data MinMaxKey
- data ObjectId = Oid Word32 Word64
- timestamp :: ObjectId -> UTCTime
- genObjectId :: IO ObjectId
- showHexLen :: (Show n, Integral n) => Int -> n -> ShowS
Document
look :: Monad m => Label -> Document -> m ValueSource
Value of field in document, or fail (Nothing) if field not found
lookup :: (Val v, Monad m) => Label -> Document -> m vSource
Lookup value of field in document and cast to expected type. Fail (Nothing) if field not found or value not of expected type.
at :: Val v => Label -> Document -> vSource
Typed value of field in document. Error if missing or wrong type.
merge :: Document -> Document -> DocumentSource
Merge documents with preference given to first one when both have the same label. I.e. for every (k := v) in first argument, if k exists in second argument then replace its value with v, otherwise add (k := v) to second argument.
Field
A BSON field is a named value, where the name (label) is a string and the value is a BSON Value
(=?) :: Val a => Label -> Maybe a -> DocumentSource
If Just value then return one field document, otherwise return empty document
Value
A BSON value is one of the following types of values
class (Typeable a, Show a, Eq a) => Val a whereSource
Haskell types of this class correspond to BSON value types
valMaybe :: Maybe a -> ValueSource
cast' :: Value -> Maybe aSource
cast'List :: Value -> Maybe [a]Source
cast'Maybe :: Value -> Maybe (Maybe a)Source
Val Bool | |
Val Char | |
Val Double | |
Val Float | |
Val Int | |
Val Int32 | |
Val Int64 | |
Val Integer | |
Val Text | |
Val POSIXTime | |
Val UTCTime | |
Val ObjectId | |
Val MinMaxKey | |
Val MongoStamp | |
Val Symbol | |
Val Javascript | |
Val Regex | |
Val UserDefined | |
Val MD5 | |
Val UUID | |
Val Function | |
Val Binary | |
Val Value | |
Val Field | |
Val a => Val [a] | |
Val a => Val (Maybe a) |
cast :: (Val a, Monad m) => Value -> m aSource
Convert Value to expected type, or fail (Nothing) if not of that type
Special Bson value types
newtype UserDefined Source
The first string is the regex pattern, the second is the regex options string. Options are identified by characters, which must be listed in alphabetical order. Valid options are *i* for case insensitive matching, *m* for multiline matching, *x* for verbose mode, *l* to make \w, \W, etc. locale dependent, *s* for dotall mode ("." matches everything), and *u* to make \w, \W, etc. match unicode.
data Javascript Source
Javascript code with possibly empty environment mapping variables to values that the code may reference
newtype MongoStamp Source
ObjectId
A BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields must be stored big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure a mostly increasing order.
genObjectId :: IO ObjectIdSource
Create a fresh ObjectId