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

Support replaceSelect #86

Open
tysonzero opened this issue Apr 10, 2018 · 2 comments
Open

Support replaceSelect #86

tysonzero opened this issue Apr 10, 2018 · 2 comments

Comments

@tysonzero
Copy link

tysonzero commented Apr 10, 2018

It would be nice to have an insertSelect equivalent that replaces overlapping rows that already exist.

@parsonsmatt
Copy link
Collaborator

This is -- unfortunately -- database specific. MySQL and Postgres have different syntax for this functionality. So we'd need to gate that behind the .MySQL and .Postgresql modules.

@JoseD92
Copy link
Contributor

JoseD92 commented Oct 22, 2019

Based on this comments I came with a solution for postgres in a function named insertSelectWithConflict, firm (MonadIO m, PersistEntity val) => Unique val -> SqlQuery (SqlExpr (Insertion val)) -> (SqlExpr (Entity val) -> SqlExpr (Entity val) -> [SqlExpr (Update val)]) -> SqlWriteT m (), it works similar to insertSelect but allows solving conflicts on a single constraint when doing insertSelect, @tysonzero problem could be solved using this function, but he will need to specify updating all the values using the excluded values, I though I could code a replaceSelect based on insertSelectWithConflict but turns out there is no way to get the lenses for each field of a datatype on a single list from persist, so I could not generate the updates list automatically, and the other solution was building all from strings that may introduce some error along the way, given the insertSelectWithConflict already accomplishes the task with a small manual work and that it allows great flexibility I think is a good solution for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants