diff --git a/src/Database/Esqueleto/Internal/Language.hs b/src/Database/Esqueleto/Internal/Language.hs index bbf0e50..38617f1 100644 --- a/src/Database/Esqueleto/Internal/Language.hs +++ b/src/Database/Esqueleto/Internal/Language.hs @@ -263,7 +263,7 @@ class (Functor query, Applicative query, Monad query) => -- | Like @coalesce@, but takes a non-nullable expression -- placed at the end of the expression list, which guarantees -- a non-NULL result. - coalesceDefault :: PersistField a => expr (Value a) -> [expr (Value (Maybe a))] -> expr (Value a) + coalesceDefault :: PersistField a => [expr (Value (Maybe a))] -> expr (Value a) -> expr (Value a) -- | @LIKE@ operator. like :: (PersistField s, IsString s) => expr (Value s) -> expr (Value s) -> expr (Value Bool) diff --git a/src/Database/Esqueleto/Internal/Sql.hs b/src/Database/Esqueleto/Internal/Sql.hs index e991f10..bb9e97d 100644 --- a/src/Database/Esqueleto/Internal/Sql.hs +++ b/src/Database/Esqueleto/Internal/Sql.hs @@ -373,8 +373,8 @@ instance Esqueleto SqlQuery SqlExpr SqlBackend where min_ = unsafeSqlFunction "MIN" max_ = unsafeSqlFunction "MAX" - coalesce = unsafeSqlFunction "COALESCE" - coalesceDefault def_expr exprs = unsafeSqlFunction "COALESCE" (exprs ++ [just def_expr]) + coalesce = unsafeSqlFunction "COALESCE" + coalesceDefault exprs = unsafeSqlFunction "COALESCE" . (exprs ++) . return . just like = unsafeSqlBinOp " LIKE " (%) = unsafeSqlValue "'%'" diff --git a/test/Test.hs b/test/Test.hs index eaade67..0ed8a23 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -582,7 +582,7 @@ main = do ret2 <- select $ from $ \p -> do orderBy [asc (p ^. PersonId)] - return (coalesceDefault (p ^. PersonFavNum) [p ^. PersonAge, p ^. PersonWeight]) + return (coalesceDefault [p ^. PersonAge, p ^. PersonWeight] (p ^. PersonFavNum)) liftIO $ ret2 `shouldBe` [ Value (36 :: Int) , Value 37 , Value 17