Skip to content

Persistent Postgres upsertByWhere etc #1236

@parsonsmatt

Description

@parsonsmatt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions