postgresql-simple 0.1.2 → 0.1.3
raw patch · 5 files changed
+56/−10 lines, 5 files
Files
- postgresql-simple.cabal +11/−2
- src/Database/PostgreSQL/Simple.hs +1/−1
- src/Database/PostgreSQL/Simple/FromField.hs +14/−1
- src/Database/PostgreSQL/Simple/Notification.hs +25/−5
- src/Database/PostgreSQL/Simple/ToField.hs +5/−1
postgresql-simple.cabal view
@@ -1,5 +1,5 @@ Name: postgresql-simple-Version: 0.1.2+Version: 0.1.3 Synopsis: Mid-Level PostgreSQL client library Description: Mid-Level PostgreSQL client library, forked from mysql-simple.@@ -62,7 +62,7 @@ source-repository this type: git location: http://github.com/lpsmith/postgresql-simple- tag: v0.1.2+ tag: v0.1.3 test-suite test type: exitcode-stdio-1.0@@ -70,7 +70,16 @@ hs-source-dirs: test main-is: Main.hs other-modules:+ Common Bytea+ Notify++ ghc-options: -Wall -fno-warn-name-shadowing -fno-warn-unused-do-bind++ extensions: NamedFieldPuns+ , OverloadedStrings+ , Rank2Types+ , RecordWildCards build-depends: base , base16-bytestring
src/Database/PostgreSQL/Simple.hs view
@@ -662,7 +662,7 @@ -- Automated type inference means that you will often be able to avoid -- supplying explicit type signatures for the elements of a tuple. -- However, sometimes the compiler will not be able to infer your--- types. Consider a care where you write a numeric literal in a+-- types. Consider a case where you write a numeric literal in a -- parameter tuple: -- -- > query conn "select ? + ?" (40,2)
src/Database/PostgreSQL/Simple/FromField.hs view
@@ -54,7 +54,7 @@ import Data.Time.Calendar (Day, fromGregorian) import Data.Time.Clock (UTCTime) import Data.Time.Format (parseTime)-import Data.Time.LocalTime (TimeOfDay, makeTimeOfDayValid)+import Data.Time.LocalTime (ZonedTime, TimeOfDay, makeTimeOfDayValid) import Data.Typeable (Typeable, typeOf) import Data.Word (Word64) import Database.PostgreSQL.Simple.Internal@@ -199,6 +199,19 @@ fromField f = case oid2builtin (typeOid f) of Just Timestamp -> doIt "%F %T%Q" id+ Just TimestampWithTimeZone -> doIt "%F %T%Q%z" (++ "00")+ _ -> const $ returnError Incompatible f "types incompatible"+ where+ doIt _ _ Nothing = returnError UnexpectedNull f ""+ doIt fmt preprocess (Just bs) =+ case parseTime defaultTimeLocale fmt str of+ Just t -> pure t+ Nothing -> returnError ConversionFailed f "could not parse"+ where str = preprocess (B8.unpack bs)++instance FromField ZonedTime where+ fromField f =+ case oid2builtin (typeOid f) of Just TimestampWithTimeZone -> doIt "%F %T%Q%z" (++ "00") _ -> const $ returnError Incompatible f "types incompatible" where
src/Database/PostgreSQL/Simple/Notification.hs view
@@ -19,6 +19,7 @@ module Database.PostgreSQL.Simple.Notification ( Notification(..) , getNotification+ , getNotificationNonBlocking ) where import Control.Concurrent ( threadWaitRead )@@ -38,6 +39,11 @@ errfd = "Database.PostgreSQL.Simple.Notification.getNotification: \ \failed to fetch file descriptor" +convertNotice :: PQ.Notify -> Notification+convertNotice PQ.Notify{..}+ = Notification { notificationPid = notifyBePid+ , notificationChannel = notifyRelname+ , notificationData = notifyExtra } -- | Returns a single notification. If no notifications are available, -- 'getNotification' blocks until one arrives.@@ -55,10 +61,24 @@ case mfd of Nothing -> fail errfd Just fd -> return (Left fd)- Just x -> return (Right x)+ Just msg -> return (Right msg)+ -- FIXME? what happens if the connection is closed/reset right here? case res of Left fd -> threadWaitRead fd >> loop True conn- Right PQ.Notify{..} -> do- return Notification { notificationPid = notifyBePid- , notificationChannel = notifyRelname- , notificationData = notifyExtra }+ Right msg -> return $! convertNotice msg++-- | Non-blocking variant of 'getNotification'. Returns a single notification,+-- if available. If no notifications are available, returns 'Nothing'.++getNotificationNonBlocking :: Connection -> IO (Maybe Notification)+getNotificationNonBlocking conn =+ withConnection conn $ \c -> do+ mmsg <- PQ.notifies c+ case mmsg of+ Just msg -> return $! Just $! convertNotice msg+ Nothing -> do+ _ <- PQ.consumeInput c+ mmsg' <- PQ.notifies c+ case mmsg' of+ Just msg -> return $! Just $! convertNotice msg+ Nothing -> return Nothing
src/Database/PostgreSQL/Simple/ToField.hs view
@@ -31,7 +31,7 @@ import Data.Time.Calendar (Day, showGregorian) import Data.Time.Clock (UTCTime) import Data.Time.Format (formatTime)-import Data.Time.LocalTime (TimeOfDay)+import Data.Time.LocalTime (TimeOfDay, ZonedTime) import Data.Typeable (Typeable) import Data.Word (Word, Word8, Word16, Word32, Word64) import Database.PostgreSQL.Simple.Types (Binary(..), In(..), Null)@@ -189,6 +189,10 @@ instance ToField UTCTime where toField = Plain . Utf8.fromString . formatTime defaultTimeLocale "'%F %T%Q+00'"+ {-# INLINE toField #-}++instance ToField ZonedTime where+ toField = Plain . Utf8.fromString . formatTime defaultTimeLocale "'%F %T%Q%z'" {-# INLINE toField #-} instance ToField Day where