Skip to content

Commit 42f3b0b

Browse files
committed
Added Postgres specific || operator for concatenating two jsonb values
into a new json value.
1 parent ebbb8da commit 42f3b0b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

beam-postgres/Database/Beam/Postgres/PgSpecific.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Database.Beam.Postgres.PgSpecific
3232

3333
, (@>), (<@), (->#), (->$)
3434
, (->>#), (->>$), (#>), (#>>)
35-
, (?), (?|), (?&)
35+
, (?), (?|), (?&), (||.)
3636

3737
, withoutKey, withoutIdx
3838
, withoutKeys
@@ -114,7 +114,7 @@ module Database.Beam.Postgres.PgSpecific
114114
)
115115
where
116116

117-
import Database.Beam hiding (char, double)
117+
import Database.Beam hiding ((||.), char, double)
118118
import Database.Beam.Backend.SQL
119119
import Database.Beam.Migrate ( HasDefaultSqlDataType(..) )
120120
import Database.Beam.Postgres.Syntax
@@ -960,6 +960,13 @@ QExpr a ?| QExpr b =
960960
QExpr a ?& QExpr b =
961961
QExpr (pgBinOp "?&" <$> a <*> b)
962962

963+
-- | Postgres @||@ operator. Concatenates two jsonb values into a new jsonb value.
964+
(||.) :: QGenExpr ctxt Postgres s (PgJSONB a)
965+
-> QGenExpr ctxt Postgres s (PgJSONB a)
966+
-> QGenExpr ctxt Postgres s (PgJSONB a)
967+
QExpr a ||. QExpr b =
968+
QExpr (pgBinOp "||" <$> a <*> b)
969+
963970
-- | Postgres @-@ operator on json objects. Returns the supplied json object
964971
-- with the supplied key deleted. See 'withoutIdx' for the corresponding
965972
-- operator on arrays.

0 commit comments

Comments
 (0)