Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix group by composite #255

Merged
merged 3 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion esqueleto.cabal
Original file line number Diff line number Diff line change
@@ -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.
.
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Esqueleto/Internal/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions test/Common/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions test/PostgreSQL/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down