Safe Haskell | Trustworthy |
---|
This module exports a safe subset of the labeled BSON (LBSON) module. See Hails.Data.LBson.TCB for documentation.
- module Data.UString
- type Document l = [Field l]
- type LabeledDocument l = Labeled l (Document l)
- look :: (Monad m, Label l) => Key -> Document l -> m (Value l)
- lookup :: (Val l v, Monad m, Label l) => Key -> Document l -> m v
- valueAt :: Label l => Key -> [Field l] -> Value l
- at :: forall v l. (Val l v, Label l) => Key -> Document l -> v
- include :: Label l => [Key] -> Document l -> Document l
- exclude :: Label l => [Key] -> Document l -> Document l
- merge :: Label l => Document l -> Document l -> Document l
- data Field l = := {}
- (=:) :: (Val l v, Label l) => Key -> v -> Field l
- (=?) :: (Val l a, Label l) => Key -> Maybe a -> Document l
- type Key = Label
- hailsInternalKeyPrefix :: Key
- data Value l
- class (Typeable a, Show a, Eq a, Label l) => Val l a where
- cast :: forall m l a. (Label l, Val l a, Monad m) => Value l -> m a
- typed :: (Val l a, Label l) => Value l -> a
- pu :: (Label l, Val a) => a -> PolicyLabeled l a
- pl :: (Label l, Val a) => Labeled l a -> PolicyLabeled l a
- newtype Binary = Binary ByteString
- newtype Function = Function ByteString
- newtype UUID = UUID ByteString
- newtype MD5 = MD5 ByteString
- newtype UserDefined = UserDefined ByteString
- data Regex = Regex UString UString
- data Javascript = Javascript Document UString
- newtype Symbol = Symbol UString
- newtype MongoStamp = MongoStamp Int64
- data MinMaxKey
- data ObjectId = Oid Word32 Word64
- timestamp :: ObjectId -> UTCTime
- genObjectId :: LabelState l p s => LIO l p s ObjectId
- type BsonValue = Value
- module Hails.Data.LBson.Rexports
- safeToBsonValue :: Label l => Value l -> Maybe BsonValue
- safeFromBsonValue :: (Serialize l, Label l) => BsonValue -> Maybe (Value l)
- type BsonDocument = Document
- safeToBsonDoc :: (Serialize l, Label l) => Document l -> Maybe BsonDocument
- safeFromBsonDoc :: (Serialize l, Label l) => BsonDocument -> Maybe (Document l)
- encodeDoc :: BsonDocSerialize doc => doc -> ByteString
- decodeDoc :: BsonDocSerialize doc => ByteString -> doc
UTF-8 String
module Data.UString
Document
type LabeledDocument l = Labeled l (Document l)Source
A labeled Document
look :: (Monad m, Label l) => Key -> Document l -> m (Value l)Source
Value of field in document, or fail (Nothing) if field not found
lookup :: (Val l v, Monad m, Label l) => Key -> Document l -> 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.
valueAt :: Label l => Key -> [Field l] -> Value lSource
Value of field in document. Error if missing.
at :: forall v l. (Val l v, Label l) => Key -> Document l -> vSource
Typed value of field in document. Error if missing or wrong type.
include :: Label l => [Key] -> Document l -> Document lSource
Only include fields of document in key list
exclude :: Label l => [Key] -> Document l -> Document lSource
Exclude fields from document in key list
merge :: Label l => Document l -> Document l -> Document lSource
Merge documents with preference given to first one when both have the same key. 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 Field
is a 'Key'-'Value' pair.
(=?) :: (Val l a, Label l) => Key -> Maybe a -> Document lSource
If Just
value then return one field document, otherwise
return empty document
hailsInternalKeyPrefix :: KeySource
This prefix is reserved for HAILS keys. It should not be used by arbitrary code.
Value
A Value
is either a standard BSON value, a labeled value, or
a policy-labeled value.
class (Typeable a, Show a, Eq a, Label l) => Val l a whereSource
Haskell types of this class correspond to LBSON value types.
(Val a, Label l) => Val l a | Every type that is an instance of BSON Val is an instance of
LBSON Val. This requires the use of |
Label l => Val l (Value l) | |
(Val a, Label l) => Val l (PolicyLabeled l a) | Convert between a policy-labeled value and a labeled BSON value. |
(Val a, Label l) => Val l (Labeled l a) | Convert between a labeled value and a labeled BSON value. |
cast :: forall m l a. (Label l, Val l a, Monad m) => Value l -> m aSource
Convert Value to expected type, or fail (Nothing) if not of that type
typed :: (Val l a, Label l) => Value l -> aSource
Convert Value to expected type. Error if not that type.
Policy labeled values
pu :: (Label l, Val a) => a -> PolicyLabeled l aSource
Wrap an unlabeled value by PolicyLabeled
.
pl :: (Label l, Val a) => Labeled l a -> PolicyLabeled l aSource
Wrap an already-labeled value by PolicyLabeled
.
Special Bson value types
newtype Function
newtype UserDefined
data Regex
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
Javascript code with possibly empty environment mapping variables to values that the code may reference
newtype MongoStamp
data MinMaxKey
ObjectId
data 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 :: LabelState l p s => LIO l p s ObjectIdSource
Generate fresh ObjectId
.
Convert to/from Data.Bson
module Hails.Data.LBson.Rexports
type BsonDocument = DocumentSource
Export Document
safeToBsonDoc :: (Serialize l, Label l) => Document l -> Maybe BsonDocumentSource
Safe version of toBsonDoc
.
safeFromBsonDoc :: (Serialize l, Label l) => BsonDocument -> Maybe (Document l)Source
Safe version of fromBsonDoc
.
Convert to/from Bytestring
encodeDoc :: BsonDocSerialize doc => doc -> ByteStringSource
Encodea document
decodeDoc :: BsonDocSerialize doc => ByteString -> docSource
Decode a document