From 42f3b0be52c1d558b3f861c9b4ce712682e35716 Mon Sep 17 00:00:00 2001 From: Matthias Putz Date: Mon, 18 May 2020 00:00:47 +0200 Subject: [PATCH] Added Postgres specific || operator for concatenating two jsonb values into a new json value. --- beam-postgres/Database/Beam/Postgres/PgSpecific.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/beam-postgres/Database/Beam/Postgres/PgSpecific.hs b/beam-postgres/Database/Beam/Postgres/PgSpecific.hs index 639b139f2..2f601ae78 100644 --- a/beam-postgres/Database/Beam/Postgres/PgSpecific.hs +++ b/beam-postgres/Database/Beam/Postgres/PgSpecific.hs @@ -32,7 +32,7 @@ module Database.Beam.Postgres.PgSpecific , (@>), (<@), (->#), (->$) , (->>#), (->>$), (#>), (#>>) - , (?), (?|), (?&) + , (?), (?|), (?&), (||.) , withoutKey, withoutIdx , withoutKeys @@ -114,7 +114,7 @@ module Database.Beam.Postgres.PgSpecific ) where -import Database.Beam hiding (char, double) +import Database.Beam hiding ((||.), char, double) import Database.Beam.Backend.SQL import Database.Beam.Migrate ( HasDefaultSqlDataType(..) ) import Database.Beam.Postgres.Syntax @@ -960,6 +960,13 @@ QExpr a ?| QExpr b = QExpr a ?& QExpr b = QExpr (pgBinOp "?&" <$> a <*> b) +-- | Postgres @||@ operator. Concatenates two jsonb values into a new jsonb value. +(||.) :: QGenExpr ctxt Postgres s (PgJSONB a) + -> QGenExpr ctxt Postgres s (PgJSONB a) + -> QGenExpr ctxt Postgres s (PgJSONB a) +QExpr a ||. QExpr b = + QExpr (pgBinOp "||" <$> a <*> b) + -- | Postgres @-@ operator on json objects. Returns the supplied json object -- with the supplied key deleted. See 'withoutIdx' for the corresponding -- operator on arrays.