Handle NULL result in avg_ too.

This commit is contained in:
Danny B 2013-08-08 16:46:01 +11:00
parent 068ec9b1ae
commit e77e056f5b
3 changed files with 6 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -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