yesodweb / yesodweb/persistent
Rethink `Unique`
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
The issue in #1236 illustrates a need to rethink how we handle Uniques.
Ultimately, the problem comes down to conflating two uses of the type:
- Specifying a unique key for retrieval (eg
getBy :: Unique rec -> m (Maybe (Entity rec))) - Specifying a uniqueness constraint for conflict (eg
upsertBy).
The EntityField rec typ type works great for talking about the fields on an entity, so it seems like we might copy that design.
-- let's factor this out of PersistEntity while we're at it
class PersistEntity rec => PersistEntityUnique rec where
data UniqueConstraint rec :: Type -> Type
data Unique rec where
Unique :: UniqueConstraint rec typ -> typ -> Unique rec
it would be nice if we could somehow capture the actual EntityFields in the UniqueConstraint type, too. Then we could reuse things like persistFieldDef :: EntityField rec typ -> FieldDef. But, we can't promote data family constructors, as that "requires dependent types" for some reason.
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 by reading issue #1236 and the current Unique, EntityField, and PersistEntity definitions. The issue names no files or tests; done would require an agreed redesign that separates retrieval keys from conflict constraints and addresses reuse of EntityFields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- databases
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100