bson-0.3.2.8: BSON documents are JSON-like objects with a standard binary encoding.

Safe HaskellNone
LanguageHaskell2010

Data.Bson

Contents

Description

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

Synopsis

Document

type Document = [Field] Source #

A BSON document is a list of Fields

(!?) :: Val a => Document -> Label -> Maybe a Source #

Recursively lookup a nested field in a Document.

look :: Monad m => Label -> Document -> m Value Source #

Value of field in document, or fail (Nothing) if field not found

lookup :: (Val v, Monad m) => Label -> Document -> m v Source #

Lookup value of field in document and cast to expected type. Fail (Nothing) if field not found or value not of expected type.

valueAt :: Label -> Document -> Value Source #

Value of field in document. Error if missing.

at :: Val v => Label -> Document -> v Source #

Typed value of field in document. Error if missing or wrong type.

include :: [Label] -> Document -> Document Source #

Only include fields of document in label list

exclude :: [Label] -> Document -> Document Source #

Exclude fields from document in label list

merge :: Document -> Document -> Document Source #

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

data Field Source #

A BSON field is a named value, where the name (label) is a string and the value is a BSON Value

Constructors

(:=) infix 0 

Fields

Instances
Eq Field Source # 
Instance details

Defined in Data.Bson

Methods

(==) :: Field -> Field -> Bool #

(/=) :: Field -> Field -> Bool #

Ord Field Source # 
Instance details

Defined in Data.Bson

Methods

compare :: Field -> Field -> Ordering #

(<) :: Field -> Field -> Bool #

(<=) :: Field -> Field -> Bool #

(>) :: Field -> Field -> Bool #

(>=) :: Field -> Field -> Bool #

max :: Field -> Field -> Field #

min :: Field -> Field -> Field #

Show Field Source # 
Instance details

Defined in Data.Bson

Methods

showsPrec :: Int -> Field -> ShowS #

show :: Field -> String #

showList :: [Field] -> ShowS #

Val Field Source # 
Instance details

Defined in Data.Bson

(=:) :: Val v => Label -> v -> Field infix 0 Source #

Field with given label and typed value

(=?) :: Val a => Label -> Maybe a -> Document infix 0 Source #

If Just value then return one field document, otherwise return empty document

type Label = Text Source #

The name of a BSON field

Value

data Value Source #

A BSON value is one of the following types of values

Instances
Eq Value Source # 
Instance details

Defined in Data.Bson

Methods

(==) :: Value -> Value -> Bool #

(/=) :: Value -> Value -> Bool #

Ord Value Source # 
Instance details

Defined in Data.Bson

Methods

compare :: Value -> Value -> Ordering #

(<) :: Value -> Value -> Bool #

(<=) :: Value -> Value -> Bool #

(>) :: Value -> Value -> Bool #

(>=) :: Value -> Value -> Bool #

max :: Value -> Value -> Value #

min :: Value -> Value -> Value #

Show Value Source # 
Instance details

Defined in Data.Bson

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

Val Value Source # 
Instance details

Defined in Data.Bson

class (Typeable a, Show a, Eq a) => Val a where Source #

Haskell types of this class correspond to BSON value types

Minimal complete definition

val, cast'

Instances
Val Bool Source # 
Instance details

Defined in Data.Bson

Val Char Source # 
Instance details

Defined in Data.Bson

Val Double Source # 
Instance details

Defined in Data.Bson

Val Float Source # 
Instance details

Defined in Data.Bson

Val Int Source # 
Instance details

Defined in Data.Bson

Val Int32 Source # 
Instance details

Defined in Data.Bson

Val Int64 Source # 
Instance details

Defined in Data.Bson

Val Integer Source # 
Instance details

Defined in Data.Bson

Val Text Source # 
Instance details

Defined in Data.Bson

Val UTCTime Source # 
Instance details

Defined in Data.Bson

Val POSIXTime Source # 
Instance details

Defined in Data.Bson

Val ObjectId Source # 
Instance details

Defined in Data.Bson

Val MinMaxKey Source # 
Instance details

Defined in Data.Bson

Val MongoStamp Source # 
Instance details

Defined in Data.Bson

Val Symbol Source # 
Instance details

Defined in Data.Bson

Val Javascript Source # 
Instance details

Defined in Data.Bson

Val Regex Source # 
Instance details

Defined in Data.Bson

Val UserDefined Source # 
Instance details

Defined in Data.Bson

Val MD5 Source # 
Instance details

Defined in Data.Bson

Val UUID Source # 
Instance details

Defined in Data.Bson

Val Function Source # 
Instance details

Defined in Data.Bson

Val Binary Source # 
Instance details

Defined in Data.Bson

Val Value Source # 
Instance details

Defined in Data.Bson

Val Field Source # 
Instance details

Defined in Data.Bson

Val a => Val [a] Source # 
Instance details

Defined in Data.Bson

Methods

val :: [a] -> Value Source #

valList :: [[a]] -> Value Source #

valMaybe :: Maybe [a] -> Value Source #

cast' :: Value -> Maybe [a] Source #

cast'List :: Value -> Maybe [[a]] Source #

cast'Maybe :: Value -> Maybe (Maybe [a]) Source #

