on dev help sign in
Add back "excluded" table
f6b8b5bEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+22−21
@@ -125,18 +125,19 @@ upsert:
125>>> :{
125>>> :{
126let
126let
127 manipulation :: Manipulation
127 manipulation :: Manipulation
128− '[ "tab" ::: 'Table ('["uq" ::: 'Unique '["col1"]] :=>
128+ '[ "customers" ::: 'Table ('["uq" ::: 'Unique '["name"]] :=>
129− '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
129+ '[ "name" ::: 'NoDef :=> 'NotNull 'PGtext
130− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
130+ , "email" ::: 'NoDef :=> 'NotNull 'PGtext ])]
131− '[] '[ "sum" ::: 'NotNull 'PGint4]
131+ '[] '[]
132 manipulation =
132 manipulation =
133− insertInto #tab
133+ insertInto #customers
134− (Values (2 `as` #col1 :* 4 `as` #col2) [6 `as` #col1 :* 8 `as` #col2])
134+ (Values_ ("John Smith" `as` #name :* "john@smith.com" `as` #email))
135− (OnConflict (OnConstraint #uq) (DoUpdate (2 `as` #col1) [#col1 .== #col2]))
135+ (OnConflict (OnConstraint #uq)
136+ (DoUpdate (((#excluded ! #email) <> ";" <> (#customers ! #email)) `as` #email) []))
136− (Returning ((#col1 + #col2) `as` #sum))
137+ (Returning Nil)
137in printSQL manipulation
138in printSQL manipulation
138:}
139:}
139−INSERT INTO "tab" ("col1", "col2") VALUES (2, 4), (6, 8) ON CONFLICT ON CONSTRAINT "uq" DO UPDATE SET "col1" = 2 WHERE ("col1" = "col2") RETURNING ("col1" + "col2") AS "sum"
140+INSERT INTO "customers" ("name", "email") VALUES (E'John Smith', E'john@smith.com') ON CONFLICT ON CONSTRAINT "uq" DO UPDATE SET "email" = ("excluded"."email" || (E';' || "customers"."email"))
140
141
141query insert:
142query insert:
142
143
@@ -271,7 +272,7 @@ insertInto
271 , SOP.SListI result )
272 , SOP.SListI result )
272 => Alias tab
273 => Alias tab
273 -> QueryClause schema params columns
274 -> QueryClause schema params columns
274− -> ConflictClause schema params table
275+ -> ConflictClause tab schema params table
275 -> ReturningClause schema params row result
276 -> ReturningClause schema params row result
276 -> Manipulation schema params result
277 -> Manipulation schema params result
277insertInto tab qry conflict ret = UnsafeManipulation $
278insertInto tab qry conflict ret = UnsafeManipulation $
@@ -469,37 +470,37 @@ renderReturningClause = \case
469-- `OnConflictDoNothing` simply avoids inserting a row.
470-- `OnConflictDoNothing` simply avoids inserting a row.
470-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
471-- `OnConflictDoUpdate` updates the existing row that conflicts with the row
471-- proposed for insertion.
472-- proposed for insertion.
472−data ConflictClause schema params table where
473+data ConflictClause tab schema params table where
473− OnConflictDoRaise :: ConflictClause schema params table
474+ OnConflictDoRaise :: ConflictClause tab schema params table
474 OnConflict
475 OnConflict
475 :: ConflictTarget constraints
476 :: ConflictTarget constraints
476− -> ConflictAction schema params columns
477+ -> ConflictAction tab schema params columns
477− -> ConflictClause schema params (constraints :=> columns)
478+ -> ConflictClause tab schema params (constraints :=> columns)
478
479
479-- | Render a `ConflictClause`.
480-- | Render a `ConflictClause`.
480renderConflictClause
481renderConflictClause
481 :: SOP.SListI (TableToColumns table)
482 :: SOP.SListI (TableToColumns table)
482− => ConflictClause schema params table
483+ => ConflictClause tab schema params table
483 -> ByteString
484 -> ByteString
484renderConflictClause = \case
485renderConflictClause = \case
485 OnConflictDoRaise -> ""
486 OnConflictDoRaise -> ""
486 OnConflict target action -> " ON CONFLICT"
487 OnConflict target action -> " ON CONFLICT"
487 <+> renderConflictTarget target <+> renderConflictAction action
488 <+> renderConflictTarget target <+> renderConflictAction action
488
489
489−data ConflictAction schema params columns where
490+data ConflictAction tab schema params columns where
490− DoNothing :: ConflictAction schema params columns
491+ DoNothing :: ConflictAction tab schema params columns
491 DoUpdate
492 DoUpdate
492 :: ( row ~ ColumnsToRow columns
493 :: ( row ~ ColumnsToRow columns
493 , SOP.SListI columns
494 , SOP.SListI columns
494 , columns ~ (col0 ': cols)
495 , columns ~ (col0 ': cols)
495 , SOP.All (HasIn columns) subcolumns
496 , SOP.All (HasIn columns) subcolumns
496 , AllUnique subcolumns )
497 , AllUnique subcolumns )
497− => NP (ColumnExpression schema '[t ::: row] 'Ungrouped params) subcolumns
498+ => NP (ColumnExpression schema '[tab ::: row, "excluded" ::: row] 'Ungrouped params) subcolumns
498− -> [Condition schema '[t ::: row] 'Ungrouped params]
499+ -> [Condition schema '[tab ::: row, "excluded" ::: row] 'Ungrouped params]
499− -> ConflictAction schema params columns
500+ -> ConflictAction tab schema params columns
500
501
501renderConflictAction
502renderConflictAction
502− :: ConflictAction schema params columns
503+ :: ConflictAction tab schema params columns
503 -> ByteString
504 -> ByteString
504renderConflictAction = \case
505renderConflictAction = \case
505 DoNothing -> "DO NOTHING"
506 DoNothing -> "DO NOTHING"