bson 0.0.2 → 0.0.3
raw patch · 2 files changed
+16/−11 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Bson: typeOfVal :: Value -> TypeRep
Files
- Data/Bson.hs +13/−8
- bson.cabal +3/−3
Data/Bson.hs view
@@ -12,7 +12,7 @@ Field(..), (=:), (=?), Label, -- * Value- Value(..), Val(..), fval, cast, typed,+ Value(..), Val(..), fval, cast, typed, typeOfVal, -- * Special Bson value types Binary(..), Function(..), UUID(..), MD5(..), UserDefined(..), Regex(..), Javascript(..), Symbol(..), MongoStamp(..), MinMaxKey(..),@@ -48,7 +48,7 @@ -- * Document type Document = [Field]--- ^ A BSON document is a sequence of 'Field's+-- ^ A BSON document is a list of 'Field's look :: (Monad m) => Label -> Document -> m Value -- ^ Value of field in document, or fail (Nothing) if field not found@@ -168,6 +168,10 @@ -- ^ Convert Value to expected type. Error if not that type. typed = runIdentity . cast +typeOfVal :: Value -> TypeRep+-- ^ Type of typed value+typeOfVal = fval typeOf+ -- ** conversion class -- | Haskell types of this class correspond to BSON value types@@ -285,7 +289,7 @@ instance Val Int32 where val = Int32 cast' (Int32 x) = Just x- cast' (Int64 x) = mInt32 x+ cast' (Int64 x) = fitInt x cast' (Float x) = Just (round x) cast' _ = Nothing @@ -297,14 +301,15 @@ cast' _ = Nothing instance Val Int where- val n = maybe (Int64 $ fromIntegral n) Int32 (mInt32 n)+ val n = maybe (Int64 $ fromIntegral n) Int32 (fitInt n) cast' (Int32 x) = Just (fromIntegral x) cast' (Int64 x) = Just (fromEnum x) cast' (Float x) = Just (round x) cast' _ = Nothing instance Val Integer where- val n = maybe (Int64 . toEnum . fromEnum $ n) Int32 (mInt32 n)+ val n = maybe (maybe err Int64 $ fitInt n) Int32 (fitInt n) where+ err = error $ show n ++ " is too large for Bson Int Value" cast' (Int32 x) = Just (fromIntegral x) cast' (Int64 x) = Just (fromIntegral x) cast' (Float x) = Just (round x)@@ -320,9 +325,9 @@ cast' (MinMax x) = Just x cast' _ = Nothing -mInt32 :: (Integral n) => n -> Maybe Int32--- ^ If number fits in 32 bits then cast to Int32, otherwise Nothing-mInt32 n = if fromIntegral (minBound :: Int32) <= n && n <= fromIntegral (maxBound :: Int32)+fitInt :: forall n m. (Integral n, Integral m, Bounded m) => n -> Maybe m+-- ^ If number fits in type m then cast to m, otherwise Nothing+fitInt n = if fromIntegral (minBound :: m) <= n && n <= fromIntegral (maxBound :: m) then Just (fromIntegral n) else Nothing
bson.cabal view
@@ -1,9 +1,9 @@ Name: bson-Version: 0.0.2+Version: 0.0.3 Synopsis: BSON documents are JSON-like objects with a standard binary encoding-Description: BSON (short for Binary JSON) is a binary-encoded serialization of JSON-like documents.+Description: A BSON Document is an untyped (dynamically type-checked) record. I.e. it is a list of name-value pairs, where a Value is a single sum type with constructors for basic types (Bool, Int, Float, String, and Time), compound types (List, and (embedded) Document), and special types (Binary, Javascript, ObjectId, RegEx, and a few others). A BSON Document is serialized to a standard bin .- This implements version 1.0 of the BSON spec, which is defined at <http://bsonspec.org>.+ A BSON Document is serialized to a standard binary encoding defined at <http://bsonspec.org>. This implements version 1 of that spec. Category: Data Homepage: http://github.com/TonyGen/bson-haskell Author: Tony Hannan