diff --git a/changelog.md b/changelog.md index c13a0befe..1c19ad570 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,25 @@ 3.6.0.0 ======= - @parsonsmatt + - [#412](https://github.com/bitemyapp/esqueleto/pull/412) + - The `random_` and `rand` functions (deprecated in 2.6.0) have been + removed. Please refer to the database specific ones (ie + `Database.Esqueleto.PostgreSQL` etc) + - The `sub_select` function (deprecated in 3.2.0) has been removed. + Please use the safer variants like `subSelect`, `subSelectMaybe`, etc. + - The `ToAliasT` and `ToAliasReferenceT` types has been removed after having been deprecated in 3.4.0.1. + - The `Union` type (deprecated in 3.4) was removed. Please use `union_` + instead. + - The `UnionAll` type (deprecated in 3.4) was removed. Please use + `unionAll_` instead. + - The `Except` type (deprecated in 3.4) was removed. Please use + `except_` instead. + - The `Intersect` type (deprecated in 3.4) was removed. Please use + `intersect_` instead. + - The `SubQuery` type (deprecated in 3.4) was removed. You do not need + to tag subqueries to use them in `from` clauses. + - The `SelectQuery` type (deprecated in 3.4) was removed. You do not + need to tag `SqlQuery` values with `SelectQuery`. - [#287](https://github.com/bitemyapp/esqueleto/pull/278) - Deprecate `distinctOn` and `distinctOnOrderBy`. Use the variants defined in `PostgreSQL` module instead. The signature has changed, but diff --git a/src/Database/Esqueleto.hs b/src/Database/Esqueleto.hs index b4b4c9812..1eac085e2 100644 --- a/src/Database/Esqueleto.hs +++ b/src/Database/Esqueleto.hs @@ -51,14 +51,14 @@ module Database.Esqueleto {-# WARNING "This module will switch over to the Exper -- $gettingstarted -- * @esqueleto@'s Language - where_, on, groupBy, orderBy, rand, asc, desc, limit, offset + where_, on, groupBy, orderBy, asc, desc, limit, offset , distinct, distinctOn, don, distinctOnOrderBy, having, locking - , sub_select, (^.), (?.) + , (^.), (?.) , val, isNothing, just, nothing, joinV, withNonNull , countRows, count, countDistinct , not_, (==.), (>=.), (>.), (<=.), (<.), (!=.), (&&.), (||.) , between, (+.), (-.), (/.), (*.) - , random_, round_, ceiling_, floor_ + , round_, ceiling_, floor_ , min_, max_, sum_, avg_, castNum, castNumM , coalesce, coalesceDefault , lower_, upper_, trim_, ltrim_, rtrim_, length_, left_, right_ diff --git a/src/Database/Esqueleto/Experimental.hs b/src/Database/Esqueleto/Experimental.hs index edffd3f57..bbb1a33b6 100644 --- a/src/Database/Esqueleto/Experimental.hs +++ b/src/Database/Esqueleto/Experimental.hs @@ -22,7 +22,6 @@ module Database.Esqueleto.Experimental from , table , Table(..) - , SubQuery(..) , selectQuery -- ** Joins @@ -40,14 +39,9 @@ module Database.Esqueleto.Experimental -- ** Set Operations -- $sql-set-operations , union_ - , Union(..) , unionAll_ - , UnionAll(..) , except_ - , Except(..) , intersect_ - , Intersect(..) - , pattern SelectQuery -- ** Common Table Expressions , with @@ -57,9 +51,7 @@ module Database.Esqueleto.Experimental , From(..) , ToMaybe(..) , ToAlias(..) - , ToAliasT , ToAliasReference(..) - , ToAliasReferenceT , ToSqlSetOperation(..) , SqlSelect @@ -68,7 +60,6 @@ module Database.Esqueleto.Experimental , groupBy , groupBy_ , orderBy - , rand , asc , desc , limit @@ -81,7 +72,6 @@ module Database.Esqueleto.Experimental , having , locking - , sub_select , (^.) , (?.) @@ -113,7 +103,6 @@ module Database.Esqueleto.Experimental , (/.) , (*.) - , random_ , round_ , ceiling_ , floor_ diff --git a/src/Database/Esqueleto/Experimental/From.hs b/src/Database/Esqueleto/Experimental/From.hs index e9d391899..1a844f67e 100644 --- a/src/Database/Esqueleto/Experimental/From.hs +++ b/src/Database/Esqueleto/Experimental/From.hs @@ -98,10 +98,6 @@ table = From $ do ) -{-# DEPRECATED SubQuery "/Since: 3.4.0.0/ - It is no longer necessary to tag 'SqlQuery' values with @SubQuery@" #-} -newtype SubQuery a = SubQuery a -instance (SqlSelect a r, ToAlias a, ToAliasReference a) => ToFrom (SubQuery (SqlQuery a)) a where - toFrom (SubQuery q) = selectQuery q instance (SqlSelect a r, ToAlias a, ToAliasReference a) => ToFrom (SqlQuery a) a where toFrom = selectQuery diff --git a/src/Database/Esqueleto/Experimental/From/SqlSetOperation.hs b/src/Database/Esqueleto/Experimental/From/SqlSetOperation.hs index c4e9145a2..63abb62e6 100644 --- a/src/Database/Esqueleto/Experimental/From/SqlSetOperation.hs +++ b/src/Database/Esqueleto/Experimental/From/SqlSetOperation.hs @@ -74,11 +74,6 @@ mkSetOperation operation lhs rhs = SqlSetOperation $ \p -> do (_, rightClause) <- unSqlSetOperation (toSqlSetOperation rhs) p pure (leftValue, \info -> leftClause info <> (operation, mempty) <> rightClause info) -{-# DEPRECATED Union "/Since: 3.4.0.0/ - Use the 'union_' function instead of the 'Union' data constructor" #-} -data Union a b = a `Union` b -instance ToSqlSetOperation a a' => ToSqlSetOperation (Union a a) a' where - toSqlSetOperation (Union a b) = union_ a b - -- | Overloaded @union_@ function to support use in both 'SqlSetOperation' -- and 'withRecursive' -- @@ -102,30 +97,10 @@ instance (ToSqlSetOperation a c, ToSqlSetOperation b c, res ~ SqlSetOperation c) => UnionAll_ (a -> b -> res) where unionAll_ = mkSetOperation " UNION ALL " -{-# DEPRECATED UnionAll "/Since: 3.4.0.0/ - Use the 'unionAll_' function instead of the 'UnionAll' data constructor" #-} -data UnionAll a b = a `UnionAll` b -instance ToSqlSetOperation a a' => ToSqlSetOperation (UnionAll a a) a' where - toSqlSetOperation (UnionAll a b) = unionAll_ a b - -{-# DEPRECATED Except "/Since: 3.4.0.0/ - Use the 'except_' function instead of the 'Except' data constructor" #-} -data Except a b = a `Except` b -instance ToSqlSetOperation a a' => ToSqlSetOperation (Except a a) a' where - toSqlSetOperation (Except a b) = except_ a b - -- | @EXCEPT@ SQL set operation. Can be used as an infix function between 'SqlQuery' values. except_ :: (ToSqlSetOperation a a', ToSqlSetOperation b a') => a -> b -> SqlSetOperation a' except_ = mkSetOperation " EXCEPT " -{-# DEPRECATED Intersect "/Since: 3.4.0.0/ - Use the 'intersect_' function instead of the 'Intersect' data constructor" #-} -data Intersect a b = a `Intersect` b -instance ToSqlSetOperation a a' => ToSqlSetOperation (Intersect a a) a' where - toSqlSetOperation (Intersect a b) = intersect_ a b - -- | @INTERSECT@ SQL set operation. Can be used as an infix function between 'SqlQuery' values. intersect_ :: (ToSqlSetOperation a a', ToSqlSetOperation b a') => a -> b -> SqlSetOperation a' intersect_ = mkSetOperation " INTERSECT " - -{-# DEPRECATED SelectQuery "/Since: 3.4.0.0/ - It is no longer necessary to tag 'SqlQuery' values with @SelectQuery@" #-} -pattern SelectQuery :: p -> p -pattern SelectQuery a = a - diff --git a/src/Database/Esqueleto/Experimental/ToAlias.hs b/src/Database/Esqueleto/Experimental/ToAlias.hs index 1756fe6bf..870d1087f 100644 --- a/src/Database/Esqueleto/Experimental/ToAlias.hs +++ b/src/Database/Esqueleto/Experimental/ToAlias.hs @@ -8,9 +8,6 @@ module Database.Esqueleto.Experimental.ToAlias import Database.Esqueleto.Internal.Internal hiding (From, from, on) import Database.Esqueleto.Internal.PersistentImport -{-# DEPRECATED ToAliasT "This type alias doesn't do anything. Please delete it. Will be removed in the next release." #-} -type ToAliasT a = a - -- Tedious tuple magic class ToAlias a where toAlias :: a -> SqlQuery a diff --git a/src/Database/Esqueleto/Experimental/ToAliasReference.hs b/src/Database/Esqueleto/Experimental/ToAliasReference.hs index 8035bc6b3..5bee884eb 100644 --- a/src/Database/Esqueleto/Experimental/ToAliasReference.hs +++ b/src/Database/Esqueleto/Experimental/ToAliasReference.hs @@ -8,9 +8,6 @@ module Database.Esqueleto.Experimental.ToAliasReference import Database.Esqueleto.Internal.Internal hiding (From, from, on) import Database.Esqueleto.Internal.PersistentImport -{-# DEPRECATED ToAliasReferenceT "This type alias doesn't do anything. Please delete it. Will be removed in the next release." #-} -type ToAliasReferenceT a = a - -- more tedious tuple magic class ToAliasReference a where toAliasReference :: Ident -> a -> SqlQuery a diff --git a/src/Database/Esqueleto/Internal/Internal.hs b/src/Database/Esqueleto/Internal/Internal.hs index ebcb27009..b43e9b168 100644 --- a/src/Database/Esqueleto/Internal/Internal.hs +++ b/src/Database/Esqueleto/Internal/Internal.hs @@ -406,12 +406,6 @@ distinctOnOrderBy exprs act = {-# DEPRECATED distinctOnOrderBy "This function is deprecated, as it is only supported in Postgresql. Please use the function defined in `Database.Esqueleto.PostgreSQL` instead." #-} --- | @ORDER BY random()@ clause. --- --- @since 1.3.10 -rand :: SqlExpr OrderBy -rand = ERaw noMeta $ \_ _ -> ("RANDOM()", []) - -- | @HAVING@. -- -- @since 1.2.2 @@ -435,29 +429,6 @@ locking kind = putLocking $ LegacyLockingClause kind putLocking :: LockingClause -> SqlQuery () putLocking clause = Q $ W.tell mempty { sdLockingClause = clause } -{-# - DEPRECATED - sub_select - "sub_select \n \ -sub_select is an unsafe function to use. If used with a SqlQuery that \n \ -returns 0 results, then it may return NULL despite not mentioning Maybe \n \ -in the return type. If it returns more than 1 result, then it will throw a \n \ -SQL error.\n\n Instead, consider using one of the following alternatives: \n \ -- subSelect: attaches a LIMIT 1 and the Maybe return type, totally safe. \n \ -- subSelectMaybe: Attaches a LIMIT 1, useful for a query that already \n \ - has a Maybe in the return type. \n \ -- subSelectCount: Performs a count of the query - this is always safe. \n \ -- subSelectUnsafe: Performs no checks or guarantees. Safe to use with \n \ - countRows and friends." - #-} --- | Execute a subquery @SELECT@ in an SqlExpression. Returns a --- simple value so should be used only when the @SELECT@ query --- is guaranteed to return just one row. --- --- Deprecated in 3.2.0. -sub_select :: PersistField a => SqlQuery (SqlExpr (Value a)) -> SqlExpr (Value a) -sub_select = sub SELECT - -- | Execute a subquery @SELECT@ in a 'SqlExpr'. The query passed to this -- function will only return a single result - it has a @LIMIT 1@ passed in to -- the query to make it safe, and the return type is 'Maybe' to indicate that @@ -891,9 +862,6 @@ not_ v = ERaw noMeta (const $ first ("NOT " <>) . x) between :: PersistField a => SqlExpr (Value a) -> (SqlExpr (Value a), SqlExpr (Value a)) -> SqlExpr (Value Bool) a `between` (b, c) = a >=. b &&. a <=. c -random_ :: (PersistField a, Num a) => SqlExpr (Value a) -random_ = unsafeSqlValue "RANDOM()" - round_ :: (PersistField a, Num a, PersistField b, Num b) => SqlExpr (Value a) -> SqlExpr (Value b) round_ = unsafeSqlFunction "ROUND" @@ -1001,12 +969,15 @@ like = unsafeSqlBinOp " LIKE " -- | @ILIKE@ operator (case-insensitive @LIKE@). -- --- Supported by PostgreSQL only. +-- Supported by PostgreSQL only. Deprecated in version 3.6.0 in favor of the +-- version available from "Database.Esqueleto.PostgreSQL". -- -- @since 2.2.3 ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool) ilike = unsafeSqlBinOp " ILIKE " +{-# DEPRECATED ilike "Since 3.6.0: `ilike` is only supported on Postgres. Please import it from 'Database.Esqueleto.PostgreSQL." #-} + -- | The string @'%'@. May be useful while using 'like' and -- concatenation ('concat_' or '++.', depending on your -- database). Note that you always have to type the parenthesis, @@ -1019,13 +990,19 @@ ilike = unsafeSqlBinOp " ILIKE " (%) = unsafeSqlValue "'%'" -- | The @CONCAT@ function with a variable number of --- parameters. Supported by MySQL and PostgreSQL. +-- parameters. Supported by MySQL and PostgreSQL. SQLite supports this in +-- versions after 3.44.0, and @persistent-sqlite@ supports this in versions +-- @2.13.3.0@ and after. concat_ :: SqlString s => [SqlExpr (Value s)] -> SqlExpr (Value s) concat_ = unsafeSqlFunction "CONCAT" -- | The @||@ string concatenation operator (named after -- Haskell's '++' in order to avoid naming clash with '||.'). +-- -- Supported by SQLite and PostgreSQL. +-- +-- MySQL support requires setting the SQL mode to @PIPES_AS_CONCAT@ or @ANSI@ +-- - see . (++.) :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s) (++.) = unsafeSqlBinOp " || " @@ -1172,13 +1149,13 @@ field /=. expr = setAux field (\ent -> ent ^. field /. expr) -- 'from' $ \\p -> do -- 'where_' (p '^.' PersonName '==.' 'val' \"Mike\")) -- 'then_' --- ('sub_select' $ +-- ('subSelect' $ -- 'from' $ \\v -> do -- let sub = -- 'from' $ \\c -> do -- 'where_' (c '^.' PersonName '==.' 'val' \"Mike\") -- return (c '^.' PersonFavNum) --- 'where_' (v '^.' PersonFavNum >. 'sub_select' sub) +-- 'where_' ('just' (v '^.' PersonFavNum) >. 'subSelect' sub) -- return $ 'count' (v '^.' PersonName) +. 'val' (1 :: Int)) ] -- ('else_' $ 'val' (-1)) -- @ @@ -1244,10 +1221,6 @@ case_ = unsafeSqlCase toBaseId :: ToBaseId ent => SqlExpr (Value (Key ent)) -> SqlExpr (Value (Key (BaseEnt ent))) toBaseId = veryUnsafeCoerceSqlExprValue -{-# DEPRECATED random_ "Since 2.6.0: `random_` is not uniform across all databases! Please use a specific one such as 'Database.Esqueleto.PostgreSQL.random_', 'Database.Esqueleto.MySQL.random_', or 'Database.Esqueleto.SQLite.random_'" #-} - -{-# DEPRECATED rand "Since 2.6.0: `rand` ordering function is not uniform across all databases! To avoid accidental partiality it will be removed in the next major version." #-} - -- Fixity declarations infixl 9 ^. infixl 7 *., /. diff --git a/src/Database/Esqueleto/Legacy.hs b/src/Database/Esqueleto/Legacy.hs index debe44ce3..dec4695f0 100644 --- a/src/Database/Esqueleto/Legacy.hs +++ b/src/Database/Esqueleto/Legacy.hs @@ -52,14 +52,14 @@ module Database.Esqueleto.Legacy -- $gettingstarted -- * @esqueleto@'s Language - where_, on, groupBy, orderBy, rand, asc, desc, limit, offset + where_, on, groupBy, orderBy, asc, desc, limit, offset , distinct, distinctOn, don, distinctOnOrderBy, having, locking - , sub_select, (^.), (?.) + , (^.), (?.) , val, isNothing, just, nothing, joinV, withNonNull , countRows, count, countDistinct , not_, (==.), (>=.), (>.), (<=.), (<.), (!=.), (&&.), (||.) , between, (+.), (-.), (/.), (*.) - , random_, round_, ceiling_, floor_ + , round_, ceiling_, floor_ , min_, max_, sum_, avg_, castNum, castNumM , coalesce, coalesceDefault , lower_, upper_, trim_, ltrim_, rtrim_, length_, left_, right_ diff --git a/src/Database/Esqueleto/PostgreSQL.hs b/src/Database/Esqueleto/PostgreSQL.hs index 9addd2f16..fbebe25b7 100644 --- a/src/Database/Esqueleto/PostgreSQL.hs +++ b/src/Database/Esqueleto/PostgreSQL.hs @@ -38,6 +38,7 @@ module Database.Esqueleto.PostgreSQL , forKeyShareOf , filterWhere , values + , ilike , distinctOn , distinctOnOrderBy , withMaterialized @@ -72,7 +73,7 @@ import Database.Esqueleto.Experimental.From.SqlSetOperation import Database.Esqueleto.Experimental.ToAlias import Database.Esqueleto.Experimental.ToAliasReference import Database.Esqueleto.Internal.Internal hiding - (From(..), distinctOn, distinctOnOrderBy, from, on, random_) + (From(..), ilike, distinctOn, distinctOnOrderBy, from, on, random_) import Database.Esqueleto.Internal.PersistentImport hiding (uniqueFields, upsert, upsertBy) import Database.Persist (ConstraintNameDB(..), EntityNameDB(..)) @@ -661,6 +662,12 @@ forKeyShareOf :: LockableEntity a => a -> OnLockedBehavior -> SqlQuery () forKeyShareOf lockableEntities onLockedBehavior = putLocking $ PostgresLockingClauses [PostgresLockingKind PostgresForKeyShare (Just $ LockingOfClause lockableEntities) onLockedBehavior] +-- | @ILIKE@ operator (case-insensitive @LIKE@). +-- +-- @since 2.2.3 +ilike :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool) +ilike = unsafeSqlBinOp " ILIKE " + -- | @WITH@ @MATERIALIZED@ clause is used to introduce a -- [Common Table Expression (CTE)](https://en.wikipedia.org/wiki/Hierarchical_and_recursive_queries_in_SQL#Common_table_expression) -- with the MATERIALIZED keyword. The MATERIALIZED keyword is only supported in PostgreSQL >= version 12. diff --git a/test/Common/Test.hs b/test/Common/Test.hs index 8db726301..37df01fca 100644 --- a/test/Common/Test.hs +++ b/test/Common/Test.hs @@ -32,7 +32,6 @@ module Common.Test ( tests , testLocking , testAscRandom - , testRandomMath , migrateAll , migrateUnique , cleanDB @@ -161,19 +160,8 @@ testSubSelect = do pure (n ^. NumbersInt) setup res <- select $ pure $ subSelect query - eres <- try $ do - select $ pure $ sub_select query asserting $ do res `shouldBe` [Value (Just 1)] - case eres of - Left (SomeException _) -> - -- We should receive an exception, but the different database - -- libraries throw different exceptions. Hooray. - pure () - Right v -> - -- This shouldn't happen, but in sqlite land, many things are - -- possible. - v `shouldBe` [Value 1] itDb "is safe for queries that may not return anything" $ do let query = @@ -185,21 +173,8 @@ testSubSelect = do res <- select $ pure $ subSelect query transactionUndo - eres <- try $ do - select $ pure $ sub_select query - asserting $ do res `shouldBe` [Value $ Just 1] - case eres of - Left (_ :: PersistException) -> - -- We expect to receive this exception. However, sqlite evidently has - -- no problems with itDb, so we can't *require* that the exception is - -- thrown. Sigh. - pure () - Right v -> - -- This shouldn't happen, but in sqlite land, many things are - -- possible. - v `shouldBe` [Value 1] describe "subSelectList" $ do itDb "is safe on empty databases as well as good databases" $ do @@ -406,7 +381,7 @@ testSelectFrom = do , (p2e, p2e) ] - itDb "works for a self-join via sub_select" $ do + itDb "works for a self-join via subSelect" $ do p1k <- insert p1 p2k <- insert p2 _f1k <- insert (Follow p1k p2k) @@ -417,7 +392,7 @@ testSelectFrom = do from $ \followB -> do where_ $ followA ^. FollowFollower ==. followB ^. FollowFollowed return $ followB ^. FollowFollower - where_ $ followA ^. FollowFollowed ==. sub_select subquery + where_ $ just (followA ^. FollowFollowed) ==. subSelect subquery return followA asserting $ length ret `shouldBe` 2 @@ -745,7 +720,7 @@ testSelectSubQuery = describe "select subquery" $ do _ <- insert' p3 let q = do (name, age) <- - Experimental.from $ SubQuery $ do + Experimental.from $ do p <- Experimental.from $ Table @Person return ( p ^. PersonName, p ^. PersonAge) orderBy [ asc age ] @@ -766,7 +741,7 @@ testSelectSubQuery = describe "select subquery" $ do lord ^. LordId ==. deed ^. DeedOwnerId) return (lord ^. LordId, deed ^. DeedId) q' = do - (lordId, deedId) <- Experimental.from $ SubQuery q + (lordId, deedId) <- Experimental.from q groupBy (lordId) return (lordId, count deedId) (ret :: [(Value (Key Lord), Value Int)]) <- select q' @@ -789,7 +764,7 @@ testSelectSubQuery = describe "select subquery" $ do return (lord ^. LordId, count (deed ^. DeedId)) (ret :: [(Value Int)]) <- select $ do - (lordId, deedCount) <- Experimental.from $ SubQuery q + (lordId, deedCount) <- Experimental.from q where_ $ deedCount >. val (3 :: Int) return (count lordId) @@ -1136,12 +1111,12 @@ testSelectOrderBy = describe "select/orderBy" $ do return p asserting $ ret `shouldBe` [ p1e, p3e, p2e ] - itDb "works with a sub_select" $ do + itDb "works with a subSelect" $ do [p1k, p2k, p3k, p4k] <- mapM insert [p1, p2, p3, p4] [b1k, b2k, b3k, b4k] <- mapM (insert . BlogPost "") [p1k, p2k, p3k, p4k] ret <- select $ from $ \b -> do - orderBy [desc $ sub_select $ + orderBy [desc $ subSelect $ from $ \p -> do where_ (p ^. PersonId ==. b ^. BlogPostAuthorId) return (p ^. PersonName) @@ -1245,8 +1220,8 @@ testCoasleceDefault = describe "coalesce/coalesceDefault" $ do let sub = from $ \p -> do where_ (p ^. PersonId ==. b ^. BlogPostAuthorId) - return $ p ^. PersonAge - return $ coalesceDefault [sub_select sub] (val (42 :: Int)) + pure $ p ^. PersonAge + return $ coalesceDefault [joinV $ subSelect sub] (val (42 :: Int)) asserting $ ret `shouldBe` [ Value (36 :: Int) , Value 42 , Value 17 @@ -1289,7 +1264,7 @@ testUpdate = describe "update" $ do where_ (b ^. BlogPostAuthorId ==. p ^. PersonId) return countRows () <- update $ \p -> do - set p [ PersonAge =. just (sub_select (blogPostsBy p)) ] + set p [ PersonAge =. subSelect (blogPostsBy p) ] ret <- select $ from $ \p -> do orderBy [ asc (p ^. PersonName) ] @@ -1558,31 +1533,6 @@ testInsertsBySelectReturnsCount = do asserting $ ret `shouldBe` [Value (3::Int)] asserting $ cnt `shouldBe` 3 - - - -testRandomMath :: SpecDb -testRandomMath = describe "random_ math" $ - itDb "rand returns result in random order" $ - do - replicateM_ 20 $ do - _ <- insert p1 - _ <- insert p2 - _ <- insert p3 - _ <- insert p4 - _ <- insert $ Person "Jane" Nothing Nothing 0 - _ <- insert $ Person "Mark" Nothing Nothing 0 - _ <- insert $ Person "Sarah" Nothing Nothing 0 - insert $ Person "Paul" Nothing Nothing 0 - ret1 <- fmap (map unValue) $ select $ from $ \p -> do - orderBy [rand] - return (p ^. PersonId) - ret2 <- fmap (map unValue) $ select $ from $ \p -> do - orderBy [rand] - return (p ^. PersonId) - - asserting $ (ret1 == ret2) `shouldBe` False - testMathFunctions :: SpecDb testMathFunctions = do describe "Math-related functions" $ do @@ -1640,16 +1590,16 @@ testCase = do (exists $ from $ \p -> do where_ (p ^. PersonName ==. val "Mike")) then_ - (sub_select $ from $ \v -> do + (subSelect $ from $ \v -> do let sub = from $ \c -> do where_ (c ^. PersonName ==. val "Mike") return (c ^. PersonFavNum) - where_ (v ^. PersonFavNum >. sub_select sub) + where_ (just (v ^. PersonFavNum) >. subSelect sub) return $ count (v ^. PersonName) +. val (1 :: Int)) ] - (else_ $ val (-1)) + (else_ $ just $ val (-1)) - asserting $ ret `shouldBe` [ Value (3) ] + asserting $ ret `shouldBe` [ Value (Just 3) ] testLocking :: SpecDb testLocking = do @@ -2371,7 +2321,7 @@ testExperimentalFrom = do insert_ p3 -- Pretend this isnt all posts upperNames <- select $ do - author <- Experimental.from $ SelectQuery $ Experimental.from $ Table @Person + author <- Experimental.from $ Experimental.from $ Table @Person pure $ upper_ $ author ^. PersonName asserting $ upperNames `shouldMatchList` [ Value "JOHN" diff --git a/test/Common/Test/Models.hs b/test/Common/Test/Models.hs index 2a1ada117..3041d2252 100644 --- a/test/Common/Test/Models.hs +++ b/test/Common/Test/Models.hs @@ -207,4 +207,3 @@ share [mkPersist sqlSettings, mkMigrate "migrateUnique"] [persistUpperCase| instance ToBaseId ArticleMetadata where type BaseEnt ArticleMetadata = Article toBaseIdWitness articleId = ArticleMetadataKey articleId - diff --git a/test/PostgreSQL/Test.hs b/test/PostgreSQL/Test.hs index 8762e4be2..1818c512a 100644 --- a/test/PostgreSQL/Test.hs +++ b/test/PostgreSQL/Test.hs @@ -63,7 +63,6 @@ spec = beforeAll mkConnectionPool $ do describe "PostgreSQL specific tests" $ do testAscRandom random_ - testRandomMath testSelectDistinctOn testPostgresModule testPostgresqlOneAscOneDesc diff --git a/test/SQLite/Test.hs b/test/SQLite/Test.hs index 79818ee01..2f1025fe0 100644 --- a/test/SQLite/Test.hs +++ b/test/SQLite/Test.hs @@ -134,7 +134,6 @@ spec = beforeAll mkConnectionPool $ do describe "SQLite specific tests" $ do testAscRandom random_ - testRandomMath testSqliteRandom testSqliteSum testSqliteTwoAscFields