From 34ae916bf61461a930d1e407b18089fc6334602a Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Thu, 29 Oct 2020 07:43:05 -0600 Subject: [PATCH] warnings, more tidying up --- esqueleto.cabal | 290 ++++++++++---------- src/Database/Esqueleto/Internal/Internal.hs | 13 + src/Database/Esqueleto/MySQL.hs | 3 +- src/Database/Esqueleto/PostgreSQL.hs | 16 +- src/Database/Esqueleto/SQLite.hs | 6 +- test/Common/Test.hs | 30 +- 6 files changed, 182 insertions(+), 176 deletions(-) diff --git a/esqueleto.cabal b/esqueleto.cabal index 4d52edb..9c90b33 100644 --- a/esqueleto.cabal +++ b/esqueleto.cabal @@ -23,152 +23,160 @@ extra-source-files: changelog.md source-repository head - type: git - location: git://github.com/bitemyapp/esqueleto.git + type: git + location: git://github.com/bitemyapp/esqueleto.git library - exposed-modules: - Database.Esqueleto - Database.Esqueleto.Experimental - Database.Esqueleto.Internal.Language - Database.Esqueleto.Internal.Sql - Database.Esqueleto.Internal.Internal - Database.Esqueleto.Internal.ExprParser - Database.Esqueleto.MySQL - Database.Esqueleto.PostgreSQL - Database.Esqueleto.PostgreSQL.JSON - Database.Esqueleto.SQLite - other-modules: - Database.Esqueleto.Internal.PersistentImport - Database.Esqueleto.PostgreSQL.JSON.Instances - Paths_esqueleto - hs-source-dirs: - src/ - build-depends: - base >=4.8 && <5.0 - , aeson >=1.0 - , attoparsec >= 0.13 && < 0.14 - , blaze-html - , bytestring - , conduit >=1.3 - , containers - , monad-logger - , persistent >=2.10.0 && <2.11 - , resourcet >=1.2 - , tagged >=0.2 - , text >=0.11 && <1.3 - , time >=1.5.0.1 && <=1.10 - , transformers >=0.2 - , unliftio - , unordered-containers >=0.2 - if impl(ghc >=8.0) - ghc-options: -Wall -Wno-redundant-constraints - else - ghc-options: -Wall - default-language: Haskell2010 + exposed-modules: + Database.Esqueleto + Database.Esqueleto.Experimental + Database.Esqueleto.Internal.Language + Database.Esqueleto.Internal.Sql + Database.Esqueleto.Internal.Internal + Database.Esqueleto.Internal.ExprParser + Database.Esqueleto.MySQL + Database.Esqueleto.PostgreSQL + Database.Esqueleto.PostgreSQL.JSON + Database.Esqueleto.SQLite + other-modules: + Database.Esqueleto.Internal.PersistentImport + Database.Esqueleto.PostgreSQL.JSON.Instances + Paths_esqueleto + hs-source-dirs: + src/ + build-depends: + base >=4.8 && <5.0 + , aeson >=1.0 + , attoparsec >= 0.13 && < 0.14 + , blaze-html + , bytestring + , conduit >=1.3 + , containers + , monad-logger + , persistent >=2.10.0 && <2.11 + , resourcet >=1.2 + , tagged >=0.2 + , text >=0.11 && <1.3 + , time >=1.5.0.1 && <=1.10 + , transformers >=0.2 + , unliftio + , unordered-containers >=0.2 + ghc-options: + -Wall + -Wno-redundant-constraints + -Wincomplete-uni-patterns + -Wincomplete-record-updates + -Wpartial-fields + -Wmissing-home-modules + -Widentities + -Wredundant-constraints + -Wcpp-undef + -Wcpp-undef + -Wmonomorphism-restriction + default-language: Haskell2010 test-suite mysql - type: exitcode-stdio-1.0 - main-is: MySQL/Test.hs - other-modules: - Common.Test - Paths_esqueleto - hs-source-dirs: - test - ghc-options: -Wall - build-depends: - base >=4.8 && <5.0 - , attoparsec - , blaze-html - , bytestring - , conduit >=1.3 - , containers - , esqueleto - , exceptions - , hspec - , monad-logger - , mtl - , mysql - , mysql-simple - , persistent >=2.8.0 && <2.11 - , persistent-mysql - , persistent-template - , resourcet >=1.2 - , tagged >=0.2 - , text >=0.11 && <1.3 - , time - , transformers >=0.2 - , unliftio - , unordered-containers >=0.2 - default-language: Haskell2010 + type: exitcode-stdio-1.0 + main-is: MySQL/Test.hs + other-modules: + Common.Test + Paths_esqueleto + hs-source-dirs: + test + ghc-options: -Wall + build-depends: + base >=4.8 && <5.0 + , attoparsec + , blaze-html + , bytestring + , conduit >=1.3 + , containers + , esqueleto + , exceptions + , hspec + , monad-logger + , mtl + , mysql + , mysql-simple + , persistent >=2.8.0 && <2.11 + , persistent-mysql + , persistent-template + , resourcet >=1.2 + , tagged >=0.2 + , text >=0.11 && <1.3 + , time + , transformers >=0.2 + , unliftio + , unordered-containers >=0.2 + default-language: Haskell2010 test-suite postgresql - type: exitcode-stdio-1.0 - main-is: PostgreSQL/Test.hs - other-modules: - Common.Test - PostgreSQL.MigrateJSON - Paths_esqueleto - hs-source-dirs: - test - ghc-options: -Wall - build-depends: - base >=4.8 && <5.0 - , aeson - , attoparsec - , blaze-html - , bytestring - , conduit >=1.3 - , containers - , esqueleto - , exceptions - , hspec - , monad-logger - , mtl - , persistent >=2.10.0 && <2.11 - , persistent-postgresql >= 2.10.0 && <2.11 - , persistent-template - , postgresql-libpq - , postgresql-simple - , resourcet >=1.2 - , tagged >=0.2 - , text >=0.11 && <1.3 - , time - , transformers >=0.2 - , unliftio - , unordered-containers >=0.2 - , vector - default-language: Haskell2010 + type: exitcode-stdio-1.0 + main-is: PostgreSQL/Test.hs + other-modules: + Common.Test + PostgreSQL.MigrateJSON + Paths_esqueleto + hs-source-dirs: + test + ghc-options: -Wall + build-depends: + base >=4.8 && <5.0 + , aeson + , attoparsec + , blaze-html + , bytestring + , conduit >=1.3 + , containers + , esqueleto + , exceptions + , hspec + , monad-logger + , mtl + , persistent >=2.10.0 && <2.11 + , persistent-postgresql >= 2.10.0 && <2.11 + , persistent-template + , postgresql-libpq + , postgresql-simple + , resourcet >=1.2 + , tagged >=0.2 + , text >=0.11 && <1.3 + , time + , transformers >=0.2 + , unliftio + , unordered-containers >=0.2 + , vector + default-language: Haskell2010 test-suite sqlite - type: exitcode-stdio-1.0 - main-is: SQLite/Test.hs - other-modules: - Common.Test - Paths_esqueleto - hs-source-dirs: - test - ghc-options: -Wall - build-depends: - base >=4.8 && <5.0 - , attoparsec - , blaze-html - , bytestring - , conduit >=1.3 - , containers - , esqueleto - , exceptions - , hspec - , monad-logger - , mtl - , persistent >=2.8.0 && <2.11 - , persistent-sqlite - , persistent-template - , resourcet >=1.2 - , tagged >=0.2 - , text >=0.11 && <1.3 - , time - , transformers >=0.2 - , unliftio - , unordered-containers >=0.2 - default-language: Haskell2010 + type: exitcode-stdio-1.0 + main-is: SQLite/Test.hs + other-modules: + Common.Test + Paths_esqueleto + hs-source-dirs: + test + ghc-options: -Wall + build-depends: + base >=4.8 && <5.0 + , attoparsec + , blaze-html + , bytestring + , conduit >=1.3 + , containers + , esqueleto + , exceptions + , hspec + , monad-logger + , mtl + , persistent >=2.8.0 && <2.11 + , persistent-sqlite + , persistent-template + , resourcet >=1.2 + , tagged >=0.2 + , text >=0.11 && <1.3 + , time + , transformers >=0.2 + , unliftio + , unordered-containers >=0.2 + default-language: Haskell2010 diff --git a/src/Database/Esqueleto/Internal/Internal.hs b/src/Database/Esqueleto/Internal/Internal.hs index 04a2aaf..c5e0937 100644 --- a/src/Database/Esqueleto/Internal/Internal.hs +++ b/src/Database/Esqueleto/Internal/Internal.hs @@ -560,10 +560,23 @@ e ^. field case e of EEntity ident -> ident EAliasedEntity baseI _ -> baseI + EAliasedEntityReference a b -> + error $ unwords + [ "Used (^.) with an EAliasedEntityReference." + , "Please file this as an Esqueleto bug." + , "EAliasedEntityReference", show a, show b + ] fieldIdent = case e of EEntity _ -> fromDBName info (fieldDB fieldDef) EAliasedEntity baseI _ -> useIdent info $ aliasedEntityColumnIdent baseI fieldDef + EAliasedEntityReference a b -> + error $ unwords + [ "Used (^.) with an EAliasedEntityReference." + , "Please file this as an Esqueleto bug." + , "EAliasedEntityReference", show a, show b + ] + -- | Project an SqlExpression that may be null, guarding against null cases. withNonNull diff --git a/src/Database/Esqueleto/MySQL.hs b/src/Database/Esqueleto/MySQL.hs index 015e3ee..4182fc6 100644 --- a/src/Database/Esqueleto/MySQL.hs +++ b/src/Database/Esqueleto/MySQL.hs @@ -7,9 +7,8 @@ module Database.Esqueleto.MySQL ( random_ ) where -import Database.Esqueleto.Internal.Language hiding (random_) +import Database.Esqueleto.Internal.Internal hiding (random_) import Database.Esqueleto.Internal.PersistentImport -import Database.Esqueleto.Internal.Sql -- | (@random()@) Split out into database specific modules -- because MySQL uses `rand()`. diff --git a/src/Database/Esqueleto/PostgreSQL.hs b/src/Database/Esqueleto/PostgreSQL.hs index dd7a3f8..026829a 100644 --- a/src/Database/Esqueleto/PostgreSQL.hs +++ b/src/Database/Esqueleto/PostgreSQL.hs @@ -43,22 +43,8 @@ import Data.List.NonEmpty (NonEmpty((:|))) import Data.Proxy (Proxy(..)) import qualified Data.Text.Internal.Builder as TLB import Data.Time.Clock (UTCTime) -import Database.Esqueleto.Internal.Internal - ( CompositeKeyError(..) - , EsqueletoError(..) - , FinalResult(..) - , Ident(..) - , KnowResult - , SetClause - , UnexpectedCaseError(..) - , UnexpectedValueError(..) - , renderUpdates - , toUniqueDef - , uncommas - ) -import Database.Esqueleto.Internal.Language hiding (random_) +import Database.Esqueleto.Internal.Internal hiding (random_) import Database.Esqueleto.Internal.PersistentImport hiding (upsert, upsertBy) -import Database.Esqueleto.Internal.Sql import Database.Persist.Class (OnlyOneUniqueKey) -- | (@random()@) Split out into database specific modules diff --git a/src/Database/Esqueleto/SQLite.hs b/src/Database/Esqueleto/SQLite.hs index c219e4b..f7adc1b 100644 --- a/src/Database/Esqueleto/SQLite.hs +++ b/src/Database/Esqueleto/SQLite.hs @@ -1,14 +1,14 @@ {-# LANGUAGE OverloadedStrings #-} + -- | This module contain SQLite-specific functions. -- --- /Since: 2.2.8/ +-- @since 2.2.8 module Database.Esqueleto.SQLite ( random_ ) where -import Database.Esqueleto.Internal.Language hiding (random_) +import Database.Esqueleto.Internal.Internal hiding (random_) import Database.Esqueleto.Internal.PersistentImport -import Database.Esqueleto.Internal.Sql -- | (@random()@) Split out into database specific modules -- because MySQL uses `rand()`. diff --git a/test/Common/Test.hs b/test/Common/Test.hs index 1c59692..06517cb 100644 --- a/test/Common/Test.hs +++ b/test/Common/Test.hs @@ -1865,21 +1865,21 @@ testRenderSql run = do expr `shouldBe` "? = ?" describe "EEntity Ident behavior" $ do - let - render :: SqlExpr (Entity val) -> Text.Text - render (EI.EEntity (EI.I ident)) = ident - it "renders sensibly" $ do - results <- run $ do - _ <- insert $ Foo 2 - _ <- insert $ Foo 3 - _ <- insert $ Person "hello" Nothing Nothing 3 - select $ - from $ \(a `LeftOuterJoin` b) -> do - on $ a ^. FooName ==. b ^. PersonFavNum - pure (val (render a), val (render b)) - head results - `shouldBe` - (Value "Foo", Value "Person") + let render :: SqlExpr (Entity val) -> Text.Text + render (EI.EEntity (EI.I ident)) = ident + render _ = error "guess we gotta handle this in the test suite now" + it "renders sensibly" $ run $ do + _ <- insert $ Foo 2 + _ <- insert $ Foo 3 + _ <- insert $ Person "hello" Nothing Nothing 3 + results <- select $ + from $ \(a `LeftOuterJoin` b) -> do + on $ a ^. FooName ==. b ^. PersonFavNum + pure (val (render a), val (render b)) + liftIO $ + head results + `shouldBe` + (Value "Foo", Value "Person") describe "ExprParser" $ do let parse parser = AP.parseOnly (parser '#')