yesodweb / yesodweb/persistent

Rethink `Unique`

Open
#1,239 5 comments 0 reactions 0 assignees View on GitHub

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:

  1. Specifying a unique key for retrieval (eg getBy :: Unique rec -> m (Maybe (Entity rec)))
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.