PersistUnique

Please read the general Persistent documentation to learn how to create
Unique keys.
SQL backends automatically create uniqueness constraints, but for MongoDB you must manually place a unique index on the field.

Some functions in this module (insertUnique, insertBy, and replaceUnique) first query the unique indexes to check for conflicts.
You could instead optimistically attempt to perform the operation (e.g. replace instead of replaceUnique). However,

there is some fragility to trying to catch the correct exception and determing the column of failure.

A modification of getBy, which takes the PersistEntity itself instead
of a Unique value. Returns a value matching one of the unique keys. This
function makes the most sense on entities with a single Unique
constructor.

Attempt to replace the record of the given key with the given new record.
First query the unique fields to make sure the replacement maintains uniqueness constraints.
Return Nothing if the replacement was made.
If uniqueness is violated, return a Just with the Unique violation

PersistEntity

Persistent serialized Haskell records to the database.
A Database Entity (A row in SQL, a document in MongoDB, etc)
corresponds to a Key plus a Haskell record.

For every Haskell record type stored in the database there is a corresponding PersistEntity instance.
An instance of PersistEntity contains meta-data for the record.
PersistEntity also helps abstract over different record types.
That way the same query interface can return a PersistEntity, with each query returning different types of Haskell records.

Some advanced type system capabilities are used to make this process type-safe.
Persistent users usually don't need to understand the class associated data and functions.