Add test for calling sql functions on aliased values; Fixed unsafeSql… (#189)
* Add test for calling sql functions on aliased values; Fixed unsafeSqlFunction to handle aliaed values properly * version bump and changelog
This commit is contained in:
parent
9a4813d422
commit
7f769cc673
@ -1,7 +1,13 @@
|
||||
3.3.3.1
|
||||
========
|
||||
- @belevy
|
||||
- [#189](https://github.com/bitemyapp/esqueleto/pull/189) - Fix bug in function calls with
|
||||
aliased values introduced by SubQuery joins.
|
||||
|
||||
3.3.3.0
|
||||
========
|
||||
- @belevy
|
||||
- [#177](https://github.com/bitemyapp/esqueleto/pull/172) - Introduce new
|
||||
- [#172](https://github.com/bitemyapp/esqueleto/pull/172) - Introduce new
|
||||
experimental module for joins, set operations (eg UNION), and safer queries
|
||||
from outer joins.
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
cabal-version: 1.12
|
||||
|
||||
name: esqueleto
|
||||
version: 3.3.3.0
|
||||
version: 3.3.3.1
|
||||
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.
|
||||
.
|
||||
|
||||
@ -1576,6 +1576,7 @@ data UnexpectedValueError =
|
||||
| FoldHelpError
|
||||
| SqlCaseError
|
||||
| SqlCastAsError
|
||||
| SqlFunctionError
|
||||
| MakeOnClauseError
|
||||
| MakeExcError
|
||||
| MakeSetError
|
||||
@ -2192,8 +2193,15 @@ 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
|
||||
let
|
||||
valueToFunctionArg v =
|
||||
case v of
|
||||
ERaw _ f -> f info
|
||||
EAliasedValue i _ -> aliasedValueIdentToRawSql i info
|
||||
EValueReference i i' -> valueReferenceToRawSql i i' info
|
||||
ECompositeKey _ -> throw (CompositeKeyErr SqlFunctionError)
|
||||
(argsTLB, argsVals) =
|
||||
uncommas' $ map valueToFunctionArg $ toArgList arg
|
||||
in (name <> parens argsTLB, argsVals)
|
||||
|
||||
-- | (Internal) An unsafe SQL function to extract a subfield from a compound
|
||||
|
||||
@ -2499,6 +2499,18 @@ testExperimentalFrom run = do
|
||||
--error . show =<< renderQuerySelect q
|
||||
pure ()
|
||||
|
||||
it "can call functions on aliased values" $ do
|
||||
run $ do
|
||||
insert_ p1
|
||||
insert_ p3
|
||||
-- Pretend this isnt all posts
|
||||
upperNames <- select $ do
|
||||
author <- Experimental.from $ SelectQuery $ Experimental.from $ Table @Person
|
||||
pure $ upper_ $ author ^. PersonName
|
||||
|
||||
liftIO $ upperNames `shouldMatchList` [ Value "JOHN"
|
||||
, Value "MIKE"
|
||||
]
|
||||
|
||||
listsEqualOn :: (Show a1, Eq a1) => [a2] -> [a2] -> (a2 -> a1) -> Expectation
|
||||
listsEqualOn a b f = map f a `shouldBe` map f b
|
||||
|
||||
Loading…
Reference in New Issue
Block a user