From c1b8a21366ad58f265abefe76e9ce9fcfa7858e8 Mon Sep 17 00:00:00 2001 From: "Scott R. Parish" Date: Tue, 9 Mar 2010 08:22:30 -0600 Subject: [PATCH] restoring array conversion using toBson/fromBson --- Database/MongoDB/BSON.hs | 95 ++++++++++++++++++++++++++++++++++++++++ map-reduce-example.md | 9 ++-- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/Database/MongoDB/BSON.hs b/Database/MongoDB/BSON.hs index 5010636..22a820a 100644 --- a/Database/MongoDB/BSON.hs +++ b/Database/MongoDB/BSON.hs @@ -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 diff --git a/map-reduce-example.md b/map-reduce-example.md index 96550dd..7f55b29 100644 --- a/map-reduce-example.md +++ b/map-reduce-example.md @@ -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 [])]) ]