Skip to content

Commit

Permalink
Added test case for PR #695
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Oct 9, 2024
1 parent b5205ec commit 8e5d870
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion beam-core/test/Database/Beam/Test/SQL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Database.Beam.Test.Schema hiding (tests)
import Database.Beam
import Database.Beam.Backend.SQL (MockSqlBackend)
import Database.Beam.Backend.SQL.AST

import Data.Kind (Type)
import Data.Int
import Data.Time.Clock
import Data.Text (Text)
Expand All @@ -24,6 +24,7 @@ tests :: TestTree
tests = testGroup "SQL generation tests"
[ simpleSelect
, simpleWhere
, simpleWhereNoFrom
, simpleJoin
, selfJoin
, leftJoin
Expand Down Expand Up @@ -118,6 +119,32 @@ simpleWhere =

selectWhere @?= Just (ExpressionBinOp "AND" salaryCond (ExpressionBinOp "AND" ageCond nameCond))

-- | Simple select without FROM clause (#667)

data EmptyDb (f :: Type -> Type) = EmptyDb

simpleWhereNoFrom :: TestTree
simpleWhereNoFrom =
testCase "WHERE clause not dropped if there is no FROM" $ do
SqlSelect Select { selectTable = SelectTable { .. }, .. } <- pure $ selectMock simple

selectGrouping @?= Nothing
selectOrdering @?= []
selectLimit @?= Nothing
selectOffset @?= Nothing
selectHaving @?= Nothing
selectQuantifier @?= Nothing
-- Important point: no FROM clause, yet WHERE clause should still be here
selectFrom @?= Nothing
selectWhere @?= (Just (ExpressionValue (Value False)))

where
simple :: Q (MockSqlBackend Command) EmptyDb s (QExpr (MockSqlBackend Command) s Bool)
simple = do
guard_ (val_ False)
pure (val_ True)


-- | Ensure that multiple tables are correctly joined

simpleJoin :: TestTree
Expand Down

0 comments on commit 8e5d870

Please sign in to comment.