Fix group by composite (#255)

* remove failing test with bad behavior

* test case

* changelog, vbump
This commit is contained in:
Matt Parsons 2021-05-20 16:33:01 -06:00 committed by GitHub
parent b5c0d84cad
commit e39c62990e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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