esqueleto 2.5.0 → 2.5.1
raw patch · 6 files changed
+28/−40 lines, 6 filesdep ~basedep ~blaze-htmldep ~bytestring
Dependency ranges changed: base, blaze-html, bytestring, conduit, monad-logger, persistent, resourcet, tagged, transformers, unordered-containers
Files
- esqueleto.cabal +9/−6
- src/Database/Esqueleto.hs +2/−2
- src/Database/Esqueleto/Internal/Language.hs +1/−3
- src/Database/Esqueleto/Internal/PersistentImport.hs +1/−1
- src/Database/Esqueleto/Internal/Sql.hs +13/−20
- test/Test.hs +2/−8
esqueleto.cabal view
@@ -1,5 +1,5 @@ name: esqueleto-version: 2.5.0+version: 2.5.1 synopsis: Type-safe EDSL for SQL queries on persistent backends. homepage: https://github.com/bitemyapp/esqueleto license: BSD3@@ -36,7 +36,7 @@ Not all SQL features are available, but most of them can be easily added (especially functions), so please open an issue or send a pull request if you need anything that is not covered by @esqueleto@ on- <https://github.com/prowdsponsor/esqueleto/>.+ <https://github.com/bitemyapp/esqueleto>. . The name of this library means \"skeleton\" in Portuguese and contains all three SQL letters in the correct order =). It was@@ -44,7 +44,7 @@ source-repository head type: git- location: git://github.com/prowdsponsor/esqueleto.git+ location: git://github.com/bitemyapp/esqueleto.git Flag postgresql Description: test postgresql. default is to test sqlite.@@ -63,10 +63,10 @@ other-modules: Database.Esqueleto.Internal.PersistentImport build-depends:- base >= 4.5 && < 4.9+ base >= 4.5 && < 5.0 , bytestring , text >= 0.11 && < 1.3- , persistent >= 2.5 && < 2.6+ , persistent >= 2.5 && < 2.7 , transformers >= 0.2 , unordered-containers >= 0.2 , tagged >= 0.2@@ -76,7 +76,10 @@ , resourcet >= 1.1 , blaze-html hs-source-dirs: src/- ghc-options: -Wall+ if impl(ghc >= 8.0)+ ghc-options: -Wall -Wno-redundant-constraints+ else+ ghc-options: -Wall test-suite test type: exitcode-stdio-1.0
src/Database/Esqueleto.hs view
@@ -14,14 +14,14 @@ -- @ -- -- For a module that mostly uses esqueleto. -- import Database.Esqueleto--- import qualified Database.Persistent as P+-- import qualified Database.Persist as P -- @ -- -- or import @esqueleto@ itself qualified: -- -- @ -- -- For a module that uses esqueleto just on some queries.--- import Database.Persistent+-- import Database.Persist -- import qualified Database.Esqueleto as E -- @ --
src/Database/Esqueleto/Internal/Language.hs view
@@ -44,7 +44,6 @@ , else_ ) where -import Control.Applicative (Applicative(..), (<$>)) import Control.Exception (Exception) import Data.Int (Int64) import Data.Typeable (Typeable)@@ -52,7 +51,6 @@ import Text.Blaze.Html (Html) import qualified Data.ByteString as B-import qualified Data.ByteString.Lazy as BL import qualified Data.Text as T import qualified Data.Text.Lazy as TL @@ -471,7 +469,7 @@ -- @ -- select $ -- 'from' $ \\person -> do- -- 'where_' $ person '^.' PersonId ``in_'` 'valList' personIds+ -- 'where_' $ person '^.' PersonId `'in_`` 'valList' personIds -- return person -- @ --
src/Database/Esqueleto/Internal/PersistentImport.hs view
@@ -5,7 +5,7 @@ ) where import Database.Persist.Sql hiding- ( BackendSpecificFilter, Filter(..), PersistQuery(..), SelectOpt(..)+ ( BackendSpecificFilter, Filter(..), PersistQuery, SelectOpt(..) , Update(..), delete, deleteWhereCount, updateWhereCount, selectList , selectKeysList, deleteCascadeWhere, (=.), (+=.), (-=.), (*=.), (/=.) , (==.), (!=.), (<.), (>.), (<=.), (>=.), (<-.), (/<-.), (||.)
src/Database/Esqueleto/Internal/Sql.hs view
@@ -51,17 +51,16 @@ , veryUnsafeCoerceSqlExprValueList ) where -import Control.Applicative (Applicative(..), (<$>), (<$)) import Control.Arrow ((***), first) import Control.Exception (throw, throwIO)-import Control.Monad (ap, MonadPlus(..), liftM)+import Control.Monad (ap, MonadPlus(..), join, void) import Control.Monad.IO.Class (MonadIO(..)) import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Resource (MonadResource) import Data.Acquire (with, allocateAcquire, Acquire) import Data.Int (Int64) import Data.List (intersperse)-import Data.Monoid (Last(..), Monoid(..), (<>))+import Data.Monoid (Last(..), (<>)) import Data.Proxy (Proxy(..)) import Database.Esqueleto.Internal.PersistentImport import Database.Persist.Sql.Util (entityColumnNames, entityColumnCount, parseEntityValues, isIdField, hasCompositeKey)@@ -648,7 +647,7 @@ deconstruct :: (TLB.Builder, [PersistValue]) -> ([TLB.Builder], [PersistValue]) deconstruct ("?", [PersistList vals]) = (replicate (length vals) "?", vals)- deconstruct (b, []) = (TLB.fromLazyText <$> TL.splitOn "," (TLB.toLazyText b), [])+ deconstruct (b', []) = (TLB.fromLazyText <$> TL.splitOn "," (TLB.toLazyText b'), []) deconstruct x = err $ "cannot deconstruct " ++ show x ++ "." compose f1 f2 info@@ -667,7 +666,7 @@ -- | (Internal) A raw SQL value. The same warning from -- 'unsafeSqlBinOp' applies to this function as well. unsafeSqlValue :: TLB.Builder -> SqlExpr (Value a)-unsafeSqlValue v = ERaw Never $ \_ -> (v, mempty)+unsafeSqlValue v = ERaw Never $ const (v, mempty) {-# INLINE unsafeSqlValue #-} @@ -784,12 +783,9 @@ , MonadResource m ) => SqlQuery a -> C.Source (SqlPersistT m) r-selectSource query = do- src <- lift $ do- res <- rawSelectSource SELECT query- fmap snd $ allocateAcquire res- src-+selectSource query = join . lift $ do+ res <- rawSelectSource SELECT query+ snd <$> allocateAcquire res -- | Execute an @esqueleto@ @SELECT@ query inside @persistent@'s -- 'SqlPersistT' monad and return a list of rows.@@ -910,8 +906,7 @@ delete :: ( MonadIO m ) => SqlQuery () -> SqlWriteT m ()-delete = liftM (const ()) . deleteCount-+delete = void . deleteCount -- | Same as 'delete', but returns the number of rows affected. deleteCount :: ( MonadIO m )@@ -936,8 +931,7 @@ , SqlEntity val ) => (SqlExpr (Entity val) -> SqlQuery ()) -> SqlWriteT m ()-update = liftM (const ()) . updateCount-+update = void . updateCount -- | Same as 'update', but returns the number of rows affected. updateCount :: ( MonadIO m@@ -1037,7 +1031,7 @@ DistinctOn exprs -> first (("SELECT DISTINCT ON (" <>) . (<> ") ")) $ uncommas' (processExpr <$> exprs) where processExpr (EDistinctOn f) = materializeExpr info f- withCols v = v <> (sqlSelectCols info ret)+ withCols v = v <> sqlSelectCols info ret plain v = (v, []) @@ -1122,7 +1116,7 @@ let fs = f info vals = repeat [] in zip (map (<> orderByType t) fs) vals- mk EOrderRandom = [first ((<> "RANDOM()")) mempty]+ mk EOrderRandom = [first (<> "RANDOM()") mempty] orderByType ASC = " ASC" orderByType DESC = " DESC" @@ -1215,8 +1209,7 @@ in (process ed, mempty) sqlSelectColCount = entityColumnCount . entityDef . getEntityVal sqlSelectProcessRow = parseEntityValues ed- where ed = entityDef $ getEntityVal $ (Proxy :: Proxy (SqlExpr (Entity a)))-+ where ed = entityDef $ getEntityVal (Proxy :: Proxy (SqlExpr (Entity a))) getEntityVal :: Proxy (SqlExpr (Entity a)) -> Proxy a getEntityVal = const Proxy@@ -1749,7 +1742,7 @@ -- /Since: 2.4.2/ insertSelect :: (MonadIO m, PersistEntity a) => SqlQuery (SqlExpr (Insertion a)) -> SqlWriteT m ()-insertSelect = liftM (const ()) . insertSelectCount+insertSelect = void . insertSelectCount -- | Insert a 'PersistField' for every selected value, return the count afterward insertSelectCount :: (MonadIO m, PersistEntity a) =>
test/Test.hs view
@@ -18,18 +18,13 @@ #-} module Main (main) where -import Control.Applicative ((<$>))-import Control.Arrow ((&&&))-import Control.Exception (IOException) import Control.Monad (forM_, replicateM, replicateM_, void) import Control.Monad.IO.Class (MonadIO(liftIO)) import Control.Monad.Logger (MonadLogger(..), runStderrLoggingT, runNoLoggingT) import Control.Monad.Trans.Control (MonadBaseControl(..)) import Control.Monad.Trans.Reader (ReaderT) import Data.Char (toLower, toUpper)-import Data.List (sortBy) import Data.Monoid ((<>))-import Data.Ord (comparing) import Database.Esqueleto #if defined (WITH_POSTGRESQL) import Database.Persist.Postgresql (withPostgresqlConn)@@ -53,7 +48,6 @@ import qualified Data.List as L import qualified Data.Set as S import qualified Data.Text.Lazy.Builder as TLB-import qualified Database.Esqueleto.PostgreSQL as EP import qualified Database.Esqueleto.Internal.Sql as EI @@ -154,7 +148,7 @@ it "works for a single NULL value" $ run $ do- ret <- select $ return $ nothing+ ret <- select $ return nothing liftIO $ ret `shouldBe` [ Value (Nothing :: Maybe Int) ] describe "select/from" $ do@@ -289,7 +283,7 @@ number = 101 Right thePk = keyFromValues [toPersistValue number] fcPk <- insert fc- [Entity _ ret] <- select $ from $ return+ [Entity _ ret] <- select $ from return liftIO $ do ret `shouldBe` fc fcPk `shouldBe` thePk