restoring array conversion using toBson/fromBson
This commit is contained in:
parent
d1366e2261
commit
c1b8a21366
2 changed files with 98 additions and 6 deletions
|
@ -472,3 +472,98 @@ instance BsonConv Word64 where
|
|||
fromBson (BsonInt32 i) = fromIntegral i
|
||||
fromBson (BsonInt64 i) = fromIntegral i
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Double] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Float] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Int] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Int8] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Int16] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Int32] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Int64] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Integer] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Word] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Word8] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Word16] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Word32] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Word64] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [Bool] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [POSIXTime] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [String] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [L8.ByteString] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [S8.ByteString] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
||||
instance BsonConv [BsonDoc] where
|
||||
toBson = BsonArray . List.map toBson
|
||||
fromBson (BsonArray ss) = List.map fromBson ss
|
||||
fromBson _ = throwUnsupConv
|
||||
|
|
|
@ -25,14 +25,11 @@ map/reduce queries on:
|
|||
> :{
|
||||
insertMany c col [
|
||||
(toBsonDoc [("x", BsonInt32 1),
|
||||
("tags", BsonArray [toBson "dog",
|
||||
toBson "cat"])]),
|
||||
("tags", toBson ["dog", "cat"])]),
|
||||
(toBsonDoc [("x", BsonInt32 2),
|
||||
("tags", BsonArray [toBson "cat"])]),
|
||||
("tags", toBson ["cat"])]),
|
||||
(toBsonDoc [("x", BsonInt32 3),
|
||||
("tags", BsonArray [toBson "mouse",
|
||||
toBson "cat",
|
||||
toBson "doc"])]),
|
||||
("tags", toBson ["mouse", "cat", "doc"])]),
|
||||
(toBsonDoc [("x", BsonInt32 4),
|
||||
("tags", BsonArray [])])
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue