diff --git a/changelog.md b/changelog.md index b6b9a83..b9a7acc 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +3.4.2.2 +======= +- @parsonsmatt + - [#255](https://github.com/bitemyapp/esqueleto/pull/255) + - Fix a bug where a composite primary key in a `groupBy` clause would break. + 3.4.2.1 ======= - @parsonsmatt diff --git a/esqueleto.cabal b/esqueleto.cabal index 0ab7d11..db61f80 100644 --- a/esqueleto.cabal +++ b/esqueleto.cabal @@ -1,7 +1,7 @@ cabal-version: 1.12 name: esqueleto -version: 3.4.2.1 +version: 3.4.2.2 synopsis: Type-safe EDSL for SQL queries on persistent backends. description: @esqueleto@ is a bare bones, type-safe EDSL for SQL queries that works with unmodified @persistent@ SQL backends. Its language closely resembles SQL, so you don't have to learn new concepts, just new syntax, and it's fairly easy to predict the generated SQL and optimize it for your backend. Most kinds of errors committed when writing SQL are caught as compile-time errors---although it is possible to write type-checked @esqueleto@ queries that fail at runtime. . diff --git a/src/Database/Esqueleto/Internal/Internal.hs b/src/Database/Esqueleto/Internal/Internal.hs index 1483860..82cb42b 100644 --- a/src/Database/Esqueleto/Internal/Internal.hs +++ b/src/Database/Esqueleto/Internal/Internal.hs @@ -3003,7 +3003,7 @@ makeGroupBy info (GroupBy fields) = first ("\nGROUP BY " <>) build match :: SomeValue -> (TLB.Builder, [PersistValue]) match (SomeValue (ERaw _ f)) = f info - match (SomeValue (ECompositeKey f)) = (mconcat $ f info, mempty) + match (SomeValue (ECompositeKey f)) = (uncommas $ f info, mempty) match (SomeValue (EAliasedValue i _)) = aliasedValueIdentToRawSql i info match (SomeValue (EValueReference i i')) = valueReferenceToRawSql i i' info diff --git a/test/Common/Test.hs b/test/Common/Test.hs index f7c4b09..47491ef 100644 --- a/test/Common/Test.hs +++ b/test/Common/Test.hs @@ -1466,6 +1466,21 @@ testUpdate run = describe "update" $ do , (Entity p1k p1, Value 3) , (Entity p3k p3, Value 7) ] + it "GROUP BY works with composite primary key" $ run $ do + p1k <- insert $ Point 1 2 "asdf" + p2k <- insert $ Point 2 3 "asdf" + ret <- + selectRethrowingQuery $ + from $ \point -> do + where_ $ point ^. PointName ==. val "asdf" + groupBy (point ^. PointId) + pure (point ^. PointId) + liftIO $ do + ret `shouldMatchList` + map Value [p1k, p2k] + + + it "GROUP BY works with COUNT and InnerJoin" $ run $ do l1k <- insert l1 l3k <- insert l3 diff --git a/test/PostgreSQL/Test.hs b/test/PostgreSQL/Test.hs index c13cbd9..d36ebf8 100644 --- a/test/PostgreSQL/Test.hs +++ b/test/PostgreSQL/Test.hs @@ -1423,26 +1423,6 @@ main = do testJSONInsertions testJSONOperators testLateralQuery - testUpdateWithExperimental - -testUpdateWithExperimental :: Spec -testUpdateWithExperimental = fdescribe "Update/Experimental" $ do - it "works" $ do - run $ do - p1k <- insert p1 - updateRethrowingQuery $ \p -> do - (p0 :& p1) <- Experimental.from $ - Table @Person - `InnerJoin` - Table @Person - `Experimental.on` do - \(p0 :& p1) -> - p0 ^. PersonName ==. p1 ^. PersonName - - set p [ PersonName =. val "asdf" ] - where_ $ p0 ^. PersonName ==. p ^. PersonName - - run, runSilent, runVerbose :: Run runSilent act = runNoLoggingT $ run_worker act