From 65d33d28508590b62f75ccb56212e27c23ea0b19 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Mon, 7 Nov 2022 06:36:54 -0800 Subject: [PATCH] Fix type of onConflictUpdateSetWhere --- .../Database/Beam/Backend/SQL/BeamExtensions.hs | 2 +- beam-postgres/Database/Beam/Postgres/Full.hs | 5 +++-- beam-sqlite/Database/Beam/Sqlite/Connection.hs | 14 ++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/beam-core/Database/Beam/Backend/SQL/BeamExtensions.hs b/beam-core/Database/Beam/Backend/SQL/BeamExtensions.hs index ae09b963..1ab37b50 100644 --- a/beam-core/Database/Beam/Backend/SQL/BeamExtensions.hs +++ b/beam-core/Database/Beam/Backend/SQL/BeamExtensions.hs @@ -178,7 +178,7 @@ class BeamSqlBackend be => BeamHasInsertOnConflict be where onConflictUpdateSetWhere :: Beamable table => (forall s. table (QField s) -> table (QExpr be s) -> QAssignment be s) - -> (forall s. table (QField s) -> table (QExpr be s) -> QExpr be s Bool) + -> (forall s. table (QExpr be s) -> table (QExpr be s) -> QExpr be s Bool) -> SqlConflictAction be table newtype InaccessibleQAssignment be = InaccessibleQAssignment diff --git a/beam-postgres/Database/Beam/Postgres/Full.hs b/beam-postgres/Database/Beam/Postgres/Full.hs index 57b0115f..8c190f41 100644 --- a/beam-postgres/Database/Beam/Postgres/Full.hs +++ b/beam-postgres/Database/Beam/Postgres/Full.hs @@ -54,9 +54,9 @@ module Database.Beam.Postgres.Full ) where import Database.Beam hiding (insert, insertValues) -import Database.Beam.Query.Internal import Database.Beam.Backend.SQL import Database.Beam.Backend.SQL.BeamExtensions +import Database.Beam.Query.Internal import Database.Beam.Schema.Tables import Database.Beam.Postgres.Types @@ -475,7 +475,8 @@ instance BeamHasInsertOnConflict Postgres where onConflictUpdateSetWhere mkAssignments where_ = PgConflictAction $ \tbl -> let QAssignment assignments = mkAssignments tbl tblExcluded - QExpr where_' = where_ tbl tblExcluded + QExpr where_' = where_ tblExpr tblExcluded + tblExpr = changeBeamRep (\(Columnar' (QField _ tblName nm)) -> Columnar' (QExpr (\_ -> fieldE (qualifiedField tblName nm)))) tbl tblExcluded = changeBeamRep (\(Columnar' (QField _ _ nm)) -> Columnar' (QExpr (\_ -> fieldE (qualifiedField "excluded" nm)))) tbl assignmentSyntaxes = diff --git a/beam-sqlite/Database/Beam/Sqlite/Connection.hs b/beam-sqlite/Database/Beam/Sqlite/Connection.hs index 519c4a64..7af4ad05 100644 --- a/beam-sqlite/Database/Beam/Sqlite/Connection.hs +++ b/beam-sqlite/Database/Beam/Sqlite/Connection.hs @@ -497,12 +497,14 @@ instance Beam.BeamHasInsertOnConflict Sqlite where in commas $ map emitAssignment assignments ] onConflictUpdateSetWhere makeAssignments makeWhere = - SqliteConflictAction $ \table -> mconcat - [ unSqliteConflictAction (Beam.onConflictUpdateSet makeAssignments) table - , emit " WHERE " - , let QExpr mkE = makeWhere table $ excluded table - in fromSqliteExpression $ mkE "t" - ] + SqliteConflictAction $ \table -> + let tableExpr = changeBeamRep (\(Columnar' (QField _ _ nm)) -> Columnar' (QExpr (\_ -> fieldE (unqualifiedField nm)))) table + in mconcat + [ unSqliteConflictAction (Beam.onConflictUpdateSet makeAssignments) table + , emit " WHERE " + , let QExpr mkE = makeWhere tableExpr $ excluded table + in fromSqliteExpression $ mkE "t" + ] excluded :: forall table s