Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HasField and pattern synonym #1401

Merged
merged 2 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion persistent/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# Changelog for persistent

## (unreleased)
## 2.14.0.1

* [#1392](https://github.com/yesodweb/persistent/pull/1392)
* Enhance `selectList` documentation with TypeApplications examples.
* Clarify `selectSource` documentation wording.
* [#1391](https://github.com/yesodweb/persistent/pull/1391)
* Increasing quasi module test coverage, improve error assertions
* [#1401](https://github.com/yesodweb/persistent/pull/1401)
* Change `Entity` back into a regular record and drop the `HasField`
instance. This is technically a breaking change, but [the bug in GHC's
`COMPLETE` annotations](https://gitlab.haskell.org/ghc/ghc/-/issues/15681)
rendered a super common pattern a much more invasive breaking change than
anticipated. As a result, upgrading to `persistent-2.14` was untenable.

If you *did* upgrade and this broke your codebase *again*, please let me
know and I can release another patch to shim it.

## 2.14.0.0

Expand Down
20 changes: 4 additions & 16 deletions persistent/Database/Persist/Class/PersistEntity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,29 +311,17 @@ data FilterValue typ where
-- Entity backend b)@), then you must you use @SELECT ??, ??
-- WHERE ...@, and so on.
data Entity record =
Entity' (Key record) record

pattern Entity :: Key rec -> rec -> Entity rec
pattern Entity { entityKey, entityVal } = Entity' entityKey entityVal

{-# COMPLETE Entity #-}
Entity
{ entityKey :: Key record
, entityVal :: record
}

deriving instance (Generic (Key record), Generic record) => Generic (Entity record)
deriving instance (Eq (Key record), Eq record) => Eq (Entity record)
deriving instance (Ord (Key record), Ord record) => Ord (Entity record)
deriving instance (Show (Key record), Show record) => Show (Entity record)
deriving instance (Read (Key record), Read record) => Read (Entity record)

instance
( SymbolToField sym ent typ
, PersistEntity ent
)
=>
HasField sym (Entity ent) typ
where
getField ent =
getConstant ((fieldLens (symbolToField @sym @ent @typ)) Constant ent)

-- | Get list of values corresponding to given entity.
entityValues :: PersistEntity record => Entity record -> [PersistValue]
entityValues (Entity k record) =
Expand Down
2 changes: 1 addition & 1 deletion persistent/persistent.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: persistent
version: 2.14.0.0
version: 2.14.0.1
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand Down