Merge pull request #66 from stackbuilders/array_remove
Add arrayRemove wrapper for PostgreSQL function
This commit is contained in:
commit
29292a4d8c
@ -13,6 +13,8 @@ addons:
|
|||||||
- postgresql-client
|
- postgresql-client
|
||||||
- postgresql-server-dev-all
|
- postgresql-server-dev-all
|
||||||
|
|
||||||
|
postgresql: "9.6"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- GHCVER=7.10
|
- GHCVER=7.10
|
||||||
- GHCVER=8.0
|
- GHCVER=8.0
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
module Database.Esqueleto.PostgreSQL
|
module Database.Esqueleto.PostgreSQL
|
||||||
( arrayAggDistinct
|
( arrayAggDistinct
|
||||||
, arrayAgg
|
, arrayAgg
|
||||||
|
, arrayRemove
|
||||||
, stringAgg
|
, stringAgg
|
||||||
, chr
|
, chr
|
||||||
, now_
|
, now_
|
||||||
@ -31,6 +32,13 @@ arrayAggDistinct = arrayAgg . distinct
|
|||||||
arrayAgg :: SqlExpr (Value a) -> SqlExpr (Value [a])
|
arrayAgg :: SqlExpr (Value a) -> SqlExpr (Value [a])
|
||||||
arrayAgg = unsafeSqlFunction "array_agg"
|
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
|
-- | (@string_agg@) Concatenate input values separated by a
|
||||||
-- delimiter.
|
-- delimiter.
|
||||||
--
|
--
|
||||||
|
|||||||
@ -1464,6 +1464,14 @@ main = do
|
|||||||
select . from $ \p -> return (EP.arrayAgg (p ^. PersonName))
|
select . from $ \p -> return (EP.arrayAgg (p ^. PersonName))
|
||||||
liftIO $ L.sort ret `shouldBe` L.sort (map personName people)
|
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" $
|
it "stringAgg looks sane" $
|
||||||
run $ do
|
run $ do
|
||||||
let people = [p1, p2, p3, p4, p5]
|
let people = [p1, p2, p3, p4, p5]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user