From e77e056f5b8ecfb5a257764268d092d23319a039 Mon Sep 17 00:00:00 2001 From: Danny B Date: Thu, 8 Aug 2013 16:46:01 +1100 Subject: [PATCH] Handle NULL result in avg_ too. --- src/Database/Esqueleto.hs | 3 ++- src/Database/Esqueleto/Internal/Language.hs | 3 ++- test/Test.hs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Database/Esqueleto.hs b/src/Database/Esqueleto.hs index f1764a8..35b4c6a 100644 --- a/src/Database/Esqueleto.hs +++ b/src/Database/Esqueleto.hs @@ -43,7 +43,8 @@ module Database.Esqueleto , val, isNothing, just, nothing, joinV, countRows, count, not_ , (==.), (>=.), (>.), (<=.), (<.), (!=.), (&&.), (||.) , (+.), (-.), (/.), (*.) - , random_, sum_, round_, ceiling_, floor_, avg_, min_, max_ + , random_, round_, ceiling_, floor_ + , min_, max_,_sum_, avg_, , like, (%), concat_, (++.) , subList_select, subList_selectDistinct, valList , in_, notIn, exists, notExists diff --git a/src/Database/Esqueleto/Internal/Language.hs b/src/Database/Esqueleto/Internal/Language.hs index ea686b0..ebc220d 100644 --- a/src/Database/Esqueleto/Internal/Language.hs +++ b/src/Database/Esqueleto/Internal/Language.hs @@ -240,10 +240,11 @@ class (Functor query, Applicative query, Monad query) => round_ :: (PersistField a, PersistField b) => expr (Value a) -> expr (Value b) ceiling_ :: (PersistField a, PersistField b) => expr (Value a) -> expr (Value b) floor_ :: (PersistField a, PersistField b) => expr (Value a) -> expr (Value b) + sum_ :: (PersistField a) => expr (Value a) -> expr (Value (Maybe a)) min_ :: (PersistField a) => expr (Value a) -> expr (Value (Maybe a)) max_ :: (PersistField a) => expr (Value a) -> expr (Value (Maybe a)) - avg_ :: (PersistField a, PersistField b) => expr (Value a) -> expr (Value b) + avg_ :: (PersistField a, PersistField b) => expr (Value a) -> expr (Value (Maybe b)) -- | @LIKE@ operator. like :: (PersistField s, IsString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool) diff --git a/test/Test.hs b/test/Test.hs index ecc3b1a..3d92243 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -285,8 +285,8 @@ main = do _ <- insert' p4 ret <- select $ from $ \p-> - return $ avg_ (p ^. PersonAge) - liftIO $ ret `shouldBe` [ Value ((36 + 17 + 17) / 3 :: Double) ] + return $ joinV $ avg_ (p ^. PersonAge) + liftIO $ ret `shouldBe` [ Value $ Just ((36 + 17 + 17) / 3 :: Double) ] it "works with min_" $ run $ do