packages feed

persistent 2.13.1.2 → 2.13.2.1

raw patch · 8 files changed

+64/−36 lines, 8 files

Files

ChangeLog.md view
@@ -1,5 +1,24 @@ # Changelog for persistent +## 2.13.2.1++* [#1329](https://github.com/yesodweb/persistent/pull/1329)+    * Prevent discovery of constrained `PersistEntity` instances in+      `discoverEntities` (since the discovered instances won't work without+      constraints anyway).++## 2.13.2.0++* [#1314](https://github.com/yesodweb/persistent/pull/1314)+    * Fix typos and minor documentation issues in Database.Persist and+      Database.Persist.Quasi.+* [#1317](https://github.com/yesodweb/persistent/pull/1317)+    * Expose `orderClause` from the Persistent internals, which allows users+      to produce well-formatted `ORDER BY` clauses.++* [#1319](https://github.com/yesodweb/persistent/pull/1319)+    * Add a `Num` instance for `OverflowNatural`+ ## 2.13.1.2  * [#1308](https://github.com/yesodweb/persistent/pull/1308)
Database/Persist.hs view
@@ -16,7 +16,7 @@ -- This syntax allows you to customize the resulting Haskell datatypes and -- database schema. See "Database.Persist.Quasi" for details on that definition -- language.---+ -- ** Reference Schema & Dataset -- -- | For a quick example of the syntax, we'll introduce this database schema, and@@ -31,7 +31,7 @@ -- |] -- @ ----- This creates a Haskell datatpe that looks like this:+-- This creates a Haskell datatype that looks like this: -- -- @ -- data User = User
Database/Persist/Class/PersistField.hs view
@@ -2,7 +2,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE PatternGuards, DataKinds, TypeOperators, UndecidableInstances #-}+{-# LANGUAGE PatternGuards, DataKinds, TypeOperators, UndecidableInstances, GeneralizedNewtypeDeriving #-} module Database.Persist.Class.PersistField     ( PersistField (..)     , SomePersistField (..)@@ -346,7 +346,7 @@ -- -- @since 2.11.0 newtype OverflowNatural = OverflowNatural { unOverflowNatural :: Natural }-    deriving (Eq, Show, Ord)+    deriving (Eq, Show, Ord, Num)  instance   TypeError
Database/Persist/Quasi.hs view
@@ -203,7 +203,7 @@ Person json     name Text @-Requires @{-# LANGUAGE FlexibleInstances #-}@+Requires @\{\-\# LANGUAGE FlexibleInstances \#\-\}@  Customizable by using mpsEntityJSON * http://hackage.haskell.org/package/persistent-template/docs/Database-Persist-TH.html#v:EntityJSON@@ -216,7 +216,7 @@     name Text @ -== Change table/collection key definition (field name and/or type, persistent >= 2.1)+== Change table/collection key definition (field name and\/or type, persistent >= 2.1)  @Id@ defines the column to use to define the key of the entity. Without type, the default backend key type will be used. You can change its@@ -956,7 +956,7 @@ setPsStrictFields :: Bool -> PersistSettings -> PersistSettings setPsStrictFields a ps = ps { psStrictFields = a } --- | Retrievce the default name of the @id@ column.+-- | Retrieve the default name of the @id@ column. -- -- @since 2.13.0.0 getPsIdName :: PersistSettings -> Text
Database/Persist/Sql.hs view
@@ -38,6 +38,7 @@     , updateWhereCount     , filterClause     , filterClauseWithVals+    , orderClause     , FilterTablePrefix (..)     -- * Transactions     , transactionSave
Database/Persist/Sql/Orphan/PersistQuery.hs view
@@ -10,6 +10,7 @@     , filterClause     , filterClauseHelper     , filterClauseWithVals+    , orderClause     , FilterTablePrefix (..)     , decorateSQLWithLimitOffset     ) where@@ -20,13 +21,13 @@ import Data.ByteString.Char8 (readInteger) import Data.Conduit import qualified Data.Conduit.List as CL+import Data.Foldable (toList) import Data.Int (Int64) import Data.List (find, inits, transpose) import Data.Maybe (isJust) import Data.Monoid (Monoid(..)) import Data.Text (Text) import qualified Data.Text as T-import Data.Foldable (toList)  import Database.Persist hiding (updateField) import Database.Persist.Sql.Orphan.PersistStore (withRawQuery)@@ -36,8 +37,8 @@ import Database.Persist.Sql.Util        ( commaSeparated        , dbIdColumns-       , keyAndEntityColumnNames        , isIdField+       , keyAndEntityColumnNames        , mkUpdateText        , parseEntityValues        , updatePersistValue@@ -111,10 +112,7 @@         wher conn = if null filts                     then ""                     else filterClause Nothing conn filts-        ord conn =-            case map (orderClause False conn) orders of-                [] -> ""-                ords -> " ORDER BY " <> T.intercalate "," ords+        ord conn = orderClause Nothing conn orders         cols = commaSeparated . toList . keyAndEntityColumnNames t         sql conn = connLimitOffset conn (limit,offset) $ mconcat             [ "SELECT "@@ -148,10 +146,7 @@          (limit, offset, orders) = limitOffsetOrder opts -        ord conn =-            case map (orderClause False conn) orders of-                [] -> ""-                ords -> " ORDER BY " <> T.intercalate "," ords+        ord conn = orderClause Nothing conn orders          parse xs = do             keyvals <- case entityPrimary t of@@ -262,6 +257,16 @@     --     -- @since 2.12.1.0 +prefixByTable+    :: Maybe FilterTablePrefix+    -> Text -- ^ Table name+    -> (Text -> Text) -- ^ Prefixing function+prefixByTable tablePrefix tableName =+    case tablePrefix of+        Just PrefixTableName -> ((tableName <> ".") <>)+        Just PrefixExcluded -> (("EXCLUDED.") <>)+        _ -> id+ filterClauseHelper     :: (PersistEntity val)     => Maybe FilterTablePrefix -- ^ include table name or PostgresSQL EXCLUDED@@ -410,11 +415,7 @@         notNullVals = filter (/= PersistNull) allVals         allVals = filterValueToPersistValues value         tn = connEscapeTableName conn $ entityDef $ dummyFromFilts [Filter field value pfilter]-        name =-          case tablePrefix of-            Just PrefixTableName -> ((tn <> ".") <>) $ connEscapeFieldName conn (fieldName field)-            Just PrefixExcluded -> (("EXCLUDED.") <>) $ connEscapeFieldName conn (fieldName field)-            _ -> id $ connEscapeFieldName conn (fieldName field)+        name = prefixByTable tablePrefix tn $ connEscapeFieldName conn (fieldName field)         qmarks = case value of                     FilterValue{} -> "(?)"                     UnsafeValue{} -> "(?)"@@ -457,28 +458,35 @@              -> (Text, [PersistValue]) filterClauseWithVals b c  = filterClauseHelper b True c OrNullNo +-- | Render a @['SelectOpt' record]@ made up *only* of 'Asc' and 'Desc' constructors+-- into a 'Text' value suitable for inclusion into a SQL query.+--+-- @since 2.13.2.0 orderClause :: (PersistEntity val)-            => Bool -- ^ include the table name+            => Maybe FilterTablePrefix -- ^ include table name or EXCLUDED             -> SqlBackend-            -> SelectOpt val+            -> [SelectOpt val]             -> Text-orderClause includeTable conn o =-    case o of-        Asc  x -> name x-        Desc x -> name x <> " DESC"-        _ -> error "orderClause: expected Asc or Desc, not limit or offset"+orderClause includeTable conn orders =+    if null orders+        then ""+        else+            " ORDER BY " <> T.intercalate ","+                (map (\case+                    Asc  x -> name x+                    Desc x -> name x <> " DESC"+                    _ -> error "orderClause: expected Asc or Desc, not limit or offset")+                    orders)   where-    dummyFromOrder :: SelectOpt a -> Maybe a+    dummyFromOrder :: [SelectOpt a] -> Maybe a     dummyFromOrder _ = Nothing -    tn = connEscapeTableName conn (entityDef $ dummyFromOrder o)+    tn = connEscapeTableName conn (entityDef $ dummyFromOrder orders)      name :: (PersistEntity record)          => EntityField record typ -> Text     name x =-        (if includeTable-            then ((tn <> ".") <>)-            else id)+        prefixByTable includeTable tn         $ connEscapeFieldName conn (fieldName x)  -- | Generates sql for limit and offset for postgres, sqlite and mysql.
Database/Persist/TH.hs view
@@ -3104,7 +3104,7 @@             mapMaybe getDecType instances         getDecType dec =             case dec of-                InstanceD _moverlap _cxt typ _decs ->+                InstanceD _moverlap [] typ _decs ->                     stripPersistEntity typ                 _ ->                     Nothing
persistent.cabal view
@@ -1,5 +1,5 @@ name:            persistent-version:         2.13.1.2+version:         2.13.2.1 license:         MIT license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>