Val a => Val (Maybe a) Source # 
Instance details

Defined in Data.Bson

fval :: (forall a. Val a => a -> b) -> Value -> b Source #

Apply generic function to typed value

cast :: (Val a, Monad m) => Value -> m a Source #

Convert Value to expected type, or fail (Nothing) if not of that type

typed :: Val a => Value -> a Source #

Convert Value to expected type. Error if not that type.

typeOfVal :: Value -> TypeRep Source #

Type of typed value

Special Bson value types

newtype Binary Source #

Constructors

Binary ByteString 
Instances
Eq Binary Source # 
Instance details

Defined in Data.Bson

Methods

(==) :: Binary -> Binary -> Bool #

(/=) :: Binary -> Binary -> Bool #

Ord Binary Source # 
Instance details

Defined in Data.Bson

Read Binary Source # 
Instance details

Defined in Data.Bson

Show Binary Source # 
Instance details

Defined in Data.Bson

Val Binary Source # 
Instance details

Defined in Data.Bson

newtype UUID Source #

Constructors

UUID ByteString 
Instances
Eq UUID Source # 
Instance details

Defined in Data.Bson

Methods

(==) :: UUID -> UUID -> Bool #

(/=) :: UUID -> UUID -> Bool #

Ord UUID Source # 
Instance details

Defined in Data.Bson

Methods

compare :: UUID -> UUID -> Ordering #

(<) :: UUID -> UUID -> Bool #

(<=) :: UUID -> UUID -> Bool #

(>) :: UUID -> UUID -> Bool #

(>=) :: UUID -> UUID -> Bool #

max :: UUID -> UUID -> UUID #

min :: UUID -> UUID -> UUID #

Read UUID Source # 
Instance details

Defined in Data.Bson

Show UUID Source # 
Instance details

Defined in Data.Bson

Methods

showsPrec :: Int -> UUID -> ShowS #

show :: UUID -> String #

showList :: [UUID] -> ShowS #

Val UUID Source # 
Instance details

Defined in Data.Bson

newtype MD5 Source #

Constructors

MD5 ByteString 
Instances
Eq MD5 Source # 
Instance details

Defined in Data.Bson

Methods

(==) :: MD5 -> MD5 -> Bool #

(/=) :: MD5 -> MD5 -> Bool #

Ord MD5 Source # 
Instance details

Defined in Data.Bson

Methods

compare :: MD5 -> MD5 -> Ordering #

(<) :: MD5 -> MD5 -> Bool #

(<=) :: MD5 -> MD5 -> Bool #

(>) :: MD5 -> MD5 -> Bool #

(>=) :: MD5 -> MD5 -> Bool #

max :: MD5 -> MD5 -> MD5 #

min :: MD5 -> MD5 -> MD5 #

Read MD5 Source # 
Instance details

Defined in Data.Bson

Show MD5 Source # 
Instance details

Defined in Data.Bson

Methods

showsPrec :: Int -> MD5 -> ShowS #

show :: MD5 -> String #

showList :: [MD5] -> ShowS #

Val MD5 Source # 
Instance details

Defined in Data.Bson

data Regex 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.

Constructors

Regex Text Text 
Instances
Eq Regex Source # 
Instance details

Defined in Data.Bson

Methods

(==) :: Regex -> Regex -> Bool #

(/=) :: Regex -> Regex -> Bool #

Ord Regex Source # 
Instance details

Defined in Data.Bson

Methods

compare :: Regex -> Regex -> Ordering #

(<) :: Regex -> Regex -> Bool #

(<=) :: Regex -> Regex -> Bool #

(>) :: Regex -> Regex -> Bool #

(>=) :: Regex -> Regex -> Bool #

max :: Regex -> Regex -> Regex #

min :: Regex -> Regex -> Regex #

Read Regex Source # 
Instance details

Defined in Data.Bson

Show Regex Source # 
Instance details

Defined in Data.Bson

Methods

showsPrec :: Int -> Regex -> ShowS #

show :: Regex -> String #

showList :: [Regex] -> ShowS #

Val Regex Source # 
Instance details

Defined in Data.Bson

data Javascript Source #

Javascript code with possibly empty environment mapping variables to values that the code may reference

Constructors

Javascript Document Text 

newtype Symbol Source #

Constructors

Symbol Text 
Instances
Eq Symbol Source # 
Instance details

Defined in Data.Bson

Methods

(==) :: Symbol -> Symbol -> Bool #

(/=) :: Symbol -> Symbol -> Bool #

Ord Symbol Source # 
Instance details

Defined in Data.Bson

Read Symbol Source # 
Instance details

Defined in Data.Bson

Show Symbol Source # 
Instance details

Defined in Data.Bson

Val Symbol Source # 
Instance details

Defined in Data.Bson

ObjectId

data ObjectId Source #

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.

Constructors

Oid !Word32 !Word64 

timestamp :: ObjectId -> UTCTime Source #

Time when objectId was created

genObjectId :: IO ObjectId Source #

Create a fresh ObjectId

showHexLen :: (Show n, Integral n) => Int -> n -> ShowS Source #

showHex of n padded with leading zeros if necessary to fill d digits