Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type of onConflictUpdateSetWhere #645

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beam-core/Database/Beam/Backend/SQL/BeamExtensions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions beam-postgres/Database/Beam/Postgres/Full.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
14 changes: 8 additions & 6 deletions beam-sqlite/Database/Beam/Sqlite/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down