on dev help sign in
optional where in on conflict do update
commit03a7e024eeb2b8fd84b656b5c351229a47149474 authorEitan Chatav <eitan.chatav@gmail.com> dateWed 16 Aug 2017, 17:30 (9 years ago) parent369e14d
2 files changed+10−8
squeal-postgresql/src/Squeal/PostgreSQL/Statement.hs+7−5 squeal-postgresql/test/Squeal/PostgreSQL/StatementSpec.hs+3−3
squeal-postgresql/src/Squeal/PostgreSQL/Statement.hs+7−5
@@ -1009,7 +1009,7 @@ data TableConstraint
10091009 = UnsafeTableConstraint { renderTableConstraint :: ByteString }
10101010
10111011check
1012− :: (forall table. Condition '[] '[table ::: columns] 'Ungrouped)
1012+ :: Condition '[] '[table ::: columns] 'Ungrouped
10131013 -> TableConstraint schema columns
10141014check condition = UnsafeTableConstraint $
10151015 "CHECK" <+> parenthesized (renderExpression condition)
@@ -1255,7 +1255,7 @@ data ConflictClause params columns where
12551255 OnConflictDoNothing :: ConflictClause params columns
12561256 OnConflictDoUpdate
12571257 :: NP (Aliased (UpdateExpression params columns)) columns
1258− -> (forall table. Condition params '[table ::: columns] 'Ungrouped)
1258+ -> Maybe (Condition params '[table ::: columns] 'Ungrouped)
12591259 -> ConflictClause params columns
12601260
12611261renderConflictClause
@@ -1265,10 +1265,12 @@ renderConflictClause
12651265renderConflictClause = \case
12661266 Conflict -> ""
12671267 OnConflictDoNothing -> " ON CONFLICT DO NOTHING"
1268− OnConflictDoUpdate updates wh
1268+ OnConflictDoUpdate updates whMaybe
12691269 -> " ON CONFLICT DO UPDATE SET"
12701270 <+> renderCommaSeparatedMaybe renderUpdateExpression updates
1271− <+> "WHERE" <+> renderExpression wh
1271+ <> case whMaybe of
1272+ Nothing -> ""
1273+ Just wh -> " WHERE" <+> renderExpression wh
12721274
12731275{-----------------------------------------
12741276UPDATE statements
@@ -1290,7 +1292,7 @@ update
12901292 :: (HasTable table schema columns, SListI columns, SListI results)
12911293 => Alias table
12921294 -> NP (Aliased (UpdateExpression params columns)) columns
1293− -> (forall tab. Condition params '[tab ::: columns] 'Ungrouped)
1295+ -> Condition params '[tab ::: columns] 'Ungrouped
12941296 -> ReturningClause params columns results
12951297 -> Manipulation schema params results
12961298update table columns wh returning = UnsafeManipulation $
squeal-postgresql/test/Squeal/PostgreSQL/StatementSpec.hs+3−3
@@ -141,12 +141,12 @@ spec = do
141141 statement =
142142 insertInto #table1 (Values (2 `As` #col1 :* 4 `As` #col2 :* Nil) [])
143143 (OnConflictDoUpdate
144− (Set 2 `As` #col1 :* Same `As` #col2 :* Nil) (#col1 /=* #col2))
144+ (Set 2 `As` #col1 :* Same `As` #col2 :* Nil) Nothing)
145145 (Returning Nil)
146146 statement `manipulationRenders`
147147 "INSERT INTO table1 (col1, col2) VALUES (2, 4)\
148148 \ ON CONFLICT DO UPDATE\
149− \ SET col1 = 2 WHERE (col1 <> col2);"
149+ \ SET col1 = 2;"
150150 it "correctly renders returning upsert INSERTs" $ do
151151 let
152152 statement :: Manipulation Tables '[] SumAndCol1
@@ -154,7 +154,7 @@ spec = do
154154 insertInto #table1 (Values (2 `As` #col1 :* 4 `As` #col2 :* Nil) [])
155155 (OnConflictDoUpdate
156156 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
157− (#col1 /=* #col2))
157+ (Just (#col1 /=* #col2)))
158158 (Returning $ (#col1 + #col2) `As` #sum :* #col1 `As` #col1 :* Nil)
159159 statement `manipulationRenders`
160160 "INSERT INTO table1 (col1, col2) VALUES (2, 4)\