diff --git a/persistent-mongoDB/test/MongoInit.hs b/persistent-mongoDB/test/MongoInit.hs index c7bc75699..380684d92 100644 --- a/persistent-mongoDB/test/MongoInit.hs +++ b/persistent-mongoDB/test/MongoInit.hs @@ -83,7 +83,7 @@ _debugOn :: Bool _debugOn = True persistSettings :: MkPersistSettings -persistSettings = (mkPersistSettings $ ConT ''Context) { mpsGeneric = True } +persistSettings = mkPersistSettings $ ConT ''Context dbName :: Text dbName = "persistent" diff --git a/persistent-mysql/test/MyInit.hs b/persistent-mysql/test/MyInit.hs index ddd50c83f..7c69dcd7d 100644 --- a/persistent-mysql/test/MyInit.hs +++ b/persistent-mysql/test/MyInit.hs @@ -115,7 +115,7 @@ _debugOn :: Bool _debugOn = False persistSettings :: MkPersistSettings -persistSettings = sqlSettings { mpsGeneric = True } +persistSettings = sqlSettings type BackendMonad = SqlBackend diff --git a/persistent-postgresql/test/PgInit.hs b/persistent-postgresql/test/PgInit.hs index dec295ad7..5251564c5 100644 --- a/persistent-postgresql/test/PgInit.hs +++ b/persistent-postgresql/test/PgInit.hs @@ -136,7 +136,7 @@ dockerPg = do _ -> Nothing persistSettings :: MkPersistSettings -persistSettings = sqlSettings { mpsGeneric = True } +persistSettings = sqlSettings runConn :: MonadUnliftIO m => SqlPersistT (LoggingT m) t -> m () runConn f = runConn_ f >>= const (return ()) diff --git a/persistent-qq/test/PersistentTestModels.hs b/persistent-qq/test/PersistentTestModels.hs index a3252c587..0a1cc086f 100644 --- a/persistent-qq/test/PersistentTestModels.hs +++ b/persistent-qq/test/PersistentTestModels.hs @@ -27,7 +27,7 @@ import PersistTestPetCollarType import PersistTestPetType share - [ mkPersist sqlSettings { mpsGeneric = True } + [ mkPersist sqlSettings , mkMigrate "testMigrate" ] [persistUpperCase| @@ -110,10 +110,7 @@ share |] -deriving instance Show (BackendKey backend) => Show (PetGeneric backend) -deriving instance Eq (BackendKey backend) => Eq (PetGeneric backend) - -share [ mkPersist sqlSettings { mpsPrefixFields = False, mpsGeneric = True } +share [ mkPersist sqlSettings { mpsPrefixFields = False } , mkMigrate "noPrefixMigrate" ] [persistLowerCase| NoPrefix1 @@ -127,12 +124,6 @@ NoPrefix2 deriving Show Eq |] -deriving instance Show (BackendKey backend) => Show (NoPrefix1Generic backend) -deriving instance Eq (BackendKey backend) => Eq (NoPrefix1Generic backend) - -deriving instance Show (BackendKey backend) => Show (NoPrefix2Generic backend) -deriving instance Eq (BackendKey backend) => Eq (NoPrefix2Generic backend) - -- | Reverses the order of the fields of an entity. Used to test -- @??@ placeholders of 'rawSql'. newtype ReverseFieldOrder a = RFO {unRFO :: a} deriving (Eq, Show) @@ -164,15 +155,13 @@ instance (PersistEntity a) => PersistEntity (ReverseFieldOrder a) where persistIdField = error "ReverseFieldOrder.persistIdField" fieldLens x = error "ReverseFieldOrder.fieldLens" -cleanDB - :: (MonadIO m, PersistQuery backend, PersistStoreWrite (BaseBackend backend)) - => ReaderT backend m () +cleanDB :: (MonadIO m) => SqlPersistT m () cleanDB = do - deleteWhere ([] :: [Filter (PersonGeneric backend)]) - deleteWhere ([] :: [Filter (Person1Generic backend)]) - deleteWhere ([] :: [Filter (PetGeneric backend)]) - deleteWhere ([] :: [Filter (MaybeOwnedPetGeneric backend)]) - deleteWhere ([] :: [Filter (NeedsPetGeneric backend)]) - deleteWhere ([] :: [Filter (OutdoorPetGeneric backend)]) - deleteWhere ([] :: [Filter (UserPTGeneric backend)]) - deleteWhere ([] :: [Filter (EmailPTGeneric backend)]) + deleteWhere ([] :: [Filter Person]) + deleteWhere ([] :: [Filter Person1]) + deleteWhere ([] :: [Filter Pet]) + deleteWhere ([] :: [Filter MaybeOwnedPet]) + deleteWhere ([] :: [Filter NeedsPet]) + deleteWhere ([] :: [Filter OutdoorPet]) + deleteWhere ([] :: [Filter UserPT]) + deleteWhere ([] :: [Filter EmailPT]) diff --git a/persistent-sqlite/test/SqliteInit.hs b/persistent-sqlite/test/SqliteInit.hs index 2c54ec8bd..c63e19af2 100644 --- a/persistent-sqlite/test/SqliteInit.hs +++ b/persistent-sqlite/test/SqliteInit.hs @@ -83,7 +83,7 @@ _debugOn :: Bool _debugOn = False persistSettings :: MkPersistSettings -persistSettings = sqlSettings { mpsGeneric = True } +persistSettings = sqlSettings type BackendMonad = SqlBackend diff --git a/persistent-test/src/CompositeTest.hs b/persistent-test/src/CompositeTest.hs index 2ec18f726..df4406b11 100644 --- a/persistent-test/src/CompositeTest.hs +++ b/persistent-test/src/CompositeTest.hs @@ -10,8 +10,7 @@ import Data.Maybe (isJust) import Init --- mpsGeneric = False is due to a bug or at least lack of a feature in mkKeyTypeDec TH.hs -share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "compositeMigrate"] [persistLowerCase| +share [mkPersist persistSettings, mkMigrate "compositeMigrate"] [persistLowerCase| TestParent name String maxlen=20 name2 String maxlen=20 diff --git a/persistent-test/src/CustomPersistFieldTest.hs b/persistent-test/src/CustomPersistFieldTest.hs index 211524924..466ec8608 100644 --- a/persistent-test/src/CustomPersistFieldTest.hs +++ b/persistent-test/src/CustomPersistFieldTest.hs @@ -5,13 +5,13 @@ module CustomPersistFieldTest (specsWith, customFieldMigrate) where import CustomPersistField import Init -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "customFieldMigrate"] [persistLowerCase| +share [mkPersist sqlSettings, mkMigrate "customFieldMigrate"] [persistLowerCase| BlogPost article Markdown deriving Show Eq |] -specsWith :: Runner backend m => RunDb backend m -> Spec +specsWith :: Runner SqlBackend m => RunDb SqlBackend m -> Spec specsWith runDB = describe "Custom persist field" $ do it "should read what it wrote" $ runDB $ do let originalBlogPost = BlogPost "article" diff --git a/persistent-test/src/CustomPrimaryKeyReferenceTest.hs b/persistent-test/src/CustomPrimaryKeyReferenceTest.hs index 2bfcb8251..26288cccb 100644 --- a/persistent-test/src/CustomPrimaryKeyReferenceTest.hs +++ b/persistent-test/src/CustomPrimaryKeyReferenceTest.hs @@ -6,8 +6,7 @@ module CustomPrimaryKeyReferenceTest where import Init --- mpsGeneric = False is due to a bug or at least lack of a feature in mkKeyTypeDec TH.hs -share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "migration"] [persistLowerCase| +share [mkPersist persistSettings, mkMigrate "migration"] [persistLowerCase| Tweet tweetId Int statusText Text sqltype=varchar(170) diff --git a/persistent-test/src/DataTypeTest.hs b/persistent-test/src/DataTypeTest.hs index b1ee4abc5..1da33f90f 100644 --- a/persistent-test/src/DataTypeTest.hs +++ b/persistent-test/src/DataTypeTest.hs @@ -43,10 +43,8 @@ DataTypeTable no-json utc UTCTime |] -cleanDB' - :: - ( MonadIO m, PersistStoreWrite (BaseBackend backend), PersistQuery backend) => ReaderT backend m () -cleanDB' = deleteWhere ([] :: [Filter (DataTypeTableGeneric backend)]) +cleanDB' :: (MonadIO m) => SqlPersistT m () +cleanDB' = deleteWhere ([] :: [Filter DataTypeTable]) roundFn :: RealFrac a => a -> Integer roundFn = round @@ -81,14 +79,10 @@ instance Arbitrary DataTypeTable where specsWith :: forall db backend m entity. ( db ~ ReaderT backend m - , PersistStoreRead backend + , backend ~ SqlBackend , PersistEntity entity - , PersistEntityBackend entity ~ BaseBackend backend + , PersistEntityBackend entity ~ SqlBackend , Arbitrary entity - , PersistStoreWrite backend - , PersistStoreWrite (BaseBackend backend) - , PersistQueryWrite (BaseBackend backend) - , PersistQueryWrite backend , MonadFail m , MonadIO m ) diff --git a/persistent-test/src/EmbedOrderTest.hs b/persistent-test/src/EmbedOrderTest.hs index 7fdc0ffad..099e3faa8 100644 --- a/persistent-test/src/EmbedOrderTest.hs +++ b/persistent-test/src/EmbedOrderTest.hs @@ -10,7 +10,7 @@ import Init debug :: Show s => s -> s debug x = trace (show x) x -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "embedOrderMigrate"] [persistUpperCase| +share [mkPersist sqlSettings, mkMigrate "embedOrderMigrate"] [persistUpperCase| Foo sql=foo_embed_order bars [Bar] deriving Eq Show @@ -21,12 +21,12 @@ Bar sql=bar_embed_order deriving Eq Show |] -cleanDB :: Runner backend m => ReaderT backend m () +cleanDB :: Runner SqlBackend m => ReaderT SqlBackend m () cleanDB = do - deleteWhere ([] :: [Filter (FooGeneric backend)]) - deleteWhere ([] :: [Filter (BarGeneric backend)]) + deleteWhere ([] :: [Filter Foo]) + deleteWhere ([] :: [Filter Bar]) -specsWith :: Runner backend m => RunDb backend m -> Spec +specsWith :: Runner SqlBackend m => RunDb SqlBackend m -> Spec specsWith db = describe "embedded entities" $ do it "preserves ordering" $ db $ do let foo = Foo [Bar "b" "u" "g"] diff --git a/persistent-test/src/EmbedTest.hs b/persistent-test/src/EmbedTest.hs index 387c4813d..396f88ede 100644 --- a/persistent-test/src/EmbedTest.hs +++ b/persistent-test/src/EmbedTest.hs @@ -28,7 +28,7 @@ instance PersistField a => PersistField (NonEmpty a) where (l:ls) -> Right (l:|ls) -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "embedMigrate"] [persistUpperCase| +share [mkPersist sqlSettings, mkMigrate "embedMigrate"] [persistUpperCase| OnlyName name Text @@ -137,18 +137,18 @@ share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "embedMigrate"] [ |] cleanDB :: (PersistQuery backend, PersistEntityBackend HasMap ~ backend, MonadIO m) => ReaderT backend m () cleanDB = do - deleteWhere ([] :: [Filter (HasEmbedGeneric backend)]) - deleteWhere ([] :: [Filter (HasEmbedsGeneric backend)]) - deleteWhere ([] :: [Filter (HasListEmbedGeneric backend)]) - deleteWhere ([] :: [Filter (HasSetEmbedGeneric backend)]) - deleteWhere ([] :: [Filter (UserGeneric backend)]) - deleteWhere ([] :: [Filter (HasMapGeneric backend)]) - deleteWhere ([] :: [Filter (HasListGeneric backend)]) - deleteWhere ([] :: [Filter (EmbedsHasMapGeneric backend)]) - deleteWhere ([] :: [Filter (ListEmbedGeneric backend)]) - deleteWhere ([] :: [Filter (ARecordGeneric backend)]) - deleteWhere ([] :: [Filter (AccountGeneric backend)]) - deleteWhere ([] :: [Filter (HasNestedListGeneric backend)]) + deleteWhere ([] :: [Filter (HasEmbed)]) + deleteWhere ([] :: [Filter (HasEmbeds)]) + deleteWhere ([] :: [Filter (HasListEmbed)]) + deleteWhere ([] :: [Filter (HasSetEmbed)]) + deleteWhere ([] :: [Filter (User)]) + deleteWhere ([] :: [Filter (HasMap)]) + deleteWhere ([] :: [Filter (HasList)]) + deleteWhere ([] :: [Filter (EmbedsHasMap)]) + deleteWhere ([] :: [Filter (ListEmbed)]) + deleteWhere ([] :: [Filter (ARecord)]) + deleteWhere ([] :: [Filter (Account)]) + deleteWhere ([] :: [Filter (HasNestedList)]) _unlessM :: MonadIO m => IO Bool -> m () -> m () _unlessM predicate body = do diff --git a/persistent-test/src/EmptyEntityTest.hs b/persistent-test/src/EmptyEntityTest.hs index 5d307f9d5..069eb0c9a 100644 --- a/persistent-test/src/EmptyEntityTest.hs +++ b/persistent-test/src/EmptyEntityTest.hs @@ -8,23 +8,23 @@ import Database.Persist.TH import Init -- Test lower case names -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "migration"] [persistLowerCase| +share [mkPersist sqlSettings, mkMigrate "migration"] [persistLowerCase| EmptyEntity |] cleanDB :: - ( PersistQueryWrite backend + ( PersistQueryWrite SqlBackend , MonadIO m - , PersistStoreWrite (BaseBackend backend) + , PersistStoreWrite (BaseBackend SqlBackend) ) - => ReaderT backend m () -cleanDB = deleteWhere ([] :: [Filter (EmptyEntityGeneric backend)]) + => ReaderT SqlBackend m () +cleanDB = deleteWhere ([] :: [Filter EmptyEntity]) specsWith - :: Runner backend m - => RunDb backend m - -> Maybe (ReaderT backend m a) + :: Runner SqlBackend m + => RunDb SqlBackend m + -> Maybe (ReaderT SqlBackend m a) -> Spec specsWith runConn mmigrate = describe "empty entity" $ it "inserts" $ asIO $ runConn $ do diff --git a/persistent-test/src/EntityEmbedTest.hs b/persistent-test/src/EntityEmbedTest.hs index f29ad9622..0422d30e4 100644 --- a/persistent-test/src/EntityEmbedTest.hs +++ b/persistent-test/src/EntityEmbedTest.hs @@ -5,7 +5,7 @@ module EntityEmbedTest where -- this is used in EmbedTest import Init -mkPersist persistSettings { mpsGeneric = True } [persistUpperCase| +mkPersist persistSettings [persistUpperCase| ARecord name Text deriving Show Eq Read Ord diff --git a/persistent-test/src/ForeignKey.hs b/persistent-test/src/ForeignKey.hs index fa1250604..baa68aa37 100644 --- a/persistent-test/src/ForeignKey.hs +++ b/persistent-test/src/ForeignKey.hs @@ -10,8 +10,7 @@ import Init import Database.Persist.EntityDef.Internal (entityExtra) --- mpsGeneric = False is due to a bug or at least lack of a feature in mkKeyTypeDec TH.hs -share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "compositeMigrate"] [persistLowerCase| +share [mkPersist persistSettings, mkMigrate "compositeMigrate"] [persistLowerCase| SimpleCascadeChild ref SimpleCascadeId OnDeleteCascade deriving Show Eq diff --git a/persistent-test/src/HtmlTest.hs b/persistent-test/src/HtmlTest.hs index f5f36ff1b..0a8d4a54c 100644 --- a/persistent-test/src/HtmlTest.hs +++ b/persistent-test/src/HtmlTest.hs @@ -11,20 +11,20 @@ import Text.Blaze.Html.Renderer.Text import Init -- Test lower case names -share [mkPersist persistSettings { mpsGeneric = True }, mkMigrate "htmlMigrate"] [persistLowerCase| +share [mkPersist persistSettings, mkMigrate "htmlMigrate"] [persistLowerCase| HtmlTable html Html deriving |] -cleanDB :: Runner backend m => ReaderT backend m () +cleanDB :: Runner SqlBackend m => ReaderT SqlBackend m () cleanDB = do - deleteWhere ([] :: [Filter (HtmlTableGeneric backend)]) + deleteWhere ([] :: [Filter HtmlTable]) specsWith - :: Runner backend m - => RunDb backend m - -> Maybe (ReaderT backend m a) + :: Runner SqlBackend m + => RunDb SqlBackend m + -> Maybe (ReaderT SqlBackend m a) -> Spec specsWith runConn mmigrate = describe "html" $ do it "works" $ asIO $ runConn $ do diff --git a/persistent-test/src/Init.hs b/persistent-test/src/Init.hs index 62bb4fc84..6809f0d6c 100644 --- a/persistent-test/src/Init.hs +++ b/persistent-test/src/Init.hs @@ -155,7 +155,7 @@ isCI = do persistSettings :: MkPersistSettings -persistSettings = sqlSettings { mpsGeneric = True } +persistSettings = sqlSettings instance Arbitrary PersistValue where arbitrary = PersistInt64 `fmap` choose (0, maxBound) diff --git a/persistent-test/src/LargeNumberTest.hs b/persistent-test/src/LargeNumberTest.hs index a59f29779..d814371cb 100644 --- a/persistent-test/src/LargeNumberTest.hs +++ b/persistent-test/src/LargeNumberTest.hs @@ -5,7 +5,7 @@ import Data.Word import Init -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "numberMigrate"] [persistLowerCase| +share [mkPersist sqlSettings, mkMigrate "numberMigrate"] [persistLowerCase| Number intx Int int32 Int32 @@ -16,11 +16,11 @@ share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "numberMigrate"] |] cleanDB - :: Runner backend m => ReaderT backend m () + :: Runner SqlBackend m => ReaderT SqlBackend m () cleanDB = do - deleteWhere ([] :: [Filter (NumberGeneric backend)]) + deleteWhere ([] :: [Filter Number]) -specsWith :: Runner backend m => RunDb backend m -> Spec +specsWith :: Runner SqlBackend m => RunDb SqlBackend m -> Spec specsWith runDb = describe "Large Numbers" $ do it "preserves their values in the database" $ runDb $ do let go x = do diff --git a/persistent-test/src/MaxLenTest.hs b/persistent-test/src/MaxLenTest.hs index 917b12138..db772a18b 100644 --- a/persistent-test/src/MaxLenTest.hs +++ b/persistent-test/src/MaxLenTest.hs @@ -7,7 +7,7 @@ import Data.String (IsString) import Init -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "maxlenMigrate"] [persistLowerCase| +share [mkPersist sqlSettings, mkMigrate "maxlenMigrate"] [persistLowerCase| MaxLen text1 Text text2 Text maxlen=3 @@ -24,7 +24,7 @@ share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "maxlenMigrate"] deriving Show Eq |] -specsWith :: Runner backend m => RunDb backend m -> Spec +specsWith :: Runner SqlBackend m => RunDb SqlBackend m -> Spec specsWith runDb = describe "Maximum length attribute" $ do it "truncates values that are too long" $ runDb $ do let t1 = MaxLen a a a a a a diff --git a/persistent-test/src/MaybeFieldDefsTest.hs b/persistent-test/src/MaybeFieldDefsTest.hs index 9242ba4b7..1398f3e63 100644 --- a/persistent-test/src/MaybeFieldDefsTest.hs +++ b/persistent-test/src/MaybeFieldDefsTest.hs @@ -8,14 +8,14 @@ import Data.String (IsString) import Init -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "maybeFieldDefMigrate"] [persistLowerCase| +share [mkPersist sqlSettings, mkMigrate "maybeFieldDefMigrate"] [persistLowerCase| MaybeFieldDefEntity optionalString (Maybe String) optionalInt (Maybe Int) deriving Eq Show |] -specsWith :: (Runner backend m) => RunDb backend m -> Spec +specsWith :: (Runner SqlBackend m) => RunDb SqlBackend m -> Spec specsWith runDb = describe "Maybe Field Definitions" $ do it "runs appropriate migrations" $ runDb $ do emptyEntity <- insert $ MaybeFieldDefEntity Nothing Nothing diff --git a/persistent-test/src/MigrationOnlyTest.hs b/persistent-test/src/MigrationOnlyTest.hs index 850f2aec8..b6064bf6e 100644 --- a/persistent-test/src/MigrationOnlyTest.hs +++ b/persistent-test/src/MigrationOnlyTest.hs @@ -10,7 +10,7 @@ import Database.Persist.TH import Init import Database.Persist.EntityDef -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "migrateAll1"] [persistLowerCase| +share [mkPersist sqlSettings, mkMigrate "migrateAll1"] [persistLowerCase| TwoField1 sql=two_field field1 Int field2 T.Text @@ -18,7 +18,7 @@ TwoField1 sql=two_field deriving Eq Show |] -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "migrateAll2"] [persistLowerCase| +share [mkPersist sqlSettings, mkMigrate "migrateAll2"] [persistLowerCase| TwoField field1 Int field2 T.Text @@ -31,9 +31,9 @@ Referencing |] specsWith - :: (MonadIO m, PersistQueryWrite backend, PersistStoreWrite backend, PersistQueryWrite (BaseBackend backend)) - => RunDb backend m - -> Maybe (ReaderT backend m a) + :: (MonadIO m) + => RunDb SqlBackend m + -> Maybe (SqlPersistT m a) -> Spec specsWith runDb mmigrate = describe "MigrationOnly field" $ do let @@ -64,4 +64,4 @@ specsWith runDb mmigrate = describe "MigrationOnly field" $ do tid <- insert tf mtf <- get tid liftIO $ mtf @?= Just tf - deleteWhere ([] :: [Filter (TwoFieldGeneric backend)]) + deleteWhere ([] :: [Filter TwoField]) diff --git a/persistent-test/src/PersistUniqueTest.hs b/persistent-test/src/PersistUniqueTest.hs index 848b40a76..e00675d74 100644 --- a/persistent-test/src/PersistUniqueTest.hs +++ b/persistent-test/src/PersistUniqueTest.hs @@ -4,8 +4,7 @@ module PersistUniqueTest where import Init --- mpsGeneric = False is due to a bug or at least lack of a feature in mkKeyTypeDec TH.hs -share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "migration"] [persistLowerCase| +share [mkPersist persistSettings, mkMigrate "migration"] [persistLowerCase| Fo foo Int bar Int diff --git a/persistent-test/src/PersistentTest.hs b/persistent-test/src/PersistentTest.hs index c9ecbe212..e462ceaad 100644 --- a/persistent-test/src/PersistentTest.hs +++ b/persistent-test/src/PersistentTest.hs @@ -40,9 +40,7 @@ catchPersistException action errValue = do return res filterOrSpecs - :: forall m backend. Runner backend m - => RunDb backend m - -> Spec + :: forall m . Runner SqlBackend m => RunDb SqlBackend m -> Spec filterOrSpecs runDb = describe "FilterOr" $ do it "FilterOr []" $ runDb $ do let p = Person "z" 1 Nothing @@ -74,7 +72,7 @@ type Getting r s t a b = (a -> Constant r b) -> s -> Constant r t view :: s -> Getting a s t a b -> a view s l = getConstant (l Constant s) -safeToRemoveSpec :: forall backend m. Runner backend m => RunDb backend m -> Spec +safeToRemoveSpec :: forall m. Runner SqlBackend m => RunDb SqlBackend m -> Spec safeToRemoveSpec runDb = do describe "DudeWeirdColumns" $ do it "can insert and get" $ do @@ -90,7 +88,7 @@ safeToRemoveSpec runDb = do ] runDb $ putMany ms -specsWith :: forall backend m. Runner backend m => RunDb backend m -> Spec +specsWith :: forall m. Runner SqlBackend m => RunDb SqlBackend m -> Spec specsWith runDb = describe "persistent" $ do describe "SafeToRemove" (safeToRemoveSpec runDb) it "fieldLens" $ do @@ -200,7 +198,7 @@ specsWith runDb = describe "persistent" $ do fmap entityVal mq @== Just q it "!=." $ runDb $ do - deleteWhere ([] :: [Filter (PersonGeneric backend)]) + deleteWhere ([] :: [Filter Person]) let mic = Person "Michael" 25 Nothing insert_ mic let eli = Person "Eliezer" 25 (Just "Red") @@ -217,7 +215,7 @@ specsWith runDb = describe "persistent" $ do it "Double Maybe" $ runDb $ do - deleteWhere ([] :: [Filter (PersonMayGeneric backend)]) + deleteWhere ([] :: [Filter PersonMay]) let mic = PersonMay (Just "Michael") Nothing insert_ mic let eli = PersonMay (Just "Eliezer") (Just "Red") @@ -228,7 +226,7 @@ specsWith runDb = describe "persistent" $ do map entityVal pne @== [eli] it "and/or" $ runDb $ do - deleteWhere ([] :: [Filter (Person1Generic backend)]) + deleteWhere ([] :: [Filter Person1]) insertMany_ [ Person1 "Michael" 25 , Person1 "Miriam" 25 , Person1 "Michael" 30 @@ -494,14 +492,14 @@ specsWith runDb = describe "persistent" $ do e4 @== Nothing it "insertMany_ with no arguments" $ runDb $ do - _ <- insertMany_ ([] :: [PersonGeneric backend]) - rows <- (count ([] :: [Filter (PersonGeneric backend)]) :: ReaderT backend m Int) + _ <- insertMany_ ([] :: [Person]) + rows <- count ([] :: [Filter Person]) rows @== 0 - _ <- insertMany ([] :: [PersonGeneric backend]) - rows2 <- count ([] :: [Filter (PersonGeneric backend)]) + _ <- insertMany ([] :: [Person]) + rows2 <- count ([] :: [Filter Person]) rows2 @== 0 - _ <- insertEntityMany ([] :: [Entity (PersonGeneric backend)]) - rows3 <- count ([] :: [Filter (PersonGeneric backend)]) + _ <- insertEntityMany ([] :: [Entity Person]) + rows3 <- count ([] :: [Filter Person]) rows3 @== 0 it "insertEntityMany" $ runDb $ do @@ -512,7 +510,7 @@ specsWith runDb = describe "persistent" $ do p4 = Entity id4 $ Person "insertEntityMany4" 3 Nothing p5 = Entity id5 $ Person "insertEntityMany5" 3 Nothing insertEntityMany [p1,p2,p3,p4,p5] - rows <- count ([] :: [Filter (PersonGeneric backend)]) + rows <- count ([] :: [Filter Person]) rows @== 5 it "insertBy" $ runDb $ do diff --git a/persistent-test/src/PersistentTestModels.hs b/persistent-test/src/PersistentTestModels.hs index 4825e6c3d..6b97046da 100644 --- a/persistent-test/src/PersistentTestModels.hs +++ b/persistent-test/src/PersistentTestModels.hs @@ -19,7 +19,7 @@ import Data.Text (append) -- just need to ensure this compiles import PersistentTestModelsImports() -share [mkPersist persistSettings { mpsGeneric = True }, mkMigrate "testMigrate"] [persistUpperCase| +share [mkPersist persistSettings, mkMigrate "testMigrate"] [persistUpperCase| -- Dedented comment -- Header-level comment @@ -44,14 +44,16 @@ share [mkPersist persistSettings { mpsGeneric = True }, mkMigrate "testMigrate" name Text Maybe color Text Maybe deriving Show Eq + Pet ownerId PersonId name Text - -- deriving Show Eq -- Dedented comment -- Header-level comment -- Indented comment type PetType + deriving Show Eq + MaybeOwnedPet ownerId PersonId Maybe name Text @@ -113,6 +115,7 @@ share [mkPersist persistSettings { mpsGeneric = True }, mkMigrate "testMigrate" -- | Fields should be documentable. name String parent RelationshipId Maybe + deriving Show Eq MutA mutB MutBId @@ -122,25 +125,20 @@ share [mkPersist persistSettings { mpsGeneric = True }, mkMigrate "testMigrate" |] -deriving instance Show (BackendKey backend) => Show (PetGeneric backend) -deriving instance Eq (BackendKey backend) => Eq (PetGeneric backend) - -deriving instance Show (BackendKey backend) => Show (RelationshipGeneric backend) -deriving instance Eq (BackendKey backend) => Eq (RelationshipGeneric backend) - share [mkPersist persistSettings { mpsPrefixFields = False , mpsFieldLabelModifier = \_ _ -> "" -- this field is ignored when mpsPrefixFields == False , mpsConstraintLabelModifier = \_ _ -> "" -- this field is ignored when mpsPrefixFields == False - , mpsGeneric = True } , mkMigrate "noPrefixMigrate" ] [persistLowerCase| NoPrefix1 someFieldName Int + deriving Eq Show NoPrefix2 someOtherFieldName Int unprefixedRef NoPrefix1Id + deriving Eq Show +NoPrefixSum unprefixedLeft Int unprefixedRight String @@ -148,12 +146,6 @@ NoPrefix2 |] -deriving instance Show (BackendKey backend) => Show (NoPrefix1Generic backend) -deriving instance Eq (BackendKey backend) => Eq (NoPrefix1Generic backend) - -deriving instance Show (BackendKey backend) => Show (NoPrefix2Generic backend) -deriving instance Eq (BackendKey backend) => Eq (NoPrefix2Generic backend) - share [mkPersist persistSettings { mpsFieldLabelModifier = \entity field -> case entity of "CustomPrefix1" -> append "_cp1" field @@ -164,12 +156,12 @@ share [mkPersist persistSettings { "CustomPrefix2" -> append "CP2" field "CustomPrefixSum" -> append "CP" field _ -> error "should not be called" - , mpsGeneric = True } , mkMigrate "customPrefixMigrate" ] [persistLowerCase| CustomPrefix1 customFieldName Int + deriving Show Eq CustomPrefix2 otherCustomFieldName Int customPrefixedRef CustomPrefix1Id @@ -179,13 +171,7 @@ CustomPrefix2 deriving Show Eq |] -deriving instance Show (BackendKey backend) => Show (CustomPrefix1Generic backend) -deriving instance Eq (BackendKey backend) => Eq (CustomPrefix1Generic backend) - -deriving instance Show (BackendKey backend) => Show (CustomPrefix2Generic backend) -deriving instance Eq (BackendKey backend) => Eq (CustomPrefix2Generic backend) - -share [mkPersist persistSettings { mpsPrefixFields = False, mpsGeneric = False } +share [mkPersist persistSettings { mpsPrefixFields = False } , mkMigrate "treeMigrate" ] [persistLowerCase| @@ -227,17 +213,15 @@ instance (PersistEntity a) => PersistEntity (ReverseFieldOrder a) where persistIdField = error "ReverseFieldOrder.persistIdField" fieldLens x = error "ReverseFieldOrder.fieldLens" -cleanDB - :: (MonadIO m, PersistQuery backend, PersistStoreWrite (BaseBackend backend)) - => ReaderT backend m () +cleanDB :: (MonadIO m) => SqlPersistT m () cleanDB = do - deleteWhere ([] :: [Filter (PersonGeneric backend)]) - deleteWhere ([] :: [Filter (Person1Generic backend)]) - deleteWhere ([] :: [Filter (PetGeneric backend)]) - deleteWhere ([] :: [Filter (MaybeOwnedPetGeneric backend)]) - deleteWhere ([] :: [Filter (NeedsPetGeneric backend)]) - deleteWhere ([] :: [Filter (OutdoorPetGeneric backend)]) - deleteWhere ([] :: [Filter (UserPTGeneric backend)]) - deleteWhere ([] :: [Filter (EmailPTGeneric backend)]) - deleteWhere ([] :: [Filter (UpsertGeneric backend)]) - deleteWhere ([] :: [Filter (UpsertByGeneric backend)]) + deleteWhere ([] :: [Filter Person]) + deleteWhere ([] :: [Filter Person1]) + deleteWhere ([] :: [Filter Pet]) + deleteWhere ([] :: [Filter MaybeOwnedPet]) + deleteWhere ([] :: [Filter NeedsPet]) + deleteWhere ([] :: [Filter OutdoorPet]) + deleteWhere ([] :: [Filter UserPT]) + deleteWhere ([] :: [Filter EmailPT]) + deleteWhere ([] :: [Filter Upsert]) + deleteWhere ([] :: [Filter UpsertBy]) diff --git a/persistent-test/src/PrimaryTest.hs b/persistent-test/src/PrimaryTest.hs index 266bed235..d0cde82dc 100644 --- a/persistent-test/src/PrimaryTest.hs +++ b/persistent-test/src/PrimaryTest.hs @@ -6,8 +6,7 @@ module PrimaryTest where import Init --- mpsGeneric = False is due to a bug or at least lack of a feature in mkKeyTypeDec TH.hs -share [mkPersist persistSettings { mpsGeneric = False }, mkMigrate "migration"] [persistLowerCase| +share [mkPersist persistSettings, mkMigrate "migration"] [persistLowerCase| Foo name String Primary name diff --git a/persistent-test/src/Recursive.hs b/persistent-test/src/Recursive.hs index 1991692b4..71808ff8a 100644 --- a/persistent-test/src/Recursive.hs +++ b/persistent-test/src/Recursive.hs @@ -6,7 +6,7 @@ module Recursive (specsWith, recursiveMigrate, cleanup) where import Init -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "recursiveMigrate"] [persistLowerCase| +share [mkPersist sqlSettings, mkMigrate "recursiveMigrate"] [persistLowerCase| SubType object [MenuObject] @@ -18,20 +18,16 @@ MenuObject |] -cleanup - :: (PersistStoreWrite (BaseBackend backend), PersistQueryWrite backend) - => ReaderT backend IO () +cleanup :: SqlPersistT IO () cleanup = do - deleteWhere ([] :: [Filter (MenuObjectGeneric backend)]) - deleteWhere ([] :: [Filter (SubTypeGeneric backend)]) + deleteWhere ([] :: [Filter MenuObject]) + deleteWhere ([] :: [Filter SubType]) specsWith :: - ( PersistStoreWrite backend - , PersistStoreWrite (BaseBackend backend) - , MonadIO m + ( MonadIO m ) - => RunDb backend m + => RunDb SqlBackend m -> Spec specsWith runDb = describe "recursive definitions" $ do it "mutually recursive" $ runDb $ do diff --git a/persistent-test/src/RenameTest.hs b/persistent-test/src/RenameTest.hs index 051497b8e..05aafb94f 100644 --- a/persistent-test/src/RenameTest.hs +++ b/persistent-test/src/RenameTest.hs @@ -13,7 +13,7 @@ import Init type TextId = Text -- Test lower case names -share [mkPersist sqlSettings { mpsGeneric = True }, mkMigrate "migration"] [persistLowerCase| +share [mkPersist sqlSettings, mkMigrate "migration"] [persistLowerCase| -- This just tests that a field can be named "key" KeyTable key Text @@ -52,26 +52,13 @@ ForeignIdTable idId IdTableId |] -cleanDB - :: forall backend. - ( BaseBackend backend ~ backend - , PersistQueryWrite backend - ) - => ReaderT backend IO () +cleanDB :: SqlPersistT IO () cleanDB = do - deleteWhere ([] :: [Filter (IdTableGeneric backend)]) - deleteWhere ([] :: [Filter (LowerCaseTableGeneric backend)]) - deleteWhere ([] :: [Filter (RefTableGeneric backend)]) + deleteWhere ([] :: [Filter IdTable]) + deleteWhere ([] :: [Filter LowerCaseTable]) + deleteWhere ([] :: [Filter RefTable]) -specsWith - :: - ( PersistStoreWrite backend, PersistQueryRead backend - , backend ~ BaseBackend backend - , MonadIO m, MonadFail m - , Eq (BackendKey backend) - ) - => RunDb backend m - -> Spec +specsWith :: ( MonadIO m, MonadFail m) => RunDb SqlBackend m -> Spec specsWith runDb = describe "rename specs" $ do describe "LowerCaseTable" $ do it "LowerCaseTable has the right sql name" $ do @@ -88,7 +75,7 @@ specsWith runDb = describe "rename specs" $ do insertKey key rec Just rec' <- get key rec' @== rec - (Entity key' _):_ <- selectList ([] :: [Filter (IdTableGeneric backend)]) [] + (Entity key' _):_ <- selectList ([] :: [Filter IdTable]) [] key' @== key it "extra blocks" $ diff --git a/persistent-test/src/SumTypeTest.hs b/persistent-test/src/SumTypeTest.hs index 79ae5f07e..520ddfa3f 100644 --- a/persistent-test/src/SumTypeTest.hs +++ b/persistent-test/src/SumTypeTest.hs @@ -8,7 +8,7 @@ import qualified Data.Text as T import Database.Persist.TH import Init -share [mkPersist persistSettings { mpsGeneric = True }, mkMigrate "sumTypeMigrate"] [persistLowerCase| +share [mkPersist persistSettings, mkMigrate "sumTypeMigrate"] [persistLowerCase| Bicycle brand T.Text Car @@ -17,22 +17,15 @@ Car +Vehicle bicycle BicycleId car CarId + deriving Eq Show |] --- This is needed for mpsGeneric = True --- The typical persistent user sets mpsGeneric = False --- https://ghc.haskell.org/trac/ghc/ticket/8100 -deriving instance Show (BackendKey backend) => Show (VehicleGeneric backend) -deriving instance Eq (BackendKey backend) => Eq (VehicleGeneric backend) - specsWith :: - ( PersistQueryWrite backend - , BaseBackend backend ~ backend - , MonadIO m, MonadFail m + ( MonadIO m, MonadFail m ) - => RunDb backend m - -> Maybe (ReaderT backend m a) + => RunDb SqlBackend m + -> Maybe (ReaderT SqlBackend m a) -- ^ Optional migrations for SQL backends -> Spec specsWith runDb mmigrate = describe "sum types" $ diff --git a/persistent-test/src/TreeTest.hs b/persistent-test/src/TreeTest.hs index ce14f5c7c..bbd80cfd3 100644 --- a/persistent-test/src/TreeTest.hs +++ b/persistent-test/src/TreeTest.hs @@ -6,10 +6,8 @@ module TreeTest where import Init --- mpsGeneric = False is due to a bug or at least lack of a feature in --- mkKeyTypeDec TH.hs share - [ mkPersist persistSettings { mpsGeneric = False } + [ mkPersist persistSettings , mkMigrate "treeMigrate" ] [persistLowerCase| Tree sql=trees diff --git a/persistent-test/src/UpsertTest.hs b/persistent-test/src/UpsertTest.hs index 09ec8863a..8c30b0c72 100644 --- a/persistent-test/src/UpsertTest.hs +++ b/persistent-test/src/UpsertTest.hs @@ -20,8 +20,8 @@ data BackendUpsertKeyBehavior | UpsertPreserveOldKey specsWith - :: forall backend m. Runner backend m - => RunDb backend m + :: forall m. Runner SqlBackend m + => RunDb SqlBackend m -> BackendNullUpdateBehavior -> BackendUpsertKeyBehavior -> Spec @@ -35,7 +35,7 @@ specsWith runDb handleNull handleKey = describe "UpsertTests" $ do describe "upsert" $ do it "adds a new row with no updates" $ runDb $ do Entity _ u <- upsert (Upsert "a" "new" "" 2) [UpsertAttr =. "update"] - c <- count ([] :: [Filter (UpsertGeneric backend)]) + c <- count ([] :: [Filter Upsert]) c @== 1 upsertAttr u @== "new" it "keeps the existing row" $ runDb $ do @@ -85,7 +85,7 @@ specsWith runDb handleNull handleKey = describe "UpsertTests" $ do uniqueEmail (UpsertBy "a" "Boston" "new") [UpsertByAttr =. "update"] - c <- count ([] :: [Filter (UpsertByGeneric backend)]) + c <- count ([] :: [Filter UpsertBy]) c @== 1 upsertByAttr u @== "new" it "keeps the existing row" $ runDb $ do diff --git a/persistent/Database/Persist/ImplicitIdDef.hs b/persistent/Database/Persist/ImplicitIdDef.hs index e82f5c871..781903f50 100644 --- a/persistent/Database/Persist/ImplicitIdDef.hs +++ b/persistent/Database/Persist/ImplicitIdDef.hs @@ -45,11 +45,8 @@ autoIncrementingInteger = FTTypeCon Nothing $ unEntityNameHS entName `mappend` "Id" , iidFieldSqlType = SqlInt64 - , iidType = \isMpsGeneric mpsBackendType -> - ConT ''BackendKey `AppT` - if isMpsGeneric - then VarT (mkName "backend") - else mpsBackendType + , iidType = \mpsBackendType -> + ConT ''BackendKey `AppT` mpsBackendType , iidDefault = Nothing , iidMaxLen = diff --git a/persistent/Database/Persist/ImplicitIdDef/Internal.hs b/persistent/Database/Persist/ImplicitIdDef/Internal.hs index 1aa002e40..2ae4c9f94 100644 --- a/persistent/Database/Persist/ImplicitIdDef/Internal.hs +++ b/persistent/Database/Persist/ImplicitIdDef/Internal.hs @@ -100,9 +100,10 @@ data ImplicitIdDef = ImplicitIdDef -- correspond with an autoincrementing integer primary key. -- -- @since 2.13.0.0 - , iidType :: Bool -> Type -> Type + , iidType :: Type -> Type -- ^ The Bool argument is whether or not the 'MkPersistBackend' type has the - -- 'mpsGeneric' field set. + -- 'mpsGeneric' field set. Since this was removed in @persistent-2.14.0@, + -- this argument is ignored. -- -- The 'Type' is the 'mpsBackend' value. -- @@ -163,7 +164,7 @@ mkImplicitIdDef def = , iidFieldSqlType = sqlType (Proxy @t) , iidType = - \_ _ -> liftType @t + \_ -> liftType @t , iidDefault = Just def , iidMaxLen = diff --git a/persistent/Database/Persist/TH.hs b/persistent/Database/Persist/TH.hs index a10dbc8e1..6c421c290 100644 --- a/persistent/Database/Persist/TH.hs +++ b/persistent/Database/Persist/TH.hs @@ -32,7 +32,6 @@ module Database.Persist.TH , mkPersistWith , MkPersistSettings , mpsBackend - , mpsGeneric , mpsPrefixFields , mpsFieldLabelModifier , mpsConstraintLabelModifier @@ -865,23 +864,6 @@ data MkPersistSettings = MkPersistSettings -- ^ Which database backend we\'re using. This type is used for the -- 'PersistEntityBackend' associated type in the entities that are -- generated. - -- - -- If the 'mpsGeneric' value is set to 'True', then this type is used for - -- the non-Generic type alias. The data and type will be named: - -- - -- @ - -- data ModelGeneric backend = Model { ... } - -- @ - -- - -- And, for convenience's sake, we provide a type alias: - -- - -- @ - -- type Model = ModelGeneric $(the type you give here) - -- @ - , mpsGeneric :: Bool - -- ^ Create generic types that can be used with multiple backends. Good for - -- reusable code, but makes error messages harder to understand. Default: - -- False. , mpsPrefixFields :: Bool -- ^ Prefix field names with the model name. Default: True. -- @@ -935,8 +917,6 @@ data MkPersistSettings = MkPersistSettings -- @since 2.13.0.0 } -{-# DEPRECATED mpsGeneric "The mpsGeneric function adds a considerable amount of overhead and complexity to the library without bringing significant benefit. We would like to remove it. If you require this feature, please comment on the linked GitHub issue, and we'll either keep it around, or we can figure out a nicer way to solve your problem.\n\n Github: https://github.com/yesodweb/persistent/issues/1204" #-} - -- | Set the 'ImplicitIdDef' in the given 'MkPersistSettings'. The default -- value is 'autoIncrementingInteger'. -- @@ -948,9 +928,8 @@ setImplicitIdDef iid mps = getImplicitIdType :: MkPersistSettings -> Type getImplicitIdType = do idDef <- mpsImplicitIdDef - isGeneric <- mpsGeneric backendTy <- mpsBackend - pure $ iidType idDef isGeneric backendTy + pure $ iidType idDef backendTy data EntityJSON = EntityJSON { entityToJSON :: Name @@ -965,7 +944,6 @@ mkPersistSettings -> MkPersistSettings mkPersistSettings backend = MkPersistSettings { mpsBackend = backend - , mpsGeneric = False , mpsPrefixFields = True , mpsFieldLabelModifier = (++) , mpsConstraintLabelModifier = (++) @@ -1028,15 +1006,8 @@ dataTypeDec mps entityMap entDef = do ] ) - (nameFinal, paramsFinal) - | mpsGeneric mps = - ( mkEntityDefGenericName entDef - , [ mkPlainTV backendName - ] - ) - - | otherwise = - (mkEntityDefName entDef, []) + (nameFinal, paramsFinal) = + (mkEntityDefName entDef, []) cols :: [VarBangType] cols = do @@ -1108,44 +1079,10 @@ mkUnique mps entityMap entDef (UniqueDef constr _ fields attrs) = , "constraint in order to disable this check. ***" ] -- | This function renders a Template Haskell 'Type' for an 'UnboundFieldDef'. --- It takes care to respect the 'mpsGeneric' setting to render an Id faithfully, --- and it also ensures that the generated Haskell type is 'Maybe' if the --- database column has that attribute. --- --- For a database schema with @'mpsGeneric' = False@, this is simple - it uses --- the @ModelNameId@ type directly. This resolves just fine. --- --- If 'mpsGeneric' is @True@, then we have to do something a bit more --- complicated. We can't refer to a @ModelNameId@ directly, because that @Id@ --- alias hides the backend type variable. Instead, we need to refer to: +-- It ensures that the generated Haskell type is 'Maybe' if the database column +-- has that attribute. -- --- > Key (ModelNameGeneric backend) --- --- This means that the client code will need both the term @ModelNameId@ in --- scope, as well as the @ModelNameGeneric@ constructor, despite the fact that --- the @ModelNameId@ is the only term explicitly used (and imported). --- --- However, we're not guaranteed to have @ModelName@ in scope - we've only --- referenced @ModelNameId@ in code, and so code generation *should* work even --- without this. Consider an explicit-style import: --- --- @ --- import Model.Foo (FooId) --- --- mkPersistWith sqlSettings $(discoverEntities) [persistLowerCase| --- Bar --- foo FooId --- |] --- @ --- --- This looks like it ought to work, but it would fail with @mpsGeneric@ being --- enabled. One hacky work-around is to perform a @'lookupTypeName' :: String -> --- Q (Maybe Name)@ on the @"ModelNameId"@ type string. If the @Id@ is --- a reference in the 'EntityMap' and @lookupTypeName@ returns @'Just' name@, --- then that 'Name' contains the fully qualified information needed to use the --- 'Name' without importing it at the client-site. Then we can perform a bit of --- surgery on the 'Name' to strip the @Id@ suffix, turn it into a 'Type', and --- apply the 'Key' constructor. +-- This uses the @ModelNameId@ type directly. This resolves just fine. maybeIdType :: MkPersistSettings -> EntityMap @@ -1165,87 +1102,20 @@ maybeIdType mps entityMap fieldDef mbackend mnull = idType = fromMaybe (ftToType $ unboundFieldType fieldDef) $ do typ <- extractForeignRef entityMap fieldDef - guard ((mpsGeneric mps)) pure $ ConT ''Key `AppT` genericDataType mps typ (VarT $ fromMaybe backendName mbackend) - -- TODO: if we keep mpsGeneric, this needs to check 'mpsGeneric' and then - -- append Generic to the model name, probably - _removeIdFromTypeSuffix :: Name -> Type - _removeIdFromTypeSuffix oldName@(Name (OccName nm) nameFlavor) = - case stripSuffix "Id" (T.pack nm) of - Nothing -> - ConT oldName - Just name -> - ConT ''Key - `AppT` do - ConT $ Name (OccName (T.unpack name)) nameFlavor - - -- | TODO: if we keep mpsGeneric, let's incorporate this behavior here, so - -- end users don't need to import the constructor type as well as the id type - -- - -- Returns 'Nothing' if the given text does not appear to be a table reference. - -- In that case, do the usual thing for generating a type name. - -- - -- Returns a @Just typ@ if the text appears to be a model name, and if the - -- @ModelId@ type is in scope. The 'Type' is a fully qualified reference to - -- @'Key' ModelName@ such that end users won't have to import it directly. - _lookupReferencedTable :: EntityMap -> Text -> Q (Maybe Type) - _lookupReferencedTable em fieldTypeText = do - let - mmodelIdString = do - fieldTypeNoId <- stripSuffix "Id" fieldTypeText - _ <- M.lookup (EntityNameHS fieldTypeNoId) em - pure (T.unpack fieldTypeText) - case mmodelIdString of - Nothing -> - pure Nothing - Just modelIdString -> do - mIdName <- lookupTypeName modelIdString - pure $ fmap _removeIdFromTypeSuffix mIdName - - _fieldNameEndsWithId :: UnboundFieldDef -> Maybe String - _fieldNameEndsWithId ufd = go (unboundFieldType ufd) - where - go = \case - FTTypeCon mmodule name -> do - a <- stripSuffix "Id" name - pure $ - T.unpack $ mconcat - [ case mmodule of - Nothing -> - "" - Just m -> - mconcat [m, "."] - , a - , "Id" - ] - _ -> - Nothing - backendDataType :: MkPersistSettings -> Type -backendDataType mps - | mpsGeneric mps = backendT - | otherwise = mpsBackend mps +backendDataType = mpsBackend --- | TODO: --- --- if we keep mpsGeneric --- then --- let's make this fully qualify the generic name --- else --- let's delete it genericDataType :: MkPersistSettings -> EntityNameHS -> Type -- ^ backend -> Type -genericDataType mps name backend - | mpsGeneric mps = - ConT (mkEntityNameHSGenericName name) `AppT` backend - | otherwise = - ConT $ mkEntityNameHSName name +genericDataType _ name _ = + ConT $ mkEntityNameHSName name degen :: [Clause] -> [Clause] degen [] = @@ -1448,20 +1318,17 @@ mkLensClauses mps entDef = do mkKeyTypeDec :: MkPersistSettings -> UnboundEntityDef -> Q (Dec, [Dec]) mkKeyTypeDec mps entDef = do (instDecs, i) <- - if mpsGeneric mps - then if not useNewtype - then do pfDec <- pfInstD - return (pfDec, supplement [''Generic]) - else do gi <- genericNewtypeInstances - return (gi, supplement []) - else if not useNewtype - then do pfDec <- pfInstD - return (pfDec, supplement [''Show, ''Read, ''Eq, ''Ord, ''Generic]) - else do - let allInstances = supplement [''Show, ''Read, ''Eq, ''Ord, ''PathPiece, ''ToHttpApiData, ''FromHttpApiData, ''PersistField, ''PersistFieldSql, ''ToJSON, ''FromJSON] - if customKeyType - then return ([], allInstances) - else do + if not useNewtype + then do + pfDec <- pfInstD + return (pfDec, supplement [''Show, ''Read, ''Eq, ''Ord, ''Generic]) + else do + let allInstances = + supplement [''Show, ''Read, ''Eq, ''Ord, ''PathPiece, ''ToHttpApiData, ''FromHttpApiData, ''PersistField, ''PersistFieldSql, ''ToJSON, ''FromJSON] + if customKeyType + then do + return ([], allInstances) + else do bi <- backendKeyI return (bi, allInstances) @@ -1749,17 +1616,10 @@ mkEntity embedEntityMap entityMap mps preDef = do keyToValues' <- mkKeyToValues mps entDef keyFromValues' <- mkKeyFromValues mps entDef - let addSyn -- FIXME maybe remove this - | mpsGeneric mps = (:) $ - TySynD name [] $ - genericDataType mps entName $ mpsBackend mps - | otherwise = id - lensClauses <- mkLensClauses mps entDef lenses <- mkLenses mps entityMap entDef - let instanceConstraint = if not (mpsGeneric mps) then [] else - [mkClassP ''PersistStore [backendT]] + let instanceConstraint = [] [keyFromRecordM'] <- case unboundPrimarySpec entDef of @@ -1794,7 +1654,7 @@ mkEntity embedEntityMap entityMap mps preDef = do entityFieldTHCon <$> efthAllFields fields allEntDefClauses = entityFieldTHClause <$> efthAllFields fields - return $ addSyn $ + return $ dtd : mconcat fkc `mappend` ( [ TySynD (keyIdName entDef) [] $ ConT ''Key `AppT` ConT name @@ -1940,12 +1800,7 @@ mkUniqueKeyInstances mps entDef = do typeErrorMultiple = mkOnlyUniqueError typeErrorMultipleCtx withPersistStoreWriteCxt = - if mpsGeneric mps - then do - write <- [t|PersistStoreWrite $(pure backendT) |] - pure [write] - else do - pure [] + pure [] typeErrorNoneCtx = do tyErr <- [t|TypeError (NoUniqueKeysError $(pure genDataType))|] @@ -2032,8 +1887,7 @@ mkLenses mps entityMap ent = fmap mconcat $ forM (getUnboundFieldDefs ent) $ \fi sT = mkST backend1 tT = mkST backend2 t1 `arrow` t2 = ArrowT `AppT` t1 `AppT` t2 - vars = mkForallTV fT - : (if mpsGeneric mps then [mkForallTV backend1{-, PlainTV backend2-}] else []) + vars = [mkForallTV fT] return [ SigD lensName $ ForallT vars [mkClassP ''Functor [VarT fT]] $ (aT `arrow` (VarT fT `AppT` bT)) `arrow` @@ -2204,12 +2058,12 @@ persistFieldFromEntity mps entDef = do fromPersistValueImplementation <- [|entityFromPersistValueHelper columnNames|] return - [ persistFieldInstanceD (mpsGeneric mps) typ + [ persistFieldInstanceD typ [ FunD 'toPersistValue [ normalClause [] toPersistValueImplementation ] , FunD 'fromPersistValue [ normalClause [] fromPersistValueImplementation ] ] - , persistFieldSqlInstanceD (mpsGeneric mps) typ + , persistFieldSqlInstanceD typ [ sqlTypeFunD sqlStringConstructor' ] ] @@ -2380,23 +2234,16 @@ sqlTypeFunD st = FunD 'sqlType typeInstanceD :: Name - -> Bool -- ^ include PersistStore backend constraint -> Type -> [Dec] -> Dec -typeInstanceD clazz hasBackend typ = - instanceD ctx (ConT clazz `AppT` typ) - where - ctx - | hasBackend = [mkClassP ''PersistStore [backendT]] - | otherwise = [] +typeInstanceD clazz typ = + instanceD [] (ConT clazz `AppT` typ) -persistFieldInstanceD :: Bool -- ^ include PersistStore backend constraint - -> Type -> [Dec] -> Dec +persistFieldInstanceD :: Type -> [Dec] -> Dec persistFieldInstanceD = typeInstanceD ''PersistField -persistFieldSqlInstanceD :: Bool -- ^ include PersistStore backend constraint - -> Type -> [Dec] -> Dec +persistFieldSqlInstanceD :: Type -> [Dec] -> Dec persistFieldSqlInstanceD = typeInstanceD ''PersistFieldSql -- | Automatically creates a valid 'PersistField' instance for any datatype @@ -2414,7 +2261,7 @@ derivePersistField s = do (x, _):_ -> Right x [] -> Left $ pack "Invalid " ++ pack dt ++ pack ": " ++ s'|] return - [ persistFieldInstanceD False (ConT $ mkName s) + [ persistFieldInstanceD (ConT $ mkName s) [ FunD 'toPersistValue [ normalClause [] tpv ] @@ -2422,7 +2269,7 @@ derivePersistField s = do [ normalClause [] (fpv `AppE` LitE (StringL s)) ] ] - , persistFieldSqlInstanceD False (ConT $ mkName s) + , persistFieldSqlInstanceD (ConT $ mkName s) [ sqlTypeFunD ss ] ] @@ -2449,7 +2296,7 @@ derivePersistFieldJSON s = do Left e -> Left $ pack "JSON decoding error for " ++ pack dt ++ pack ": " ++ pack e ++ pack ". On Input: " ++ decodeUtf8 bs' Right x -> Right x|] return - [ persistFieldInstanceD False (ConT $ mkName s) + [ persistFieldInstanceD (ConT $ mkName s) [ FunD 'toPersistValue [ normalClause [] tpv ] @@ -2457,7 +2304,7 @@ derivePersistFieldJSON s = do [ normalClause [] (fpv `AppE` LitE (StringL s)) ] ] - , persistFieldSqlInstanceD False (ConT $ mkName s) + , persistFieldSqlInstanceD (ConT $ mkName s) [ sqlTypeFunD ss ] ] @@ -2560,14 +2407,8 @@ mkIdField mps ued = do let entityName = getUnboundEntityNameHS ued - entityIdType - | mpsGeneric mps = - ConT ''Key `AppT` ( - ConT (mkEntityNameHSGenericName entityName) - `AppT` backendT - ) - | otherwise = - ConT $ mkName $ (T.unpack $ unEntityNameHS entityName) ++ "Id" + entityIdType = + ConT $ mkName $ (T.unpack $ unEntityNameHS entityName) ++ "Id" name = filterConName' mps entityName (FieldNameHS "Id") clause <- @@ -2655,7 +2496,7 @@ mkJSON mps (fixEntityDef -> def) = do typ = genericDataType mps (entityHaskell (unboundEntityDef def)) backendT toJSONI = - typeInstanceD ''ToJSON (mpsGeneric mps) typ [toJSON'] + typeInstanceD ''ToJSON typ [toJSON'] where toJSON' = FunD 'toJSON $ return $ normalClause [ConP conName $ fmap VarP xs] @@ -2667,7 +2508,7 @@ mkJSON mps (fixEntityDef -> def) = do dotEqualE (Just $ VarE x) fromJSONI = - typeInstanceD ''FromJSON (mpsGeneric mps) typ [parseJSON'] + typeInstanceD ''FromJSON typ [parseJSON'] where parseJSON' = FunD 'parseJSON [ normalClause [ConP 'Object [VarP obj]] @@ -2689,14 +2530,8 @@ mkJSON mps (fixEntityDef -> def) = do Nothing -> return [toJSONI, fromJSONI] Just entityJSON -> do - entityJSONIs <- if mpsGeneric mps - then [d| - instance PersistStore $(pure backendT) => ToJSON (Entity $(pure typ)) where - toJSON = $(varE (entityToJSON entityJSON)) - instance PersistStore $(pure backendT) => FromJSON (Entity $(pure typ)) where - parseJSON = $(varE (entityFromJSON entityJSON)) - |] - else [d| + entityJSONIs <- + [d| instance ToJSON (Entity $(pure typ)) where toJSON = $(varE (entityToJSON entityJSON)) instance FromJSON (Entity $(pure typ)) where @@ -2782,13 +2617,8 @@ mkSymbolToFieldInstances mps entityMap (fixEntityDef -> ed) = do pure (mkey <> join regularFields) where - nameG = - mkEntityDefGenericName ed - recordNameT - | mpsGeneric mps = - conT nameG `appT` varT backendName - | otherwise = - entityDefConT ed + recordNameT = + entityDefConT ed mkInstance fieldNameT fieldTypeT entityFieldConstr = [d| instance SymbolToField $(fieldNameT) $(recordNameT) $(fieldTypeT) where @@ -2925,11 +2755,6 @@ mkEntityDefName :: UnboundEntityDef -> Name mkEntityDefName = mkEntityNameHSName . entityHaskell . unboundEntityDef --- | Make a TH Name for the EntityDef's Haskell type, when using mpsGeneric -mkEntityDefGenericName :: UnboundEntityDef -> Name -mkEntityDefGenericName = - mkEntityNameHSGenericName . entityHaskell . unboundEntityDef - mkEntityNameHSGenericName :: EntityNameHS -> Name mkEntityNameHSGenericName name = mkName $ T.unpack (unEntityNameHS name <> "Generic") diff --git a/persistent/test/Database/Persist/THSpec.hs b/persistent/test/Database/Persist/THSpec.hs index 1fd910be3..6272bd2c5 100644 --- a/persistent/test/Database/Persist/THSpec.hs +++ b/persistent/test/Database/Persist/THSpec.hs @@ -66,7 +66,7 @@ import qualified Database.Persist.TH.CommentSpec as CommentSpec -- machinery type TextId = Text -share [mkPersist sqlSettings { mpsGeneric = False, mpsDeriveInstances = [''Generic] }] [persistUpperCase| +share [mkPersist sqlSettings { mpsDeriveInstances = [''Generic] }] [persistUpperCase| Person json name Text @@ -144,7 +144,7 @@ KeyTable |] -share [mkPersist sqlSettings { mpsGeneric = False, mpsGenerateLenses = True }] [persistLowerCase| +share [mkPersist sqlSettings { mpsGenerateLenses = True }] [persistLowerCase| Lperson json name Text age Int Maybe