packages feed

postgresql-simple 0.3.10.0 → 0.4.0.0

raw patch · 7 files changed

+58/−22 lines, 7 filesdep ~aesondep ~base

Dependency ranges changed: aeson, base

Files

postgresql-simple.cabal view
@@ -1,5 +1,5 @@ Name:                postgresql-simple-Version:             0.3.10.0+Version:             0.4.0.0 Synopsis:            Mid-Level PostgreSQL client library Description:     Mid-Level PostgreSQL client library, forked from mysql-simple.@@ -79,7 +79,7 @@ source-repository this   type:     git   location: http://github.com/lpsmith/postgresql-simple-  tag:      v0.3.10.0+  tag:      v0.4.0.0  test-suite test   type:           exitcode-stdio-1.0
src/Database/PostgreSQL/Simple/FromField.hs view
@@ -95,21 +95,24 @@  import           Control.Applicative                    ( Applicative, (<|>), (<$>), pure )+import           Control.Concurrent.MVar (MVar, newMVar) import           Control.Exception (Exception) import qualified Data.Aeson as JSON import           Data.Attoparsec.Char8 hiding (Result) import           Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as B import           Data.Int (Int16, Int32, Int64)+import           Data.IORef (IORef, newIORef) import           Data.Ratio (Ratio) import           Data.Time ( UTCTime, ZonedTime, LocalTime, Day, TimeOfDay ) import           Data.Typeable (Typeable, typeOf) import           Data.Vector (Vector)+import           Data.Vector.Mutable (IOVector) import qualified Data.Vector as V import           Database.PostgreSQL.Simple.Internal import           Database.PostgreSQL.Simple.Compat import           Database.PostgreSQL.Simple.Ok-import           Database.PostgreSQL.Simple.Types (Binary(..), Null(..))+import           Database.PostgreSQL.Simple.Types import           Database.PostgreSQL.Simple.TypeInfo as TI import qualified Database.PostgreSQL.Simple.TypeInfo.Static as TI import           Database.PostgreSQL.Simple.TypeInfo.Macro as TI@@ -166,17 +169,6 @@     -- Returns a list of exceptions if the conversion fails.  In the case of     -- library instances,  this will usually be a single 'ResultError',  but     -- may be a 'UnicodeException'.-    ---    -- Note that retaining any reference to the 'Field' or 'ByteString'-    -- arguments causes the entire @LibPQ.'PQ.Result'@ to be retained.-    -- Thus, as a rule of thumb, implementations of 'fromField' should-    -- not refer to these values after the result has been evaluated-    -- to WHNF.  But it can be profitable to break this rule when you-    -- know it won't cause memory management problems.-    ---    -- The instances included with postgresql-simple follow this rule-    -- of thumb (modulo bugs).   For example, the instance for 'ByteString'-    -- uses 'B.copy' to avoid such a reference.  -- | Returns the data type name.  This is the preferred way of identifying --   types that do not have a stable type oid, such as types provided by@@ -320,7 +312,7 @@ instance FromField SB.ByteString where     fromField f dat = if typeOid f == $(inlineTypoid TI.bytea)                       then unBinary <$> fromField f dat-                      else doFromField f okText' (pure . B.copy) dat+                      else doFromField f okText' pure dat  -- | oid instance FromField PQ.Oid where@@ -340,7 +332,7 @@ instance FromField (Binary SB.ByteString) where     fromField f dat = case format f of       PQ.Text   -> doFromField f okBinary (unescapeBytea f) dat-      PQ.Binary -> doFromField f okBinary (pure . Binary . B.copy) dat+      PQ.Binary -> doFromField f okBinary (pure . Binary) dat  -- | bytea instance FromField (Binary LB.ByteString) where@@ -423,7 +415,7 @@                     <|> (Left  <$> fromField f dat)  -- | any postgresql array whose elements are compatible with type @a@-instance (FromField a, Typeable a) => FromField (Vector a) where+instance (FromField a, Typeable a) => FromField (PGArray a) where     fromField f mdat = do         info <- typeInfo f         case info of@@ -433,7 +425,7 @@                 Just dat -> do                    case parseOnly (fromArray info f) dat of                      Left  err  -> returnError ConversionFailed f err-                     Right conv -> V.fromList <$> conv+                     Right conv -> PGArray <$> conv           _ -> returnError Incompatible f ""  fromArray :: (FromField a)@@ -446,6 +438,12 @@       where f' | Arrays.Array _ <- item = f                | otherwise              = fElem +instance (FromField a, Typeable a) => FromField (Vector a) where+    fromField f v = V.fromList . fromPGArray <$> fromField f v++instance (FromField a, Typeable a) => FromField (IOVector a) where+    fromField f v = liftConversion . V.unsafeThaw =<< fromField f v+ -- | uuid instance FromField UUID where     fromField f mbs =@@ -466,7 +464,13 @@       else case mbs of              Nothing -> returnError UnexpectedNull f ""              Just bs ->+#if MIN_VERSION_aeson(0,6,3)                  case JSON.eitherDecodeStrict' bs of+#elsif MIN_VERSION_bytestring(0,10,0)+                 case JSON.eitherDecode' $ LB.fromStrict bs of+#else+                 case JSON.eitherDecode' $ LB.fromChunks [bs] of+#endif                    Left  err -> returnError ConversionFailed f err                    Right val -> pure val @@ -486,6 +490,19 @@         JSON.Error err -> returnError ConversionFailed f $                             "JSON decoding error: " ++ err         JSON.Success x -> pure x+++-- | Compatible with the same set of types as @a@.  Note that+--   modifying the 'IORef' does not have any effects outside+--   the local process on the local machine.+instance FromField a => FromField (IORef a) where+    fromField f v = liftConversion . newIORef =<< fromField f v++-- | Compatible with the same set of types as @a@.  Note that+--   modifying the 'MVar' does not have any effects outside+--   the local process on the local machine.+instance FromField a => FromField (MVar a) where+    fromField f v = liftConversion . newMVar =<< fromField f v  type Compat = PQ.Oid -> Bool 
src/Database/PostgreSQL/Simple/FromRow.hs view
@@ -70,7 +70,7 @@     fromRow :: RowParser a  getvalue :: PQ.Result -> PQ.Row -> PQ.Column -> Maybe ByteString-getvalue result row col = unsafeDupablePerformIO (PQ.getvalue result row col)+getvalue result row col = unsafeDupablePerformIO (PQ.getvalue' result row col)  nfields :: PQ.Result -> PQ.Column nfields result = unsafeDupablePerformIO (PQ.nfields result)
+ src/Database/PostgreSQL/Simple/Internal.hs-boot view
@@ -0,0 +1,3 @@+module Database.PostgreSQL.Simple.Internal where++data RowParser a
src/Database/PostgreSQL/Simple/ToField.hs view
@@ -33,7 +33,7 @@ import Data.Time (Day, TimeOfDay, LocalTime, UTCTime, ZonedTime) import Data.Typeable (Typeable) import Data.Word (Word, Word8, Word16, Word32, Word64)-import Database.PostgreSQL.Simple.Types (Binary(..), In(..), Null, Default)+import Database.PostgreSQL.Simple.Types import qualified Blaze.ByteString.Builder.Char.Utf8 as Utf8 import qualified Data.ByteString as SB import qualified Data.ByteString.Lazy as LB@@ -230,13 +230,16 @@     toField = Plain . inQuotes . dateToBuilder     {-# INLINE toField #-} -instance (ToField a) => ToField (Vector a) where+instance (ToField a) => ToField (PGArray a) where     toField xs = Many $         Plain (fromByteString "ARRAY[") :-        (intersperse (Plain (fromChar ',')) . map toField $ V.toList xs) +++        (intersperse (Plain (fromChar ',')) . map toField $ fromPGArray xs) ++         [Plain (fromChar ']')]         -- Because the ARRAY[...] input syntax is being used, it is possible         -- that the use of type-specific separator characters is unnecessary.++instance (ToField a) => ToField (Vector a) where+    toField = toField . PGArray . V.toList  instance ToField UUID where     toField = Plain . inQuotes . fromByteString . UUID.toASCIIBytes
+ src/Database/PostgreSQL/Simple/TypeInfo.hs-boot view
@@ -0,0 +1,7 @@+module Database.PostgreSQL.Simple.TypeInfo where++import qualified Database.PostgreSQL.LibPQ as PQ+import           Database.PostgreSQL.Simple.TypeInfo.Types+import           Database.PostgreSQL.Simple.Internal++getTypeInfo :: Connection -> PQ.Oid -> IO TypeInfo
src/Database/PostgreSQL/Simple/Types.hs view
@@ -24,6 +24,7 @@     , Oid(..)     , (:.)(..)     , Savepoint(..)+    , PGArray(..)     ) where  import Blaze.ByteString.Builder (toByteString)@@ -115,6 +116,11 @@  -- | Wrap binary data for use as a @bytea@ value. newtype Binary a = Binary {fromBinary :: a}+    deriving (Eq, Ord, Read, Show, Typeable, Functor)+++-- | Wrap a list for use as a PostgreSQL array.+newtype PGArray a = PGArray {fromPGArray :: [a]}     deriving (Eq, Ord, Read, Show, Typeable, Functor)  -- | A composite type to parse your custom data structures without