persistent 2.2.1 → 2.2.2
raw patch · 4 files changed
+40/−20 lines, 4 filesdep +http-api-data
Dependencies added: http-api-data
Files
- ChangeLog.md +7/−0
- Database/Persist/Sql/Orphan/PersistStore.hs +2/−1
- Database/Persist/Types/Base.hs +28/−18
- persistent.cabal +3/−1
ChangeLog.md view
@@ -1,4 +1,11 @@+## 2.2.2++* support http-api-data for url serialization++## 2.2.1+ * Migration failure message with context+* Fix insertKey for composite keys ## 2.2
Database/Persist/Sql/Orphan/PersistStore.hs view
@@ -34,6 +34,7 @@ import Data.Acquire (with) import Data.Int (Int64) import Web.PathPieces (PathPiece)+import Web.HttpApiData (ToHttpApiData, FromHttpApiData) import Database.Persist.Sql.Class (PersistFieldSql) import qualified Data.Aeson as A import Control.Exception.Lifted (throwIO)@@ -105,7 +106,7 @@ instance PersistStore SqlBackend where newtype BackendKey SqlBackend = SqlBackendKey { unSqlBackendKey :: Int64 }- deriving (Show, Read, Eq, Ord, Num, Integral, PersistField, PersistFieldSql, PathPiece, Real, Enum, Bounded, A.ToJSON, A.FromJSON)+ deriving (Show, Read, Eq, Ord, Num, Integral, PersistField, PersistFieldSql, PathPiece, ToHttpApiData, FromHttpApiData, Real, Enum, Bounded, A.ToJSON, A.FromJSON) update _ [] = return () update k upds = do
Database/Persist/Types/Base.hs view
@@ -5,7 +5,8 @@ import qualified Data.Aeson as A import Control.Exception (Exception)-import Web.PathPieces (PathPiece (..))+import Web.PathPieces (PathPiece(..))+import Web.HttpApiData (ToHttpApiData (..), FromHttpApiData (..), parseUrlPieceMaybe, showTextData, readTextData, parseBoundedTextData) import Control.Monad.Trans.Error (Error (..)) import Data.Typeable (Typeable) import Data.Text (Text, pack)@@ -15,6 +16,7 @@ import qualified Data.ByteString.Base64 as B64 import qualified Data.Vector as V import Control.Arrow (second)+import Control.Applicative ((<$>)) import Data.Time (Day, TimeOfDay, UTCTime) import Data.Int (Int64) import qualified Data.Text.Read@@ -82,13 +84,14 @@ -- may be any number of 'Inactive' records. deriving (Eq, Ord, Read, Show, Enum, Bounded) -instance PathPiece Checkmark where- toPathPiece = pack . show- fromPathPiece txt =- case reads (T.unpack txt) of- [(a, "")] -> Just a- _ -> Nothing+instance ToHttpApiData Checkmark where+ toUrlPiece = showTextData +instance FromHttpApiData Checkmark where+ parseUrlPiece = parseBoundedTextData++instance PathPiece Checkmark+ data IsNullable = Nullable !WhyNullable | NotNullable deriving (Eq, Show)@@ -301,18 +304,25 @@ deriving (Show, Read, Eq, Typeable, Ord) -instance PathPiece PersistValue where- fromPathPiece t =- case Data.Text.Read.signed Data.Text.Read.decimal t of- Right (i, t')- | T.null t' -> Just $ PersistInt64 i- _ -> case reads $ T.unpack t of- [(fks, "")] -> Just $ PersistList fks- _ -> Just $ PersistText t- toPathPiece x =- case fromPersistValueText x of- Left e -> error $ T.unpack e+instance ToHttpApiData PersistValue where+ toUrlPiece val =+ case fromPersistValueText val of+ Left e -> error $ T.unpack e Right y -> y++instance FromHttpApiData PersistValue where+ parseUrlPiece input =+ PersistInt64 <$> parseUrlPiece input+ <!> PersistList <$> readTextData input+ <!> PersistText <$> return input+ where+ infixl 3 <!>+ Left _ <!> y = y+ x <!> _ = x++instance PathPiece PersistValue where+ toPathPiece = toUrlPiece+ fromPathPiece = parseUrlPieceMaybe fromPersistValueText :: PersistValue -> Either Text Text fromPersistValueText (PersistText s) = Right s
persistent.cabal view
@@ -1,5 +1,5 @@ name: persistent-version: 2.2.1+version: 2.2.2 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -36,6 +36,7 @@ , lifted-base >= 0.1 , resource-pool >= 0.2.2.0 , path-pieces >= 0.1+ , http-api-data >= 0.2 && < 0.3 , aeson >= 0.5 , monad-logger >= 0.3 , transformers-base@@ -98,6 +99,7 @@ , attoparsec , transformers , path-pieces+ , http-api-data >= 0.2 && < 0.3 , aeson , resourcet , monad-logger