postgresql-simple 0.4.2.1 → 0.4.2.2
raw patch · 5 files changed
+51/−15 lines, 5 filesdep ~basedep ~scientific
Dependency ranges changed: base, scientific
Files
- postgresql-simple.cabal +2/−2
- src/Database/PostgreSQL/Simple.hs +33/−4
- src/Database/PostgreSQL/Simple/FromField.hs +6/−3
- src/Database/PostgreSQL/Simple/FromRow.hs-boot +3/−4
- src/Database/PostgreSQL/Simple/ToField.hs +7/−2
postgresql-simple.cabal view
@@ -1,5 +1,5 @@ Name: postgresql-simple-Version: 0.4.2.1+Version: 0.4.2.2 Synopsis: Mid-Level PostgreSQL client library Description: Mid-Level PostgreSQL client library, forked from mysql-simple.@@ -81,7 +81,7 @@ source-repository this type: git location: http://github.com/lpsmith/postgresql-simple- tag: v0.4.2.1+ tag: v0.4.2.2 test-suite test type: exitcode-stdio-1.0
src/Database/PostgreSQL/Simple.hs view
@@ -331,7 +331,8 @@ -- -- Returns the number of rows affected. ----- Throws 'FormatError' if the query could not be formatted correctly.+-- Throws 'FormatError' if the query could not be formatted correctly, or+-- a 'SqlError' exception if the backend returns an error. execute :: (ToRow q) => Connection -> Query -> q -> IO Int64 execute conn template qs = do result <- exec conn =<< formatQuery conn template qs@@ -340,9 +341,12 @@ -- | Execute a multi-row @INSERT@, @UPDATE@, or other SQL query that is not -- expected to return results. ----- Returns the number of rows affected.+-- Returns the number of rows affected. If the list of parameters is empty,+-- this function will simply return 0 without issuing the query to the backend.+-- If this is not desired, consider using the 'Values' constructor instead. ----- Throws 'FormatError' if the query could not be formatted correctly.+-- Throws 'FormatError' if the query could not be formatted correctly, or+-- a 'SqlError' exception if the backend returns an error. -- -- For example, here's a command that inserts two rows into a table -- with two columns:@@ -377,6 +381,10 @@ -- in cases where you are only inserting a single row, and do not need -- functionality analogous to 'executeMany'. --+-- If the list of parameters is empty, this function will simply return @[]@+-- without issuing the query to the backend. If this is not desired,+-- consider using the 'Values' constructor instead.+-- -- Throws 'FormatError' if the query could not be formatted correctly. returning :: (ToRow q, FromRow r) => Connection -> Query -> [q] -> IO [r] returning _ _ [] = return []@@ -399,6 +407,9 @@ -- using 'execute' instead of 'query'). -- -- * 'ResultError': result conversion failed.+--+-- * 'SqlError': the postgresql backend returned an error, e.g.+-- a syntax or type error, or an incorrect table or column name. query :: (ToRow q, FromRow r) => Connection -> Query -> q -> IO [r] query = queryWith fromRow @@ -428,6 +439,12 @@ -- This fold is /not/ strict. The stream consumer is responsible for -- forcing the evaluation of its result to avoid space leaks. --+-- This is implemented using a database cursor. As such, this requires+-- a transaction. This function will detect whether or not there is a+-- transaction in progress, and will create a 'ReadCommitted' 'ReadOnly'+-- transaction if needed. The cursor is given a unique temporary name,+-- so the consumer may itself call fold.+-- -- Exceptions that may be thrown: -- -- * 'FormatError': the query string could not be formatted correctly.@@ -436,7 +453,9 @@ -- using 'execute' instead of 'query'). -- -- * 'ResultError': result conversion failed.-+--+-- * 'SqlError': the postgresql backend returned an error, e.g.+-- a syntax or type error, or an incorrect table or column name. fold :: ( FromRow row, ToRow params ) => Connection -> Query@@ -446,6 +465,9 @@ -> IO a fold = foldWithOptions defaultFoldOptions +-- | Number of rows to fetch at a time. 'Automatic' currently defaults+-- to 256 rows, although it might be nice to make this more intelligent+-- based on e.g. the average size of the rows. data FetchQuantity = Automatic | Fixed !Int@@ -456,12 +478,19 @@ transactionMode :: !TransactionMode } +-- | defaults to 'Automatic', and 'TransactionMode' 'ReadCommitted' 'ReadOnly' defaultFoldOptions :: FoldOptions defaultFoldOptions = FoldOptions { fetchQuantity = Automatic, transactionMode = TransactionMode ReadCommitted ReadOnly } +-- | The same as 'fold', but this provides a bit more control over+-- lower-level details. Currently, the number of rows fetched per+-- round-trip to the server and the transaction mode may be adjusted+-- accordingly. If the connection is already in a transaction,+-- then the existing transaction is used and thus the 'transactionMode'+-- option is ignored. foldWithOptions :: ( FromRow row, ToRow params ) => FoldOptions -> Connection
src/Database/PostgreSQL/Simple/FromField.hs view
@@ -27,9 +27,12 @@ conversion routine, which sacrifices some accuracy for speed. If you need accuracy, consider first converting data to a 'Scientific' or 'Rational' type, and then converting to a floating-point type. If you are defining-your own 'ToRow' instances, this can be acheived simply by-@'fromRational' '<$>' 'field'@, although this idiom additionally compatible-with PostgreSQL's @numeric@ type.+your own 'Database.PostgreSQL.Simple.FromRow.FromRow' instances, this can be +acheived simply by +@'fromRational' '<$>' 'Database.PostgreSQL.Simple.FromRow.field'@, although +this idiom is additionally compatible with PostgreSQL's @numeric@ type.+If this is unacceptable, you may find +'Database.PostgreSQL.Simple.FromRow.fieldWith' useful. Because 'FromField' is a typeclass, one may provide conversions to additional Haskell types without modifying postgresql-simple. This is
src/Database/PostgreSQL/Simple/FromRow.hs-boot view
@@ -8,11 +8,10 @@ instance (FromField a) => FromRow (Only a) instance (FromField a, FromField b) => FromRow (a,b)-instance (FromField a, FromField b, FromField c, FromField d) +instance (FromField a, FromField b, FromField c, FromField d) => FromRow (a,b,c,d)-instance (FromField a, FromField b, FromField c, FromField d, FromField e) +instance (FromField a, FromField b, FromField c, FromField d, FromField e) => FromRow (a,b,c,d,e) instance (FromField a, FromField b, FromField c, FromField d, FromField e- ,FromField f) + ,FromField f) => FromRow (a,b,c,d,e,f)-
src/Database/PostgreSQL/Simple/ToField.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE DeriveDataTypeable, DeriveFunctor #-}+{-# LANGUAGE CPP, DeriveDataTypeable, DeriveFunctor #-} {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} ------------------------------------------------------------------------------@@ -48,7 +48,12 @@ import qualified Data.Vector as V import qualified Database.PostgreSQL.LibPQ as PQ import Database.PostgreSQL.Simple.Time-import Data.Scientific (Scientific, scientificBuilder)+import Data.Scientific (Scientific)+#if MIN_VERSION_scientific(0,3,0)+import Data.Text.Lazy.Builder.Scientific (scientificBuilder)+#else+import Data.Scientific (scientificBuilder)+#endif -- | How to render an element when substituting it into a query. data Action =