persistent 1.1.3.2 → 1.1.4
raw patch · 4 files changed
+42/−4 lines, 4 files
Files
- Database/Persist/GenericSql/Raw.hs +33/−2
- Database/Persist/Query/GenericSql.hs +3/−1
- Database/Persist/Store.hs +5/−0
- persistent.cabal +1/−1
Database/Persist/GenericSql/Raw.hs view
@@ -8,6 +8,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE EmptyDataDecls #-}+{-# LANGUAGE DeriveDataTypeable #-} module Database.Persist.GenericSql.Raw ( withStmt , execute@@ -16,6 +17,7 @@ , getStmt , SqlBackend , MonadSqlPersist (..)+ , StatementAlreadyFinalized (..) ) where import qualified Database.Persist.GenericSql.Internal as I@@ -30,7 +32,8 @@ import Control.Monad.Trans.Class (MonadTrans (..)) import Control.Monad.Base (MonadBase (liftBase)) import Control.Monad.Trans.Control (MonadBaseControl (..), ComposeSt, defaultLiftBaseWith, defaultRestoreM, MonadTransControl (..))-import Control.Monad (liftM)+import Control.Monad (liftM, when)+import Control.Exception (throwIO, Exception) #define MBCIO MonadBaseControl IO import Data.Text (Text, pack) import Control.Monad (MonadPlus)@@ -38,6 +41,7 @@ import Data.Conduit import Control.Monad.Logger (MonadLogger (..)) import Data.Monoid (Monoid)+import Data.Typeable (Typeable) import Control.Monad.Logger (LoggingT) import Control.Monad.Trans.Identity ( IdentityT)@@ -143,6 +147,33 @@ case Map.lookup sql smap of Just stmt -> return stmt Nothing -> do- stmt <- liftIO $ prepare conn sql+ stmt' <- liftIO $ prepare conn sql+ iactive <- liftIO $ newIORef True+ let stmt = I.Statement+ { finalize = do+ active <- readIORef iactive+ if active+ then do+ finalize stmt'+ writeIORef iactive False+ else return ()+ , reset = do+ active <- readIORef iactive+ when active $ reset stmt'+ , I.execute = \x -> do+ active <- readIORef iactive+ if active+ then I.execute stmt' x+ else throwIO $ StatementAlreadyFinalized sql+ , I.withStmt = \x -> do+ active <- liftIO $ readIORef iactive+ if active+ then I.withStmt stmt' x+ else liftIO $ throwIO $ StatementAlreadyFinalized sql+ } liftIO $ writeIORef (stmtMap conn) $ Map.insert sql stmt smap return stmt++data StatementAlreadyFinalized = StatementAlreadyFinalized Text+ deriving (Typeable, Show)+instance Exception StatementAlreadyFinalized
Database/Persist/Query/GenericSql.hs view
@@ -58,7 +58,9 @@ , escapeName conn $ entityDB t , " SET " , T.intercalate "," $ map (go' . go) upds- , " WHERE id=?"+ , " WHERE "+ , escapeName conn $ entityID t+ , "=?" ] execute' sql $ map updatePersistValue upds `mappend` [unKey k]
Database/Persist/Store.hs view
@@ -576,6 +576,11 @@ insert :: (PersistMonadBackend m ~ PersistEntityBackend val, PersistEntity val) => val -> m (Key val) + -- | Same as 'insert', but doesn't return a @Key@.+ insert_ :: (PersistMonadBackend m ~ PersistEntityBackend val, PersistEntity val)+ => val -> m ()+ insert_ val = insert val >> return ()+ -- | Create a new record in the database using the given key. insertKey :: (PersistMonadBackend m ~ PersistEntityBackend val, PersistEntity val) => Key val -> val -> m ()
persistent.cabal view
@@ -1,5 +1,5 @@ name: persistent-version: 1.1.3.2+version: 1.1.4 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>