bson-generic-0.0.8: Generic functionality for BSON

Safe HaskellNone
LanguageHaskell2010

Data.Bson.Generic

Contents

Description

Examples

data Test0 = A | B | C deriving (Generic, Typeable, Show, Eq)
instance ToBSON Test0
instance FromBSON Test0

(fromBSON $ toBSON A) :: Maybe Test0
data Test1 = Test1 String String deriving (Generic, Typeable, Show, Eq)
instance ToBSON Test1
instance FromBSON Test1

(fromBSON $ toBSON $ Test1 "aa" "bb") :: Maybe Test1
data Test2 = Test2 { test20 :: String, test21 :: String } deriving (Generic, Typeable, Show, Eq)
instance ToBSON Test2
instance FromBSON Test2

(fromBSON $ toBSON $ Test2 "aa" "bb") :: Maybe Test2
data Test3 = Test3 { test30 :: Test2, test31 :: String } deriving (Generic, Typeable, Show, Eq)
instance ToBSON Test3
instance FromBSON Test3

(fromBSON $ toBSON $ Test3 (Test2 "aa" "bb") "cc") :: Maybe Test3
data Test4 = Test4 { test4Key :: ObjectKey, test4 :: String } deriving (Generic, Typeable, Show, Eq)
instance ToBSON Test4
instance FromBSON Test4

(fromBSON $ toBSON $ Test4 (ObjectKey . Just $ unsafePerformIO genObjectId) "something") :: Maybe Test4
(fromBSON $ toBSON $ Test4 (ObjectKey Nothing) "something") :: Maybe Test4
data Comment = Comment { author :: String, comments :: [Comment] } deriving (Generic, Typeable, Show, Eq)
instance ToBSON Comment
instance FromBSON Comment

(fromBSON $ toBSON $ Comment "Joe1" [Comment "Joe2" [], Comment "Joe3" [Comment "Joe4" [], Comment "Joe5" []]]) :: Maybe Comment

Representation

toBSON $ Test2 "aa" "bb"

[ test20: "aa", test21: "bb" ]
toBSON $ Test3 (Test2 "aa" "bb") "cc"

[ test30: [ test20: "aa", test21: "bb"], test31: "cc" ]
toBSON $ Test4 (ObjectKey . Just $ unsafePerformIO genObjectId) "something"

[ _id: 4f226c27900faa06ab000001, test4: "something" ]
toBSON $ Test4 (ObjectKey Nothing) "something"

[ test4: "something" ]
toBSON $ Comment "Joe1" [ Comment "Joe2" []
                        , Comment "Joe3" [ Comment "Joe4" []
                                         , Comment "Joe5" []
                                         ]
                        ]

[ author: "Joe1", comments: [ [ author: "Joe2", comments: []]
                            , [ author: "Joe3", comments: [ [ author: "Joe4", comments: []]
                                                          , [ author: "Joe5", comments: []]
                                                          ]]
                            ]]

Documentation

class ToBSON a where Source #

Minimal complete definition

Nothing

Methods

toBSON :: a -> Document Source #

toBSON :: (Generic a, GConstructorCount (Rep a), GToBSON (Rep a)) => a -> Document Source #

Instances
ToBSON ObjectKey Source # 
Instance details

Defined in Data.Bson.Generic

class FromBSON a where Source #

Minimal complete definition

Nothing

Methods

fromBSON :: Document -> Maybe a Source #

fromBSON :: (Generic a, GConstructorCount (Rep a), GFromBSON (Rep a)) => Document -> Maybe a Source #

Instances
FromBSON ObjectKey Source # 
Instance details

Defined in Data.Bson.Generic

newtype ObjectKey Source #

Constructors

ObjectKey 
Instances
Eq ObjectKey Source # 
Instance details

Defined in Data.Bson.Generic

Show ObjectKey Source # 
Instance details

Defined in Data.Bson.Generic

Generic ObjectKey Source # 
Instance details

Defined in Data.Bson.Generic

Associated Types

type Rep ObjectKey :: Type -> Type #

FromBSON ObjectKey Source # 
Instance details

Defined in Data.Bson.Generic

ToBSON ObjectKey Source # 
Instance details

Defined in Data.Bson.Generic

type Rep ObjectKey Source # 
Instance details

Defined in Data.Bson.Generic

type Rep ObjectKey = D1 (MetaData "ObjectKey" "Data.Bson.Generic" "bson-generic-0.0.8-2ACitfRCkDYKvChFkSGjXv" True) (C1 (MetaCons "ObjectKey" PrefixI True) (S1 (MetaSel (Just "unObjectKey") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe ObjectId))))

Orphan instances

(FromBSON a, ToBSON a, Typeable a, Show a, Eq a) => Val a Source # 
Instance details

Methods

val :: a -> Value #

valList :: [a] -> Value #

valMaybe :: Maybe a -> Value #

cast' :: Value -> Maybe a #

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

cast'Maybe :: Value -> Maybe (Maybe a) #