Merge pull request #66 from stackbuilders/array_remove

Add arrayRemove wrapper for PostgreSQL function
This commit is contained in:
Chris Allen 2018-01-10 12:52:01 -06:00 committed by GitHub
commit 29292a4d8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -13,6 +13,8 @@ addons:
- postgresql-client
- postgresql-server-dev-all
postgresql: "9.6"
env:
- GHCVER=7.10
- GHCVER=8.0

View File

@ -6,6 +6,7 @@
module Database.Esqueleto.PostgreSQL
( arrayAggDistinct
, arrayAgg
, arrayRemove
, stringAgg
, chr
, now_
@ -31,6 +32,13 @@ arrayAggDistinct = arrayAgg . distinct
arrayAgg :: SqlExpr (Value a) -> SqlExpr (Value [a])
arrayAgg = unsafeSqlFunction "array_agg"
-- | (@array_remove@) Remove all elements equal to the given value from the
-- array.
--
-- /Since: 2.5.3/
arrayRemove :: SqlExpr (Value [a]) -> SqlExpr (Value a) -> SqlExpr (Value [a])
arrayRemove arr elem = unsafeSqlFunction "array_remove" (arr, elem)
-- | (@string_agg@) Concatenate input values separated by a
-- delimiter.
--

View File

@ -1464,6 +1464,14 @@ main = do
select . from $ \p -> return (EP.arrayAgg (p ^. PersonName))
liftIO $ L.sort ret `shouldBe` L.sort (map personName people)
it "arrayRemove looks sane" $
run $ do
let people = [p1, p2, p3, p4, p5]
mapM_ insert people
[Value ret] <-
select . from $ \p -> return (EP.arrayRemove (EP.arrayAgg (p ^. PersonName)) (val "Rachel"))
liftIO $ ret `shouldMatchList` ["John", "Mike", "Livia", "Mitch"]
it "stringAgg looks sane" $
run $ do
let people = [p1, p2, p3, p4, p5]