It is nearly always a good idea for a database operation to include somewhere
a type application for each table involved in the query. Selects usually should
have a type application on table.
Missing a type application:
select $ do
people <- from $ table
where_ $ people ^. #name ==. val "Robin"
pure peopleBetter:
select $ do
people <- from $ table @Person
where_ $ people ^. #name ==. val "Robin"
pure peopleEnable the OverloadedLabels Haskell extension.
Do not:
select $ do
people <- from $ table @Person
where_ $ people ^. PersonName ==. val "Robin"
pure peopleDo this:
select $ do
people <- from $ table @Person
where_ $ people ^. #name ==. val "Robin"
pure peopleModules that define Persistent entities should generally not even export their
fully qualified entity fields e.g. pattern PersonName, as there ought to be
no cause to use them.
The mkPersist settings should be:
sqlSettings {mpsFieldLabelModifier = const id}This prevents Persistent from prefixing the Haskell record field names,
in accordance with our Haskell best practices that rely on NoFieldSelectors,
DuplicateRecordFields, and OverloadedRecordDot.