From 6948cb377983a7098c9b0cab39056e266479fb60 Mon Sep 17 00:00:00 2001 From: Yuriy Syrovetskiy Date: Tue, 28 Mar 2023 18:54:02 +0200 Subject: [PATCH] Code gardening --- Database/MySQL/Internal/Blaze.hs | 1 - Database/MySQL/Simple.hs | 7 +++---- Database/MySQL/Simple/Param.hs | 2 +- Database/MySQL/Simple/Result.hs | 4 ++-- mysql-simple.cabal | 3 +-- test/CustomTypeSpec.hs | 2 +- test/DateTimeSpec.hs | 2 +- test/main.hs | 5 +++++ 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Database/MySQL/Internal/Blaze.hs b/Database/MySQL/Internal/Blaze.hs index 2a25378..6e2e714 100644 --- a/Database/MySQL/Internal/Blaze.hs +++ b/Database/MySQL/Internal/Blaze.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE BangPatterns, CPP, MagicHash, OverloadedStrings, UnboxedTuples #-} -- | This module is designed to provide a shim for @blaze-textual@. diff --git a/Database/MySQL/Simple.hs b/Database/MySQL/Simple.hs index 7bab87c..987421e 100644 --- a/Database/MySQL/Simple.hs +++ b/Database/MySQL/Simple.hs @@ -184,7 +184,7 @@ formatMany conn q@(Query template) qs = do buildQuery :: Connection -> Query -> ByteString -> [Action] -> IO Builder buildQuery conn q template xs = zipParams queryFragments <$> mapM sub xs where sub (Plain b) = pure b - sub (Escape s) = (inQuotes . fromByteString) <$> Base.escape conn s + sub (Escape s) = inQuotes . fromByteString <$> Base.escape conn s sub (Many ys) = mconcat <$> mapM sub ys zipParams (t:ts) (p:ps) = t `mappend` p `mappend` zipParams ts ps zipParams [t] [] = t @@ -198,8 +198,7 @@ buildQuery conn q template xs = zipParams queryFragments <$> mapM sub xs -- break a fragment if the question mark is in a string literal. splitQuery :: ByteString -> [Builder] splitQuery s = - reverse $ fmap (fromByteString . BS.pack . reverse) $ - begin [] (BS.unpack s) + reverse $ fromByteString . BS.pack . reverse <$> begin [] (BS.unpack s) where begin = normal [] @@ -369,7 +368,7 @@ finishFold conn q z0 f = withResult (Base.useResult conn) q $ \r fs -> [] -> return z _ -> (f z $! convertResults fs row) >>= loop -withResult :: (IO Base.Result) -> Query -> (Base.Result -> [Field] -> IO a) -> IO a +withResult :: IO Base.Result -> Query -> (Base.Result -> [Field] -> IO a) -> IO a withResult fetchResult q act = bracket fetchResult Base.freeResult $ \r -> do ncols <- Base.fieldCount (Right r) if ncols == 0 diff --git a/Database/MySQL/Simple/Param.hs b/Database/MySQL/Simple/Param.hs index b1bfd1c..00a40bc 100644 --- a/Database/MySQL/Simple/Param.hs +++ b/Database/MySQL/Simple/Param.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE CPP, DeriveDataTypeable, DeriveFunctor, FlexibleInstances, +{-# LANGUAGE CPP, DeriveDataTypeable, FlexibleInstances, OverloadedStrings, DefaultSignatures #-} -- | diff --git a/Database/MySQL/Simple/Result.hs b/Database/MySQL/Simple/Result.hs index f3a669e..5ff7cb4 100644 --- a/Database/MySQL/Simple/Result.hs +++ b/Database/MySQL/Simple/Result.hs @@ -180,13 +180,13 @@ instance Result (Ratio Integer) where Long,LongLong] instance Result SB.ByteString where - convert f = doConvert f okText $ id + convert f = doConvert f okText id instance Result LB.ByteString where convert f = LB.fromChunks . (:[]) . convert f instance Result ST.Text where - convert f | isText f = doConvert f okText $ ST.decodeUtf8 + convert f | isText f = doConvert f okText ST.decodeUtf8 | otherwise = incompatible f (typeOf ST.empty) "attempt to mix binary and text" diff --git a/mysql-simple.cabal b/mysql-simple.cabal index fd4a145..59b3e66 100644 --- a/mysql-simple.cabal +++ b/mysql-simple.cabal @@ -3,7 +3,7 @@ version: 0.4.9 homepage: https://github.com/paul-rouse/mysql-simple bug-reports: https://github.com/paul-rouse/mysql-simple/issues synopsis: A mid-level MySQL client library. -description: +description: A mid-level client library for the MySQL database, intended to be fast and easy to use. . @@ -52,7 +52,6 @@ library containers, mysql >= 0.1.7, pcre-light, - old-locale, text >= 0.11.0.2, time >= 1.5 if !impl(ghc >= 8.0) diff --git a/test/CustomTypeSpec.hs b/test/CustomTypeSpec.hs index 64fce82..554fce2 100644 --- a/test/CustomTypeSpec.hs +++ b/test/CustomTypeSpec.hs @@ -64,6 +64,6 @@ customTypeSpec conn = describe "writing a custom type" $ do it "should work with parameter substitution" $ do _ <- execute conn "insert into custom (i,c) values (?,?)" - ((3::Int), Latin "nuntium") + (3::Int, Latin "nuntium") result <- query_ conn "select c from custom where i = 3" result `shouldBe` [Only (Latin "nuntium")] diff --git a/test/DateTimeSpec.hs b/test/DateTimeSpec.hs index 04c3254..d5199a4 100644 --- a/test/DateTimeSpec.hs +++ b/test/DateTimeSpec.hs @@ -18,7 +18,7 @@ import Common () -- An arbitrary date and time: 2022-05-25 13:09:34.375 UTC testTime :: UTCTime testTime = UTCTime (ModifiedJulianDay 59724) - (realToFrac $ (378995 % 8 :: Rational)) + (realToFrac (378995 % 8 :: Rational)) testYear :: Day testYear = diff --git a/test/main.hs b/test/main.hs index f6f8339..f1007d1 100644 --- a/test/main.hs +++ b/test/main.hs @@ -21,6 +21,11 @@ isCI = do _ -> False -- This is how to connect to our test database +-- +-- @ +-- CREATE USER test@localhost IDENTIFIED BY 'test'; +-- GRANT ALL PRIVILEGES ON test.* TO test@localhost; +-- @ testConn :: Bool -> ConnectInfo testConn ci = defaultConnectInfo { connectHost = "127.0.0.1"