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.
As documented in #1235 ,
persistent-postgresql'supsertWherefamily of functions need to have correspondingupsertByWherethat accept theUniqueconstraint in question.Unfortunately, this is a bit tricky, since a
Unique recordisn't just the fields of the record, but also the corresponding value - so a datatype like:will have a generated
Uniquedatatype like:We don't care about the value in the datatype - we only want the
UniqueDeffor it, so we can dig out the column names to specify in the clause.I'm reminded of the stupid
KnowResultstuff I did forpersistent-documentationwhere you could pass an entity's constructor, and thenKnowResultwould 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 -persistUniqueToFieldNamesis what we need, specifically, and I don't trust that to work nicely with theundefinedtrick I'm considering here.