bson-generic-0.0.5.1: Generic functionality for BSON

Data.Bson.Generic

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 whereSource

Methods

toBSON :: a -> DocumentSource

Instances

class FromBSON a whereSource

Instances

newtype ObjectKey Source

Constructors

ObjectKey 

Instances

Eq ObjectKey 
Show ObjectKey 
Typeable ObjectKey 
Generic ObjectKey 
FromBSON ObjectKey 
ToBSON ObjectKey 
Selector s => GFromBSON (S1 s (K1 i ObjectKey))

ObjectKey special treatment

Selector s => GToBSON (S1 s (K1 i ObjectKey))

ObjectKey special treatment