Use CPP to maintain backward compat
This commit is contained in:
parent
8e71f766b5
commit
d99de61554
@ -19,4 +19,5 @@ extra-deps:
|
||||
- wai-app-static-3.1.4.1
|
||||
- http-api-data-0.2
|
||||
- yaml-0.8.17
|
||||
- nonce-1.0.2
|
||||
- persistent-2.5
|
||||
|
||||
@ -499,6 +499,7 @@ class (YesodAuth master, YesodPersist master) => YesodAuthPersist master where
|
||||
|
||||
getAuthEntity :: AuthId master -> HandlerT master IO (Maybe (AuthEntity master))
|
||||
|
||||
#if MIN_VERSION_persistent(2,5,0)
|
||||
default getAuthEntity
|
||||
:: ( YesodPersistBackend master ~ backend
|
||||
, PersistRecordBackend (AuthEntity master) backend
|
||||
@ -506,6 +507,16 @@ class (YesodAuth master, YesodPersist master) => YesodAuthPersist master where
|
||||
, PersistStore backend
|
||||
)
|
||||
=> AuthId master -> HandlerT master IO (Maybe (AuthEntity master))
|
||||
#else
|
||||
default getAuthEntity
|
||||
:: ( YesodPersistBackend master
|
||||
~ PersistEntityBackend (AuthEntity master)
|
||||
, Key (AuthEntity master) ~ AuthId master
|
||||
, PersistStore (YesodPersistBackend master)
|
||||
, PersistEntity (AuthEntity master)
|
||||
)
|
||||
=> AuthId master -> HandlerT master IO (Maybe (AuthEntity master))
|
||||
#endif
|
||||
getAuthEntity = runDB . get
|
||||
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ library
|
||||
, unordered-containers
|
||||
, yesod-form >= 1.4 && < 1.5
|
||||
, transformers >= 0.2.2
|
||||
, persistent >= 2.5 && < 2.6
|
||||
, persistent >= 2.1 && < 2.6
|
||||
, persistent-template >= 2.1 && < 2.2
|
||||
, http-client
|
||||
, http-conduit >= 2.1
|
||||
|
||||
@ -75,7 +75,11 @@ import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
|
||||
import Data.Text.Encoding.Error (lenientDecode)
|
||||
import Network.URI (parseURI)
|
||||
import Database.Persist.Sql (PersistField, PersistFieldSql (..))
|
||||
#if MIN_VERSION_persistent(2,5,0)
|
||||
import Database.Persist (Entity (..), SqlType (SqlString), PersistRecordBackend, PersistQueryRead)
|
||||
#else
|
||||
import Database.Persist (Entity (..), SqlType (SqlString))
|
||||
#endif
|
||||
import Text.HTML.SanitizeXSS (sanitizeBalance)
|
||||
import Control.Monad (when, unless)
|
||||
import Data.Either (partitionEithers)
|
||||
@ -646,6 +650,7 @@ optionsEnum = optionsPairs $ map (\x -> (pack $ show x, x)) [minBound..maxBound]
|
||||
-- > <$> areq (selectField countries) "Which country do you live in?" Nothing
|
||||
-- > where
|
||||
-- > countries = optionsPersist [] [Asc CountryName] countryName
|
||||
#if MIN_VERSION_persistent(2,5,0)
|
||||
optionsPersist :: ( YesodPersist site
|
||||
, PersistQueryRead backend
|
||||
, PathPiece (Key a)
|
||||
@ -657,6 +662,18 @@ optionsPersist :: ( YesodPersist site
|
||||
-> [SelectOpt a]
|
||||
-> (a -> msg)
|
||||
-> HandlerT site IO (OptionList (Entity a))
|
||||
#else
|
||||
optionsPersist :: ( YesodPersist site, PersistEntity a
|
||||
, PersistQuery (PersistEntityBackend a)
|
||||
, PathPiece (Key a)
|
||||
, RenderMessage site msg
|
||||
, YesodPersistBackend site ~ PersistEntityBackend a
|
||||
)
|
||||
=> [Filter a]
|
||||
-> [SelectOpt a]
|
||||
-> (a -> msg)
|
||||
-> HandlerT site IO (OptionList (Entity a))
|
||||
#endif
|
||||
optionsPersist filts ords toDisplay = fmap mkOptionList $ do
|
||||
mr <- getMessageRender
|
||||
pairs <- runDB $ selectList filts ords
|
||||
@ -670,6 +687,7 @@ optionsPersist filts ords toDisplay = fmap mkOptionList $ do
|
||||
-- the entire 'Entity'.
|
||||
--
|
||||
-- Since 1.3.2
|
||||
#if MIN_VERSION_persistent(2,5,0)
|
||||
optionsPersistKey
|
||||
:: (YesodPersist site
|
||||
, PersistQueryRead backend
|
||||
@ -682,6 +700,20 @@ optionsPersistKey
|
||||
-> [SelectOpt a]
|
||||
-> (a -> msg)
|
||||
-> HandlerT site IO (OptionList (Key a))
|
||||
#else
|
||||
optionsPersistKey
|
||||
:: (YesodPersist site
|
||||
, PersistEntity a
|
||||
, PersistQuery (PersistEntityBackend a)
|
||||
, PathPiece (Key a)
|
||||
, RenderMessage site msg
|
||||
, YesodPersistBackend site ~ PersistEntityBackend a
|
||||
)
|
||||
=> [Filter a]
|
||||
-> [SelectOpt a]
|
||||
-> (a -> msg)
|
||||
-> HandlerT site IO (OptionList (Key a))
|
||||
#endif
|
||||
|
||||
optionsPersistKey filts ords toDisplay = fmap mkOptionList $ do
|
||||
mr <- getMessageRender
|
||||
|
||||
@ -81,9 +81,15 @@ newtype DBRunner site = DBRunner
|
||||
-- | Helper for implementing 'getDBRunner'.
|
||||
--
|
||||
-- Since 1.2.0
|
||||
#if MIN_VERSION_persistent(2,5,0)
|
||||
defaultGetDBRunner :: (SQL.IsSqlBackend backend, YesodPersistBackend site ~ backend)
|
||||
=> (site -> Pool backend)
|
||||
-> HandlerT site IO (DBRunner site, HandlerT site IO ())
|
||||
#else
|
||||
defaultGetDBRunner :: YesodPersistBackend site ~ SQL.SqlBackend
|
||||
=> (site -> Pool SQL.SqlBackend)
|
||||
-> HandlerT site IO (DBRunner site, HandlerT site IO ())
|
||||
#endif
|
||||
defaultGetDBRunner getPool = do
|
||||
pool <- fmap getPool getYesod
|
||||
let withPrep conn f = f (persistBackend conn) (SQL.connPrepare $ persistBackend conn)
|
||||
@ -125,9 +131,15 @@ respondSourceDB :: YesodPersistRunner site
|
||||
respondSourceDB ctype = respondSource ctype . runDBSource
|
||||
|
||||
-- | Get the given entity by ID, or return a 404 not found if it doesn't exist.
|
||||
#if MIN_VERSION_persistent(2,5,0)
|
||||
get404 :: (MonadIO m, PersistStore backend, PersistRecordBackend val backend)
|
||||
=> Key val
|
||||
-> ReaderT backend m val
|
||||
#else
|
||||
get404 :: (MonadIO m, PersistStore (PersistEntityBackend val), PersistEntity val)
|
||||
=> Key val
|
||||
-> ReaderT (PersistEntityBackend val) m val
|
||||
#endif
|
||||
get404 key = do
|
||||
mres <- get key
|
||||
case mres of
|
||||
@ -136,9 +148,15 @@ get404 key = do
|
||||
|
||||
-- | Get the given entity by unique key, or return a 404 not found if it doesn't
|
||||
-- exist.
|
||||
#if MIN_VERSION_persistent(2,5,0)
|
||||
getBy404 :: (PersistUnique backend, PersistRecordBackend val backend, MonadIO m)
|
||||
=> Unique val
|
||||
-> ReaderT backend m (Entity val)
|
||||
#else
|
||||
getBy404 :: (PersistUnique (PersistEntityBackend val), PersistEntity val, MonadIO m)
|
||||
=> Unique val
|
||||
-> ReaderT (PersistEntityBackend val) m (Entity val)
|
||||
#endif
|
||||
getBy404 key = do
|
||||
mres <- getBy key
|
||||
case mres of
|
||||
|
||||
@ -16,7 +16,7 @@ extra-source-files: README.md ChangeLog.md
|
||||
library
|
||||
build-depends: base >= 4 && < 5
|
||||
, yesod-core >= 1.4.0 && < 1.5
|
||||
, persistent >= 2.5 && < 2.6
|
||||
, persistent >= 2.1 && < 2.6
|
||||
, persistent-template >= 2.1 && < 2.2
|
||||
, transformers >= 0.2.2
|
||||
, blaze-builder
|
||||
|
||||
Loading…
Reference in New Issue
Block a user