Compare commits
3 Commits
master
...
matt/sub-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
966ab2ff98 | ||
|
|
ce2236d232 | ||
|
|
9338cfdc5e |
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ stack.yaml.lock
|
|||||||
.cabal-sandbox/
|
.cabal-sandbox/
|
||||||
cabal.sandbox.config
|
cabal.sandbox.config
|
||||||
.hspec-failures
|
.hspec-failures
|
||||||
|
stack.yaml.lock
|
||||||
|
|||||||
@ -634,11 +634,11 @@ v `notIn` e = ifNotEmptyList e True $ unsafeSqlBinOp " NOT IN " v (veryUnsafeCo
|
|||||||
-- return person
|
-- return person
|
||||||
-- @
|
-- @
|
||||||
exists :: SqlQuery () -> SqlExpr (Value Bool)
|
exists :: SqlQuery () -> SqlExpr (Value Bool)
|
||||||
exists = unsafeSqlFunction "EXISTS " . existsHelper
|
exists = unsafeSqlFunctionNoParens "EXISTS " . existsHelper
|
||||||
|
|
||||||
-- | @NOT EXISTS@ operator.
|
-- | @NOT EXISTS@ operator.
|
||||||
notExists :: SqlQuery () -> SqlExpr (Value Bool)
|
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
|
-- | @SET@ clause used on @UPDATE@s. Note that while it's not
|
||||||
-- a type error to use this function on a @SELECT@, it will
|
-- 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 =>
|
unsafeSqlFunction :: UnsafeSqlFunctionArgument a =>
|
||||||
TLB.Builder -> a -> SqlExpr (Value b)
|
TLB.Builder -> a -> SqlExpr (Value b)
|
||||||
unsafeSqlFunction name arg =
|
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 ->
|
ERaw Never $ \info ->
|
||||||
let (argsTLB, argsVals) =
|
let (argsTLB, argsVals) =
|
||||||
uncommas' $ map (\(ERaw _ f) -> f info) $ toArgList arg
|
uncommas' $ map (\(ERaw _ f) -> f info) $ toArgList arg
|
||||||
|
|||||||
@ -219,6 +219,22 @@ testSelect run = do
|
|||||||
ret <- select $ return nothing
|
ret <- select $ return nothing
|
||||||
liftIO $ ret `shouldBe` [ Value (Nothing :: Maybe Int) ]
|
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 -> Spec
|
||||||
testSelectSource run = do
|
testSelectSource run = do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user