From 29eb0d8be3b4ede2ea42ec13a8d89025e443e847 Mon Sep 17 00:00:00 2001 From: Felipe Lessa Date: Sat, 20 Jun 2015 23:50:47 -0300 Subject: [PATCH] Explicitly state multiple 'orderBy's work (closes #103). --- src/Database/Esqueleto/Internal/Language.hs | 3 +++ test/Test.hs | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Database/Esqueleto/Internal/Language.hs b/src/Database/Esqueleto/Internal/Language.hs index ca461ef..72f1341 100644 --- a/src/Database/Esqueleto/Internal/Language.hs +++ b/src/Database/Esqueleto/Internal/Language.hs @@ -166,6 +166,9 @@ class (Functor query, Applicative query, Monad query) => groupBy :: (ToSomeValues expr a) => a -> query () -- | @ORDER BY@ clause. See also 'asc' and 'desc'. + -- + -- Multiple calls to 'orderBy' get concatenated on the final + -- query, including 'distinctOnOrderBy'. orderBy :: [expr OrderBy] -> query () -- | Ascending order of this field or expression. diff --git a/test/Test.hs b/test/Test.hs index a6184b7..3026730 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -706,7 +706,7 @@ main = do return p liftIO $ ret `shouldBe` [ p1e, p3e, p2e ] - it "works with two ASC fields" $ + it "works with two ASC fields (one call)" $ run $ do p1e <- insert' p1 p2e <- insert' p2 @@ -724,7 +724,7 @@ main = do liftIO $ ret `shouldBe` [ p2e, p4e, p3e, p1e ] #endif - it "works with one ASC and one DESC field" $ + it "works with one ASC and one DESC field (two calls)" $ run $ do p1e <- insert' p1 p2e <- insert' p2 @@ -732,7 +732,8 @@ main = do p4e <- insert' p4 ret <- select $ from $ \p -> do - orderBy [desc (p ^. PersonAge), asc (p ^. PersonName)] + orderBy [desc (p ^. PersonAge)] + orderBy [asc (p ^. PersonName)] return p #ifdef WITH_POSTGRESQL liftIO $ ret `shouldBe` [ p2e, p1e, p4e, p3e ]