Compare commits

...

3 Commits

Author SHA1 Message Date
Chris Allen
966ab2ff98 Merge branch 'master' into matt/sub-select-bug 2019-09-24 10:27:58 -05:00
parsonsmatt
ce2236d232 uhhhh this passes all the tests????? 2019-09-20 09:09:30 -05:00
parsonsmatt
9338cfdc5e Add failing test 2019-09-20 09:09:30 -05:00
3 changed files with 27 additions and 2 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ stack.yaml.lock
.cabal-sandbox/
cabal.sandbox.config
.hspec-failures
stack.yaml.lock

View File

@ -634,11 +634,11 @@ v `notIn` e = ifNotEmptyList e True $ unsafeSqlBinOp " NOT IN " v (veryUnsafeCo
-- return person
-- @
exists :: SqlQuery () -> SqlExpr (Value Bool)
exists = unsafeSqlFunction "EXISTS " . existsHelper
exists = unsafeSqlFunctionNoParens "EXISTS " . existsHelper
-- | @NOT EXISTS@ operator.
notExists :: SqlQuery () -> SqlExpr (Value Bool)
notExists = unsafeSqlFunction "NOT EXISTS " . existsHelper
notExists = unsafeSqlFunctionNoParens "NOT EXISTS " . existsHelper
-- | @SET@ clause used on @UPDATE@s. Note that while it's not
-- a type error to use this function on a @SELECT@, it will
@ -1717,6 +1717,14 @@ unsafeSqlValue v = ERaw Never $ const (v, mempty)
unsafeSqlFunction :: UnsafeSqlFunctionArgument a =>
TLB.Builder -> a -> SqlExpr (Value b)
unsafeSqlFunction name arg =
ERaw Never $ \info ->
let (argsTLB, argsVals) =
uncommas' $ map (\(ERaw _ f) -> f info) $ toArgList arg
in (name <> parens (parens argsTLB), argsVals)
unsafeSqlFunctionNoParens :: UnsafeSqlFunctionArgument a =>
TLB.Builder -> a -> SqlExpr (Value b)
unsafeSqlFunctionNoParens name arg =
ERaw Never $ \info ->
let (argsTLB, argsVals) =
uncommas' $ map (\(ERaw _ f) -> f info) $ toArgList arg

View File

@ -219,6 +219,22 @@ testSelect run = do
ret <- select $ return nothing
liftIO $ ret `shouldBe` [ Value (Nothing :: Maybe Int) ]
describe "sub_select" $ do
it "works inside of sum" $ do
run $ do
ret <-
select $
pure $
sum_ $
sub_select $
from $ \foo -> do
pure (foo ^. FooName)
nonSub <-
select $
from $ \foo -> do
pure (sum_ (foo ^. FooName))
liftIO $ ret `shouldBe` (nonSub :: [Value (Maybe Int)])
testSelectSource :: Run -> Spec
testSelectSource run = do