Skip to content
Open
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
8 changes: 5 additions & 3 deletions persistent/Database/Persist/Sql/Orphan/PersistStore.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
Expand Down Expand Up @@ -34,6 +35,7 @@ import Data.Text (Text, unpack)
import qualified Data.Text as T
import Data.Void (Void)
import GHC.Generics (Generic)
import Language.Haskell.TH.Syntax (Lift)
import Web.HttpApiData (FromHttpApiData, ToHttpApiData)
import Web.PathPieces (PathPiece)

Expand Down Expand Up @@ -121,17 +123,17 @@ fieldDBName = fieldDB . persistFieldDef

instance PersistCore SqlBackend where
newtype BackendKey SqlBackend = SqlBackendKey { unSqlBackendKey :: Int64 }
deriving stock (Show, Read, Eq, Ord, Generic)
deriving stock (Show, Read, Eq, Ord, Generic, Lift)
deriving newtype (Num, Integral, PersistField, PersistFieldSql, PathPiece, ToHttpApiData, FromHttpApiData, Real, Enum, Bounded, A.ToJSON, A.FromJSON)

instance PersistCore SqlReadBackend where
newtype BackendKey SqlReadBackend = SqlReadBackendKey { unSqlReadBackendKey :: Int64 }
deriving stock (Show, Read, Eq, Ord, Generic)
deriving stock (Show, Read, Eq, Ord, Generic, Lift)
deriving newtype (Num, Integral, PersistField, PersistFieldSql, PathPiece, ToHttpApiData, FromHttpApiData, Real, Enum, Bounded, A.ToJSON, A.FromJSON)

instance PersistCore SqlWriteBackend where
newtype BackendKey SqlWriteBackend = SqlWriteBackendKey { unSqlWriteBackendKey :: Int64 }
deriving stock (Show, Read, Eq, Ord, Generic)
deriving stock (Show, Read, Eq, Ord, Generic, Lift)
deriving newtype (Num, Integral, PersistField, PersistFieldSql, PathPiece, ToHttpApiData, FromHttpApiData, Real, Enum, Bounded, A.ToJSON, A.FromJSON)

instance BackendCompatible SqlBackend SqlBackend where
Expand Down
8 changes: 4 additions & 4 deletions persistent/Database/Persist/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,8 +1270,8 @@ dataTypeDec mps entityMap entDef = do

stockClasses =
Set.fromList (fmap mkName
[ "Eq", "Ord", "Show", "Read", "Bounded", "Enum", "Ix", "Generic", "Data", "Typeable"
] <> [''Eq, ''Ord, ''Show, ''Read, ''Bounded, ''Enum, ''Ix, ''Generic, ''Data, ''Typeable
[ "Eq", "Ord", "Show", "Read", "Bounded", "Enum", "Ix", "Generic", "Data", "Typeable", "Lift"
] <> [''Eq, ''Ord, ''Show, ''Read, ''Bounded, ''Enum, ''Ix, ''Generic, ''Data, ''Typeable, ''Lift
]
)

Expand Down Expand Up @@ -1746,10 +1746,10 @@ mkKeyTypeDec mps entDef = do

requirePersistentExtensions

-- Always use StockStrategy for Show/Read. This means e.g. (FooKey 1) shows as ("FooKey 1"), rather than just "1"
-- Always use StockStrategy for Lift/Show/Read. This means e.g. (FooKey 1) shows as ("FooKey 1"), rather than just "1"
-- This is much better for debugging/logging purposes
-- cf. https://github.com/yesodweb/persistent/issues/1104
let alwaysStockStrategyTypeclasses = [''Show, ''Read]
let alwaysStockStrategyTypeclasses = [''Lift, ''Show, ''Read]
deriveClauses = fmap (\typeclass ->
if (not useNewtype || typeclass `elem` alwaysStockStrategyTypeclasses)
then DerivClause (Just StockStrategy) [(ConT typeclass)]
Expand Down