-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | BSON documents are JSON-like objects with a standard binary encoding. -- -- A BSON Document is an untyped (dynamically type-checked) record. I.e. -- it is a list of name-value pairs, where a Value is a single sum type -- with constructors for basic types (Bool, Int, Float, String, and -- Time), compound types (List, and (embedded) Document), and special -- types (Binary, Javascript, ObjectId, RegEx, and a few others). A BSON -- Document is serialized to a standard binary encoding defined at -- http://bsonspec.org. This implements version 1 of that spec. @package bson @version 0.3 -- | 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 module Data.Bson -- | A BSON document is a list of Fields type Document = [Field] -- | Recursively lookup a nested field in a Document. (!?) :: Val a => Document -> Label -> Maybe a -- | Value of field in document, or fail (Nothing) if field not found look :: Monad m => Label -> Document -> m Value -- | Lookup value of field in document and cast to expected type. Fail -- (Nothing) if field not found or value not of expected type. lookup :: (Val v, Monad m) => Label -> Document -> m v -- | Value of field in document. Error if missing. valueAt :: Label -> Document -> Value -- | Typed value of field in document. Error if missing or wrong type. at :: Val v => Label -> Document -> v -- | Only include fields of document in label list include :: [Label] -> Document -> Document -- | Exclude fields from document in label list exclude :: [Label] -> Document -> Document -- | 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. merge :: Document -> Document -> Document -- | A BSON field is a named value, where the name (label) is a string and -- the value is a BSON Value data Field (:=) :: !Label -> Value -> Field label :: Field -> !Label value :: Field -> Value -- | Field with given label and typed value (=:) :: Val v => Label -> v -> Field -- | If Just value then return one field document, otherwise return empty -- document (=?) :: Val a => Label -> Maybe a -> Document -- | The name of a BSON field type Label = Text -- | A BSON value is one of the following types of values data Value Float :: Double -> Value String :: Text -> Value Doc :: Document -> Value Array :: [Value] -> Value Bin :: Binary -> Value Fun :: Function -> Value Uuid :: UUID -> Value Md5 :: MD5 -> Value UserDef :: UserDefined -> Value ObjId :: ObjectId -> Value Bool :: Bool -> Value UTC :: UTCTime -> Value Null :: Value RegEx :: Regex -> Value JavaScr :: Javascript -> Value Sym :: Symbol -> Value Int32 :: Int32 -> Value Int64 :: Int64 -> Value Stamp :: MongoStamp -> Value MinMax :: MinMaxKey -> Value -- | Haskell types of this class correspond to BSON value types class (Typeable a, Show a, Eq a) => Val a where valList = Array . map val valMaybe = maybe Null val cast'List (Array x) = mapM cast x cast'List _ = Nothing cast'Maybe Null = Just Nothing cast'Maybe v = fmap Just (cast' v) val :: Val a => a -> Value valList :: Val a => [a] -> Value valMaybe :: Val a => Maybe a -> Value cast' :: Val a => Value -> Maybe a cast'List :: Val a => Value -> Maybe [a] cast'Maybe :: Val a => Value -> Maybe (Maybe a) -- | Apply generic function to typed value fval :: (forall a. Val a => a -> b) -> Value -> b -- | Convert Value to expected type, or fail (Nothing) if not of that type cast :: (Val a, Monad m) => Value -> m a -- | Convert Value to expected type. Error if not that type. typed :: Val a => Value -> a -- | Type of typed value typeOfVal :: Value -> TypeRep newtype Binary Binary :: ByteString -> Binary newtype Function Function :: ByteString -> Function newtype UUID UUID :: ByteString -> UUID newtype MD5 MD5 :: ByteString -> MD5 newtype UserDefined UserDefined :: ByteString -> UserDefined -- | 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 Regex Regex :: Text -> Text -> Regex -- | Javascript code with possibly empty environment mapping variables to -- values that the code may reference data Javascript Javascript :: Document -> Text -> Javascript newtype Symbol Symbol :: Text -> Symbol newtype MongoStamp MongoStamp :: Int64 -> MongoStamp data MinMaxKey MinKey :: MinMaxKey MaxKey :: MinMaxKey -- | 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. data ObjectId Oid :: Word32 -> Word64 -> ObjectId -- | Time when objectId was created timestamp :: ObjectId -> UTCTime -- | Create a fresh ObjectId genObjectId :: IO ObjectId instance Typeable Binary instance Typeable Function instance Typeable UUID instance Typeable MD5 instance Typeable UserDefined instance Typeable Regex instance Typeable Symbol instance Typeable MongoStamp instance Typeable MinMaxKey instance Typeable ObjectId instance Typeable Value instance Typeable Javascript instance Typeable Field instance Show Binary instance Read Binary instance Eq Binary instance Ord Binary instance Show Function instance Read Function instance Eq Function instance Ord Function instance Show UUID instance Read UUID instance Eq UUID instance Ord UUID instance Show MD5 instance Read MD5 instance Eq MD5 instance Ord MD5 instance Show UserDefined instance Read UserDefined instance Eq UserDefined instance Ord UserDefined instance Show Regex instance Read Regex instance Eq Regex instance Ord Regex instance Show Symbol instance Read Symbol instance Eq Symbol instance Ord Symbol instance Show MongoStamp instance Read MongoStamp instance Eq MongoStamp instance Ord MongoStamp instance Show MinMaxKey instance Read MinMaxKey instance Eq MinMaxKey instance Ord MinMaxKey instance Eq ObjectId instance Ord ObjectId instance Eq Value instance Ord Value instance Show Javascript instance Eq Javascript instance Ord Javascript instance Eq Field instance Ord Field instance Read ObjectId instance Show ObjectId instance Val MinMaxKey instance Val MongoStamp instance Val Integer instance Val Int instance Val Int64 instance Val Int32 instance Val Symbol instance Val Javascript instance Val Regex instance Val a => Val (Maybe a) instance Val POSIXTime instance Val UTCTime instance Val Bool instance Val ObjectId instance Val UserDefined instance Val MD5 instance Val UUID instance Val Function instance Val Binary instance Val a => Val [a] instance Val Value instance Val Field instance Val Char instance Val Text instance Val Float instance Val Double instance Show Value instance Show Field -- | Standard binary encoding of BSON documents, version 1.0. See -- bsonspec.org module Data.Bson.Binary putDocument :: Document -> Put getDocument :: Get Document putDouble :: Double -> Put getDouble :: Get Double putInt32 :: Int32 -> Put getInt32 :: Get Int32 putInt64 :: Int64 -> Put getInt64 :: Get Int64 putCString :: Text -> Put getCString :: Get Text