From a2836281714b2010d83e013defa3d13c43948537 Mon Sep 17 00:00:00 2001 From: Thomas Mahler Date: Mon, 25 Nov 2024 15:22:30 +0100 Subject: [PATCH] just use commit... --- src/Database/GP/GenericPersistence.hs | 2 +- test/PostgresSpec.hs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Database/GP/GenericPersistence.hs b/src/Database/GP/GenericPersistence.hs index 851d658..b31cf25 100644 --- a/src/Database/GP/GenericPersistence.hs +++ b/src/Database/GP/GenericPersistence.hs @@ -134,7 +134,7 @@ entitiesFromRows = (fromEitherExOrA .) . GpSafe.entitiesFromRows -- deprecated: use upsert instead {-# DEPRECATED persist "use upsert instead" #-} persist :: forall a. (Entity a) => Conn -> a -> IO () -persist = upsert --(fromEitherExOrA .) . GpSafe.upsert +persist = upsert -- | A function that upserts an entity into a database. -- The function takes an HDBC connection and an entity as parameters. diff --git a/test/PostgresSpec.hs b/test/PostgresSpec.hs index 168e703..a576302 100644 --- a/test/PostgresSpec.hs +++ b/test/PostgresSpec.hs @@ -197,11 +197,11 @@ spec = do conn <- prepareDB allPersons <- select conn allEntries :: IO [Person] length allPersons `shouldBe` 0 - persist conn person + upsert conn person commit conn allPersons' <- select conn allEntries :: IO [Person] length allPersons' `shouldBe` 1 - persist conn person {age = 26} + upsert conn person {age = 26} commit conn person' <- selectById conn (123456 :: Int) :: IO (Maybe Person) person' `shouldBe` Just person {age = 26} @@ -233,6 +233,8 @@ spec = do upsert conn car2 car2' <- selectById conn (1 :: Int) :: IO (Maybe Car) car2' `shouldBe` Just car2 + commit conn + it "can upsert Entities without autoIncrement" $ do conn <- prepareDB let boat = Boat 1 "Sailboat" @@ -245,6 +247,7 @@ spec = do upsert conn boat2 boat2' <- selectById conn (1 :: Int) :: IO (Maybe Boat) boat2' `shouldBe` Just boat2 + commit conn it "inserts Entities using Generics" $ do conn <- prepareDB