Skip to content

Commit

Permalink
Remove SomePersistField (#1346)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Parsons <parsonsmatt@gmail.com>
  • Loading branch information
halogenandtoast and parsonsmatt committed Apr 12, 2022
1 parent d6453cf commit ea09601
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion persistent/Database/Persist/Class/PersistEntity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ( PersistField (Key record), ToJSON (Key record), FromJSON (Key record)
-- | Return meta-data for a given 'EntityField'.
persistFieldDef :: EntityField record typ -> FieldDef
-- | A meta-operation to get the database fields of a record.
toPersistFields :: record -> [SomePersistField]
toPersistFields :: record -> [PersistValue]
-- | A lower-level operation to convert from database values to a Haskell record.
fromPersistValues :: [PersistValue] -> Either Text record

Expand Down
6 changes: 0 additions & 6 deletions persistent/Database/Persist/Class/PersistField.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{-# LANGUAGE PatternGuards, DataKinds, TypeOperators, UndecidableInstances, GeneralizedNewtypeDeriving #-}
module Database.Persist.Class.PersistField
( PersistField (..)
, SomePersistField (..)
, getPersistMap
, OverflowNatural(..)
) where
Expand Down Expand Up @@ -452,11 +451,6 @@ getPersistMap (PersistByteString bs)
getPersistMap PersistNull = Right []
getPersistMap x = Left $ fromPersistValueError "[(Text, PersistValue)]" "map, string, bytestring or null" x

data SomePersistField = forall a. (PersistField a) => SomePersistField a
instance PersistField SomePersistField where
toPersistValue (SomePersistField a) = toPersistValue a
fromPersistValue x = fmap SomePersistField (fromPersistValue x :: Either Text Text)

instance PersistField Checkmark where
toPersistValue Active = PersistBool True
toPersistValue Inactive = PersistNull
Expand Down
6 changes: 3 additions & 3 deletions persistent/Database/Persist/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ mkToPersistFields mps ed = do
xs <- sequence $ replicate fieldCount $ newName "x"
let name = mkEntityDefName ed
pat = conp name $ fmap VarP xs
sp <- [|SomePersistField|]
sp <- [|toPersistValue|]
let bod = ListE $ fmap (AppE sp . VarE) xs
return $ normalClause [pat] bod

Expand All @@ -1303,13 +1303,13 @@ mkToPersistFields mps ed = do
goSum :: UnboundFieldDef -> Int -> Q Clause
goSum fieldDef idx = do
let name = sumConstrName mps ed fieldDef
enull <- [|SomePersistField PersistNull|]
enull <- [|PersistNull|]
let beforeCount = idx - 1
afterCount = fieldCount - idx
before = replicate beforeCount enull
after = replicate afterCount enull
x <- newName "x"
sp <- [|SomePersistField|]
sp <- [|toPersistValue|]
let body = ListE $ mconcat
[ before
, [sp `AppE` VarE x]
Expand Down
1 change: 0 additions & 1 deletion persistent/Database/Persist/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module Database.Persist.Types
-- database and Haskell types.
, module Database.Persist.PersistValue
-- * Other Useful Stuff
, SomePersistField (..)
, Update (..)
, BackendSpecificUpdate
, SelectOpt (..)
Expand Down
2 changes: 1 addition & 1 deletion persistent/test/Database/Persist/TH/MigrationOnlySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec = describe "MigrationOnlySpec" $ do
it "should have one field" $ do
map toPersistValue (toPersistFields (HasMigrationOnly "asdf"))
`shouldBe`
map toPersistValue [SomePersistField ("asdf" :: Text)]
[PersistText ("asdf" :: Text)]
describe "fromPersistValues" $ do
it "should work with only item in list" $ do
fromPersistValues [PersistText "Hello"]
Expand Down

0 comments on commit ea09601

Please sign in to comment.