Merge pull request #65 from stackbuilders/array_agg_distinct
Add arrayAggDistinct wrapper for PostgreSQL function
This commit is contained in:
commit
664d36151b
@ -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
|
||||
|
||||
@ -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.
|
||||
--
|
||||
|
||||
10
test/Test.hs
10
test/Test.hs
@ -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]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user