Merge pull request #65 from stackbuilders/array_agg_distinct

Add arrayAggDistinct wrapper for PostgreSQL function
This commit is contained in:
Chris Allen 2018-01-10 10:37:54 -06:00 committed by GitHub
commit 664d36151b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -1,5 +1,5 @@
name: esqueleto
version: 2.5.2
version: 2.5.3
synopsis: Type-safe EDSL for SQL queries on persistent backends.
homepage: https://github.com/bitemyapp/esqueleto
license: BSD3

View File

@ -4,7 +4,8 @@
--
-- /Since: 2.2.8/
module Database.Esqueleto.PostgreSQL
( arrayAgg
( arrayAggDistinct
, arrayAgg
, stringAgg
, chr
, now_
@ -14,6 +15,15 @@ import Database.Esqueleto.Internal.Language
import Database.Esqueleto.Internal.Sql
import Data.Time.Clock (UTCTime)
-- | (@array_agg@) Concatenate distinct input values, including @NULL@s, into
-- an array.
--
-- /Since: 2.5.3/
arrayAggDistinct :: SqlExpr (Value a) -> SqlExpr (Value [a])
arrayAggDistinct = arrayAgg . distinct
where
distinct = unsafeSqlBinOp " " (unsafeSqlValue "DISTINCT")
-- | (@array_agg@) Concatenate input values, including @NULL@s,
-- into an array.
--

View File

@ -1446,6 +1446,16 @@ main = do
#else
(return () :: IO ())
it "arrayAggDistinct looks sane" $
run $ do
let people1 = fmap (\p -> p { personName = "John" }) [p1, p2, p3]
people2 = fmap (\p -> p { personName = "Rachel" }) [p4, p5]
mapM_ insert $ people1 <> people2
[Value ret] <-
select . from $ \p -> return (EP.arrayAggDistinct (p ^. PersonName))
liftIO $ L.sort ret `shouldBe` ["John", "Rachel"]
it "arrayAgg looks sane" $
run $ do
let people = [p1, p2, p3, p4, p5]