yesodweb / yesodweb/persistent
Persistent Postgres upsertByWhere etc
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
As documented in #1235 , persistent-postgresql's upsertWhere family of functions need to have corresponding upsertByWhere that accept the Unique constraint in question.
Unfortunately, this is a bit tricky, since a Unique record isn't just the fields of the record, but also the corresponding value - so a datatype like:
User
name Text
UniqueName name
will have a generated Unique datatype like:
class PersistEntity User where
-- ...
data Unique User
= UniqueName Text
We don't care about the value in the datatype - we only want the UniqueDef for it, so we can dig out the column names to specify in the clause.
I'm reminded of the stupid KnowResult stuff I did for persistent-documentation where you could pass an entity's constructor, and then KnowResult would blast through the arrows to determine the entity result type, and use that in the type inference. But we don't just want that, we also want to actually call a function on the value - persistUniqueToFieldNames is what we need, specifically, and I don't trust that to work nicely with the undefined trick I'm considering here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the persistent-postgresql upsertWhere family and the documented context in issue #1235. Investigate how the generated Unique type relates to UniqueDef and how persistUniqueToFieldNames could supply the clause columns. Done means adding corresponding upsertByWhere functions that accept a Unique constraint and correctly derive its field names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell, postgresql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100