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.
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:
getBy :: Unique rec -> m (Maybe (Entity rec)))upsertBy).The
EntityField rec typtype works great for talking about the fields on an entity, so it seems like we might copy that design.it would be nice if we could somehow capture the actual
EntityFields in theUniqueConstrainttype, too. Then we could reuse things likepersistFieldDef :: EntityField rec typ -> FieldDef. But, we can't promote data family constructors, as that "requires dependent types" for some reason.