persistent 2.0.7.1 → 2.0.8
raw patch · 5 files changed
+33/−16 lines, 5 files
Files
- Database/Persist/Class.hs +3/−2
- Database/Persist/Class/PersistStore.hs +16/−0
- Database/Persist/Sql/Class.hs +0/−8
- Database/Persist/Sql/Orphan/PersistStore.hs +13/−5
- persistent.cabal +1/−1
Database/Persist/Class.hs view
@@ -1,7 +1,8 @@ module Database.Persist.Class- (+ ( ToBackendKey (..)+ -- * PersistStore- PersistStore (..)+ , PersistStore (..) , getJust , belongsTo , belongsToJust
Database/Persist/Class/PersistStore.hs view
@@ -10,6 +10,7 @@ , getJust , belongsTo , belongsToJust+ , ToBackendKey(..) ) where import qualified Prelude@@ -41,6 +42,21 @@ liftPersist f = do env <- ask liftIO $ runReaderT f (persistBackend env)++-- | ToBackendKey converts a 'PersistEntity' 'Key' into a 'BackendKey'+-- This can be used by each backend to convert between a 'Key' and a plain Haskell type.+-- For Sql, that is done with 'toSqlKey' and 'fromSqlKey'.+--+-- By default, a 'PersistEntity' uses the default 'BackendKey' for its Key+-- and is an instance of ToBackendKey+--+-- A 'Key' that instead uses a custom type will not be an instance of 'ToBackendKey'+class ( PersistEntity record+ , PersistEntityBackend record ~ backend+ , PersistStore backend+ ) => ToBackendKey backend record where+ toBackendKey :: Key record -> BackendKey backend+ fromBackendKey :: BackendKey backend -> Key record class ( Show (BackendKey backend), Read (BackendKey backend)
Database/Persist/Sql/Class.hs view
@@ -10,7 +10,6 @@ module Database.Persist.Sql.Class ( RawSql (..) , PersistFieldSql (..)- , IsSqlKey (..) ) where import Control.Applicative ((<$>), (<*>))@@ -269,10 +268,3 @@ -- An embedded Entity instance (PersistField record, PersistEntity record) => PersistFieldSql (Entity record) where sqlType _ = SqlString---- | A class for all numeric SQL keys, for easy conversion to/from Int64 values.------ Since 2.0.2-class IsSqlKey a where- toSqlKey :: Int64 -> a- fromSqlKey :: a -> Int64
Database/Persist/Sql/Orphan/PersistStore.hs view
@@ -2,13 +2,19 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE DefaultSignatures #-} {-# OPTIONS_GHC -fno-warn-orphans #-}-module Database.Persist.Sql.Orphan.PersistStore (withRawQuery, BackendKey(..)) where+module Database.Persist.Sql.Orphan.PersistStore+ ( withRawQuery+ , BackendKey(..)+ , toSqlKey+ , fromSqlKey+ ) where import Database.Persist import Database.Persist.Sql.Types import Database.Persist.Sql.Raw-import Database.Persist.Sql.Class (IsSqlKey (..)) import qualified Data.Conduit as C import qualified Data.Conduit.List as CL import qualified Data.Text as T@@ -35,9 +41,11 @@ srcRes <- rawQueryRes sql vals liftIO $ with srcRes (C.$$ sink) -instance IsSqlKey (BackendKey SqlBackend) where- toSqlKey = SqlBackendKey- fromSqlKey = unSqlBackendKey+toSqlKey :: ToBackendKey SqlBackend record => Int64 -> Key record+toSqlKey = fromBackendKey . SqlBackendKey++fromSqlKey :: ToBackendKey SqlBackend record => Key record -> Int64+fromSqlKey = unSqlBackendKey . toBackendKey instance PersistStore Connection where newtype BackendKey Connection = SqlBackendKey { unSqlBackendKey :: Int64 }
persistent.cabal view
@@ -1,5 +1,5 @@ name: persistent-version: 2.0.7.1+version: 2.0.8 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>