postgresql-simple 0.1 → 0.1.1
raw patch · 6 files changed
+70/−25 lines, 6 files
Files
- postgresql-simple.cabal +2/−2
- src/Database/PostgreSQL/Simple.hs +3/−3
- src/Database/PostgreSQL/Simple/FromField.hs +0/−2
- src/Database/PostgreSQL/Simple/LargeObjects.hs +10/−1
- src/Database/PostgreSQL/Simple/Notification.hs +15/−6
- src/Database/PostgreSQL/Simple/Ok.hs +40/−11
postgresql-simple.cabal view
@@ -1,5 +1,5 @@ Name: postgresql-simple-Version: 0.1+Version: 0.1.1 Synopsis: Mid-Level PostgreSQL client library Description: Mid-Level PostgreSQL client library, forked from mysql-simple.@@ -63,4 +63,4 @@ source-repository this type: git location: http://github.com/lpsmith/postgresql-simple- tag: v0.1+ tag: v0.1.1
src/Database/PostgreSQL/Simple.hs view
@@ -597,9 +597,9 @@ where isolevel = case isolationLevel mode of DefaultIsolationLevel -> ""- ReadCommitted -> " READ COMMITTED"- RepeatableRead -> " REPEATABLE READ"- Serializable -> " SERIALIZABLE"+ ReadCommitted -> " ISOLATION LEVEL READ COMMITTED"+ RepeatableRead -> " ISOLATION LEVEL REPEATABLE READ"+ Serializable -> " ISOLATION LEVEL SERIALIZABLE" readmode = case readWriteMode mode of DefaultReadWriteMode -> "" ReadWrite -> " READ WRITE"
src/Database/PostgreSQL/Simple/FromField.hs view
@@ -59,11 +59,9 @@ import Data.Word (Word64) import Database.PostgreSQL.Simple.Internal import Database.PostgreSQL.Simple.BuiltinTypes--- import qualified Database.PostgreSQ import Database.PostgreSQL.Simple.Ok import Database.PostgreSQL.Simple.Types (Binary(..), Null(..)) import qualified Database.PostgreSQL.LibPQ as PQ--- import Database.PostgreSQL.LibPQ (Format(..), Oid(..)) import System.IO.Unsafe (unsafePerformIO) import System.Locale (defaultTimeLocale) import qualified Data.ByteString as SB
src/Database/PostgreSQL/Simple/LargeObjects.hs view
@@ -1,10 +1,19 @@ ----------------------------------------------------------------------------- -- | -- Module : Database.PostgreSQL.Simple.LargeObjects--- Copyright : (c) 2011 Leon P Smith+-- Copyright : (c) 2011-2012 Leon P Smith -- License : BSD3 -- -- Maintainer : leon@melding-monads.com+--+-- Support for PostgreSQL's Large Objects; see+-- <http://www.postgresql.org/docs/9.1/static/largeobjects.html> for more+-- information.+--+-- Note that Large Object File Descriptors are only valid within a single+-- database transaction, so if you are interested in using anything beyond+-- 'loCreat', 'loImport', 'loExport', and 'loUnlink', you will need to run+-- the entire sequence of functions in a transaction. -- -----------------------------------------------------------------------------
src/Database/PostgreSQL/Simple/Notification.hs view
@@ -3,12 +3,17 @@ ----------------------------------------------------------------------------- -- | -- Module : Database.PostgreSQL.Simple.Notification--- Copyright : (c) 2011 Leon P Smith+-- Copyright : (c) 2011-2012 Leon P Smith -- License : BSD3 -- -- Maintainer : leon@melding-monads.com -- Stability : experimental --+-- Support for receiving asynchronous notifications via PostgreSQL's+-- Listen/Notify mechanism. See+-- <http://www.postgresql.org/docs/9.1/static/sql-notify.html> for more+-- information.+-- ----------------------------------------------------------------------------- module Database.PostgreSQL.Simple.Notification@@ -23,15 +28,19 @@ import qualified Database.PostgreSQL.LibPQ as PQ import System.Posix.Types ( CPid ) -data Notification = Notification- { notificationPid :: CPid- , notificationChannel :: B.ByteString- , notificationData :: B.ByteString- }+data Notification = Notification+ { notificationPid :: !CPid+ , notificationChannel :: !B.ByteString+ , notificationData :: !B.ByteString+ } errfd :: String errfd = "Database.PostgreSQL.Simple.Notification.getNotification: \ \failed to fetch file descriptor"+++-- | Returns a single notification. If no notifications are available,+-- 'getNotification' blocks until one arrives. getNotification :: Connection -> IO Notification getNotification = loop False
src/Database/PostgreSQL/Simple/Ok.hs view
@@ -1,6 +1,34 @@ {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveFunctor #-} +------------------------------------------------------------------------------+-- |+-- Module : Database.PostgreSQL.Simple.Ok+-- Copyright : (c) 2011-2012 Leon P Smith+-- License : BSD3+--+-- Maintainer : leon@melding-monads.com+-- Stability : experimental+--+-- The 'Ok' type is a simple error handler, basically equivalent to+-- @Either [SomeException]@. This type (without the list) was used to+-- handle conversion errors in early versions of postgresql-simple.+--+-- One of the primary reasons why this type was introduced is that+-- @Either SomeException@ had not been provided an instance for 'Alternative',+-- and it would have been a bad idea to provide an orphaned instance for a+-- commonly-used type and typeclass included in @base@.+--+-- Extending the failure case to a list of 'SomeException's enables a+-- more sensible 'Alternative' instance definitions: '<|>' concatinates+-- the list of exceptions when both cases fail, and 'empty' is defined as+-- 'Errors []'. Though '<|>' one could pick one of two exceptions, and+-- throw away the other, and have 'empty' provide a generic exception,+-- this avoids cases where 'empty' overrides a more informative exception+-- and allows you to see all the different ways your computation has failed.+--+------------------------------------------------------------------------------+ module Database.PostgreSQL.Simple.Ok where import Control.Applicative@@ -8,16 +36,15 @@ import Control.Monad(MonadPlus(..)) import Data.Typeable -newtype ManyErrors = ManyErrors [SomeException] - deriving (Show, Typeable)--instance Exception ManyErrors---- FIXME: [SomeException] should probably be a difference list+-- FIXME: [SomeException] should probably be something else, maybe+-- a difference list (or a tree?) data Ok a = Errors [SomeException] | Ok !a deriving(Show, Typeable, Functor) +-- | Two 'Errors' cases are considered equal, regardless of what the+-- list of exceptions looks like.+ instance Eq a => Eq (Ok a) where Errors _ == Errors _ = True Ok a == Ok b = a == b@@ -37,7 +64,6 @@ Errors _ <|> b@(Ok _) = b Errors as <|> Errors bs = Errors (as ++ bs) - instance MonadPlus Ok where mzero = empty mplus = (<|>)@@ -47,9 +73,12 @@ Errors es >>= _ = Errors es Ok a >>= f = f a- -- TODO: add a definition for "fail", akin to - -- fail str = Errors [SomeException (error str)]+ fail str = Errors [SomeException (ErrorCall str)] - -- but *correct*, as this will throw an exception if you try to- -- examine the exception.+-- | a way to reify a list of exceptions into a single exception++newtype ManyErrors = ManyErrors [SomeException]+ deriving (Show, Typeable)++instance Exception ManyErrors