You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Uniqueness keys can be converted into a [PersistValue] (but not parsed - there's no [PersistValue] -> Either Text (Unique record)?)
Uniqueness keys have a NonEmpty (FieldNameHS, FieldNameDB) associated - like a FieldDef or EntityDef
Primary keys and Unique keys are not interchangeable.
This is too much.
Here's a sketch of how I'd like to refactor this. First, I want to have classes for things that can be rendered into a database with multiple columns, as well as a class for parsing them out.
classToPersistValuesawheretoPersistValues::a-> [PersistValue]
classFromPersistValuesawhere-- note that we may want this to be something like Either Text ([PersistValue], a)-- if the idea is that we parse multiple columns, then it makes sense to have left oversfromPersistValues:: [PersistValue] ->EitherTexta
We can pretty easily have an instance of PersistField a => ToPersistValues (Only a). And we can make tuples for parsing out lots of stuff.
In #1133 I talk about using prairie, which pulls out EntityField, persistFieldLens, and other things from PersistEntity. That may not be feasible until we get the separation of types for inserting/reading from the database. I'm not sure if that's necessary.
Then that leaves our Key and Unique stuff. #1239 I think I'll put most of my thoughts in there about how to resolve it.
So, I think, for a path forward:
Implement the To/FromPersistValues classes and make them superclasses of PersistEntity.
Figure out the uniqueness keys design
a. Do we want to make that a superclass? It doesn't make sense for all things... it is perfectly possible in SQL to have a table without a primary key.
Related to #1037 and #1239
Right now,
PersistEntityhas a ton of responsibilities. Here's the class definition (minus comments)So, a
PersistEntity recordimplies:PersistEntityBackend recordthat the type must be used with (probably can be deleted with Deprecate mpsGeneric #1250 )Keyfor the record.[PersistValue], and parsed from a[PersistValue]EntityFieldthat directly corresponds to that primary key (this is false for composite keys)entityDef Proxy :: EntityDeffor a given type.EntityFieldinstance for the type.[SomePersistField]and parse one out of a[PersistValue].Unique#1239[PersistValue](but not parsed - there's no[PersistValue] -> Either Text (Unique record)?)NonEmpty (FieldNameHS, FieldNameDB)associated - like aFieldDeforEntityDefThis is too much.
Here's a sketch of how I'd like to refactor this. First, I want to have classes for things that can be rendered into a database with multiple columns, as well as a class for parsing them out.
We can pretty easily have an instance of
PersistField a => ToPersistValues (Only a). And we can make tuples for parsing out lots of stuff.In #1133 I talk about using
prairie, which pulls outEntityField,persistFieldLens, and other things fromPersistEntity. That may not be feasible until we get the separation of types for inserting/reading from the database. I'm not sure if that's necessary.Then that leaves our
KeyandUniquestuff. #1239 I think I'll put most of my thoughts in there about how to resolve it.So, I think, for a path forward:
To/FromPersistValuesclasses and make them superclasses ofPersistEntity.a. Do we want to make that a superclass? It doesn't make sense for all things... it is perfectly possible in SQL to have a table without a primary key.