on dev help sign in
optional where in on conflict do update
03a7e02Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Statement.hs+7−5
@@ -1009,7 +1009,7 @@ data TableConstraint
1009 = UnsafeTableConstraint { renderTableConstraint :: ByteString }
1009 = UnsafeTableConstraint { renderTableConstraint :: ByteString }
1010
1010
1011check
1011check
1012− :: (forall table. Condition '[] '[table ::: columns] 'Ungrouped)
1012+ :: Condition '[] '[table ::: columns] 'Ungrouped
1013 -> TableConstraint schema columns
1013 -> TableConstraint schema columns
1014check condition = UnsafeTableConstraint $
1014check condition = UnsafeTableConstraint $
1015 "CHECK" <+> parenthesized (renderExpression condition)
1015 "CHECK" <+> parenthesized (renderExpression condition)
@@ -1255,7 +1255,7 @@ data ConflictClause params columns where
1255 OnConflictDoNothing :: ConflictClause params columns
1255 OnConflictDoNothing :: ConflictClause params columns
1256 OnConflictDoUpdate
1256 OnConflictDoUpdate
1257 :: NP (Aliased (UpdateExpression params columns)) columns
1257 :: NP (Aliased (UpdateExpression params columns)) columns
1258− -> (forall table. Condition params '[table ::: columns] 'Ungrouped)
1258+ -> Maybe (Condition params '[table ::: columns] 'Ungrouped)
1259 -> ConflictClause params columns
1259 -> ConflictClause params columns
1260
1260
1261renderConflictClause
1261renderConflictClause
@@ -1265,10 +1265,12 @@ renderConflictClause
1265renderConflictClause = \case
1265renderConflictClause = \case
1266 Conflict -> ""
1266 Conflict -> ""
1267 OnConflictDoNothing -> " ON CONFLICT DO NOTHING"
1267 OnConflictDoNothing -> " ON CONFLICT DO NOTHING"
1268− OnConflictDoUpdate updates wh
1268+ OnConflictDoUpdate updates whMaybe
1269 -> " ON CONFLICT DO UPDATE SET"
1269 -> " ON CONFLICT DO UPDATE SET"
1270 <+> renderCommaSeparatedMaybe renderUpdateExpression updates
1270 <+> renderCommaSeparatedMaybe renderUpdateExpression updates
1271+ <> case whMaybe of
1272+ Nothing -> ""
1271− <+> "WHERE" <+> renderExpression wh
1273+ Just wh -> " WHERE" <+> renderExpression wh
1272
1274
1273{-----------------------------------------
1275{-----------------------------------------
1274UPDATE statements
1276UPDATE statements
@@ -1290,7 +1292,7 @@ update
1290 :: (HasTable table schema columns, SListI columns, SListI results)
1292 :: (HasTable table schema columns, SListI columns, SListI results)
1291 => Alias table
1293 => Alias table
1292 -> NP (Aliased (UpdateExpression params columns)) columns
1294 -> NP (Aliased (UpdateExpression params columns)) columns
1293− -> (forall tab. Condition params '[tab ::: columns] 'Ungrouped)
1295+ -> Condition params '[tab ::: columns] 'Ungrouped
1294 -> ReturningClause params columns results
1296 -> ReturningClause params columns results
1295 -> Manipulation schema params results
1297 -> Manipulation schema params results
1296update table columns wh returning = UnsafeManipulation $
1298update table columns wh returning = UnsafeManipulation $
squeal-postgresql/test/Squeal/PostgreSQL/StatementSpec.hs+3−3
@@ -141,12 +141,12 @@ spec = do
141 statement =
141 statement =
142 insertInto #table1 (Values (2 `As` #col1 :* 4 `As` #col2 :* Nil) [])
142 insertInto #table1 (Values (2 `As` #col1 :* 4 `As` #col2 :* Nil) [])
143 (OnConflictDoUpdate
143 (OnConflictDoUpdate
144− (Set 2 `As` #col1 :* Same `As` #col2 :* Nil) (#col1 /=* #col2))
144+ (Set 2 `As` #col1 :* Same `As` #col2 :* Nil) Nothing)
145 (Returning Nil)
145 (Returning Nil)
146 statement `manipulationRenders`
146 statement `manipulationRenders`
147 "INSERT INTO table1 (col1, col2) VALUES (2, 4)\
147 "INSERT INTO table1 (col1, col2) VALUES (2, 4)\
148 \ ON CONFLICT DO UPDATE\
148 \ ON CONFLICT DO UPDATE\
149− \ SET col1 = 2 WHERE (col1 <> col2);"
149+ \ SET col1 = 2;"
150 it "correctly renders returning upsert INSERTs" $ do
150 it "correctly renders returning upsert INSERTs" $ do
151 let
151 let
152 statement :: Manipulation Tables '[] SumAndCol1
152 statement :: Manipulation Tables '[] SumAndCol1
@@ -154,7 +154,7 @@ spec = do
154 insertInto #table1 (Values (2 `As` #col1 :* 4 `As` #col2 :* Nil) [])
154 insertInto #table1 (Values (2 `As` #col1 :* 4 `As` #col2 :* Nil) [])
155 (OnConflictDoUpdate
155 (OnConflictDoUpdate
156 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
156 (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
157− (#col1 /=* #col2))
157+ (Just (#col1 /=* #col2)))
158 (Returning $ (#col1 + #col2) `As` #sum :* #col1 `As` #col1 :* Nil)
158 (Returning $ (#col1 + #col2) `As` #sum :* #col1 `As` #col1 :* Nil)
159 statement `manipulationRenders`
159 statement `manipulationRenders`
160 "INSERT INTO table1 (col1, col2) VALUES (2, 4)\
160 "INSERT INTO table1 (col1, col2) VALUES (2, 4)\