| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
OpenTelemetry.Instrumentation.PostgresqlSimple
Description
Database semantic conventions have been declared stable. Opt-in by setting the environment variable OTEL_SEMCONV_STABILITY_OPT_IN to - "database" - to use the stable conventions - "database/dup" - to emit both the old and the stable conventions Otherwise, the old conventions will be used. The stable conventions will replace the old conventions in the next major release of this library.
Synopsis
- staticConnectionAttributes :: (HasCallStack, MonadIO m) => Connection -> m (HashMap Text Attribute)
- query :: (HasCallStack, MonadIO m, ToRow q, FromRow r) => Connection -> Query -> q -> m [r]
- query_ :: (HasCallStack, MonadIO m, FromRow r) => Connection -> Query -> m [r]
- queryWith :: (HasCallStack, MonadIO m, ToRow q) => RowParser r -> Connection -> Query -> q -> m [r]
- queryWith_ :: MonadIO m => RowParser r -> Connection -> Query -> m [r]
- fold :: (HasCallStack, MonadUnliftIO m, FromRow row, ToRow params) => Connection -> Query -> params -> a -> (a -> row -> m a) -> m a
- foldWithOptions :: (HasCallStack, MonadUnliftIO m, FromRow row, ToRow params) => FoldOptions -> Connection -> Query -> params -> a -> (a -> row -> m a) -> m a
- fold_ :: (HasCallStack, MonadUnliftIO m, FromRow r) => Connection -> Query -> a -> (a -> r -> m a) -> m a
- foldWithOptions_ :: (HasCallStack, MonadUnliftIO m, FromRow r) => FoldOptions -> Connection -> Query -> a -> (a -> r -> m a) -> m a
- forEach :: (MonadUnliftIO m, ToRow q, FromRow r) => p1 -> p2 -> p3 -> p4 -> Connection -> Query -> q -> (r -> m ()) -> m ()
- forEach_ :: (HasCallStack, MonadUnliftIO m, FromRow r) => Connection -> Query -> (r -> m ()) -> m ()
- returning :: (HasCallStack, MonadIO m, ToRow q, FromRow r) => Connection -> Query -> [q] -> m [r]
- foldWith :: (HasCallStack, MonadUnliftIO m, ToRow params) => RowParser row -> Connection -> Query -> params -> a -> (a -> row -> m a) -> m a
- foldWithOptionsAndParser :: (HasCallStack, MonadUnliftIO m, ToRow params) => FoldOptions -> RowParser row -> Connection -> Query -> params -> a -> (a -> row -> m a) -> m a
- foldWith_ :: MonadUnliftIO m => RowParser r -> Connection -> Query -> a -> (a -> r -> m a) -> m a
- foldWithOptionsAndParser_ :: MonadUnliftIO m => FoldOptions -> RowParser r -> Connection -> Query -> a -> (a -> r -> m a) -> m a
- forEachWith :: (HasCallStack, MonadUnliftIO m, ToRow q) => RowParser r -> Connection -> Query -> q -> (r -> m ()) -> m ()
- forEachWith_ :: MonadUnliftIO m => RowParser r -> Connection -> Query -> (r -> m ()) -> m ()
- returningWith :: (HasCallStack, MonadIO m, ToRow q) => RowParser r -> Connection -> Query -> [q] -> m [r]
- execute :: (HasCallStack, MonadIO m, ToRow q) => Connection -> Query -> q -> m Int64
- execute_ :: MonadIO m => Connection -> Query -> m Int64
- executeMany :: (HasCallStack, MonadIO m, ToRow q) => Connection -> Query -> [q] -> m Int64
- newtype Only a = Only {
- fromOnly :: a
- data FetchQuantity
- close :: Connection -> IO ()
- newtype In a = In a
- newtype Binary a = Binary {
- fromBinary :: a
- connect :: ConnectInfo -> IO Connection
- data Connection
- data ExecStatus
- commit :: Connection -> IO ()
- data h :. t = h :. t
- data Query
- class ToRow a
- class FromRow a
- data ConnectInfo = ConnectInfo {}
- data FormatError = FormatError {
- fmtMessage :: String
- fmtQuery :: Query
- fmtParams :: [ByteString]
- data QueryError = QueryError {}
- data SqlError = SqlError {}
- data SomePostgreSqlException = Exception e => SomePostgreSqlException e
- defaultConnectInfo :: ConnectInfo
- withConnect :: ConnectInfo -> (Connection -> IO c) -> IO c
- connectPostgreSQL :: ByteString -> IO Connection
- postgreSQLConnectionString :: ConnectInfo -> ByteString
- withTransaction :: Connection -> IO a -> IO a
- rollback :: Connection -> IO ()
- begin :: Connection -> IO ()
- withSavepoint :: Connection -> IO a -> IO a
- data ResultError
- = Incompatible { }
- | UnexpectedNull { }
- | ConversionFailed { }
- data FoldOptions = FoldOptions {}
- formatQuery :: ToRow q => Connection -> Query -> q -> IO ByteString
- formatMany :: ToRow q => Connection -> Query -> [q] -> IO ByteString
- defaultFoldOptions :: FoldOptions
- pgsSpan :: HasCallStack => Connection -> ByteString -> IO a -> IO a
- extractOperationName :: ByteString -> Maybe Text
Documentation
staticConnectionAttributes :: (HasCallStack, MonadIO m) => Connection -> m (HashMap Text Attribute) Source #
Get attributes that can be attached to a span denoting some database action
Queries that return results
query :: (HasCallStack, MonadIO m, ToRow q, FromRow r) => Connection -> Query -> q -> m [r] Source #
Instrumented version of query
query_ :: (HasCallStack, MonadIO m, FromRow r) => Connection -> Query -> m [r] Source #
Instrumented version of query_
Queries taking parser as argument
queryWith :: (HasCallStack, MonadIO m, ToRow q) => RowParser r -> Connection -> Query -> q -> m [r] Source #
Instrumented version of queryWith
queryWith_ :: MonadIO m => RowParser r -> Connection -> Query -> m [r] Source #
Instrumented version of queryWith_
Queries that stream results
fold :: (HasCallStack, MonadUnliftIO m, FromRow row, ToRow params) => Connection -> Query -> params -> a -> (a -> row -> m a) -> m a Source #
Instrumented version of fold
foldWithOptions :: (HasCallStack, MonadUnliftIO m, FromRow row, ToRow params) => FoldOptions -> Connection -> Query -> params -> a -> (a -> row -> m a) -> m a Source #
Instrumented version of foldWithOptions
fold_ :: (HasCallStack, MonadUnliftIO m, FromRow r) => Connection -> Query -> a -> (a -> r -> m a) -> m a Source #
Instrumented version of fold_
foldWithOptions_ :: (HasCallStack, MonadUnliftIO m, FromRow r) => FoldOptions -> Connection -> Query -> a -> (a -> r -> m a) -> m a Source #
Instrumented version of foldWithOptions_
forEach :: (MonadUnliftIO m, ToRow q, FromRow r) => p1 -> p2 -> p3 -> p4 -> Connection -> Query -> q -> (r -> m ()) -> m () Source #
Instrumented version of forEach
forEach :: (HasCallStack, MonadUnliftIO m, ToRow q, FromRow r) => Connection -> Query -> q -> (r -> m ()) -> m ()
forEach_ :: (HasCallStack, MonadUnliftIO m, FromRow r) => Connection -> Query -> (r -> m ()) -> m () Source #
Instrumented version of forEach_
returning :: (HasCallStack, MonadIO m, ToRow q, FromRow r) => Connection -> Query -> [q] -> m [r] Source #
Instrumented version of returning
Queries that stream results taking a parser as an argument
foldWith :: (HasCallStack, MonadUnliftIO m, ToRow params) => RowParser row -> Connection -> Query -> params -> a -> (a -> row -> m a) -> m a Source #
Instrumented version of foldWith
foldWithOptionsAndParser :: (HasCallStack, MonadUnliftIO m, ToRow params) => FoldOptions -> RowParser row -> Connection -> Query -> params -> a -> (a -> row -> m a) -> m a Source #
Instrumented version of foldWithOptionsAndParser
foldWith_ :: MonadUnliftIO m => RowParser r -> Connection -> Query -> a -> (a -> r -> m a) -> m a Source #
Instrumented version of foldWith_
foldWithOptionsAndParser_ :: MonadUnliftIO m => FoldOptions -> RowParser r -> Connection -> Query -> a -> (a -> r -> m a) -> m a Source #
Instrumented version of foldWithOptionsAndParser_
forEachWith :: (HasCallStack, MonadUnliftIO m, ToRow q) => RowParser r -> Connection -> Query -> q -> (r -> m ()) -> m () Source #
Instrumented version of forEachWith
forEachWith_ :: MonadUnliftIO m => RowParser r -> Connection -> Query -> (r -> m ()) -> m () Source #
Instrumented version of forEachWith_
returningWith :: (HasCallStack, MonadIO m, ToRow q) => RowParser r -> Connection -> Query -> [q] -> m [r] Source #
A version of returning taking parser as argument
Statements that do not return results
execute :: (HasCallStack, MonadIO m, ToRow q) => Connection -> Query -> q -> m Int64 Source #
Instrumented version of execute
executeMany :: (HasCallStack, MonadIO m, ToRow q) => Connection -> Query -> [q] -> m Int64 Source #
Instrumented version of executeMany
Reexported functions
The 1-tuple type or single-value "collection".
This type is structurally equivalent to the
Identity type, but its intent is more
about serving as the anonymous 1-tuple type missing from Haskell for attaching
typeclass instances.
Parameter usage example:
encodeSomething (Only (42::Int))Result usage example:
xs <- decodeSomething
forM_ xs $ \(Only id) -> {- ... -}Instances
| Functor Only | |||||
| NFData a => NFData (Only a) | |||||
Defined in Data.Tuple.Only | |||||
| Data a => Data (Only a) | |||||
Defined in Data.Tuple.Only Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Only a -> c (Only a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Only a) # toConstr :: Only a -> Constr # dataTypeOf :: Only a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Only a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Only a)) # gmapT :: (forall b. Data b => b -> b) -> Only a -> Only a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r # gmapQ :: (forall d. Data d => d -> u) -> Only a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Only a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Only a -> m (Only a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Only a -> m (Only a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Only a -> m (Only a) # | |||||
| Generic (Only a) | |||||
Defined in Data.Tuple.Only Associated Types
| |||||
| Read a => Read (Only a) | |||||
| Show a => Show (Only a) | |||||
| Eq a => Eq (Only a) | |||||
| Ord a => Ord (Only a) | |||||
| FromField a => FromRow (Only a) | |||||
Defined in Database.PostgreSQL.Simple.FromRow | |||||
| FromField a => FromRow (Maybe (Only a)) | |||||
| ToField a => ToRow (Only a) | |||||
Defined in Database.PostgreSQL.Simple.ToRow | |||||
| type Rep (Only a) | |||||
Defined in Data.Tuple.Only | |||||
data FetchQuantity #
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.
close :: Connection -> IO () #
Wrap a list of values for use in an IN clause. Replaces a
single "?" character with a parenthesized list of rendered
values.
Example:
query c "select * from whatever where id in ?" (Only (In [3,4,5]))
Note that In [] expands to (null), which works as expected in
the query above, but evaluates to the logical null value on every
row instead of TRUE. This means that changing the query above
to ... id NOT in ? and supplying the empty list as the parameter
returns zero rows, instead of all of them as one would expect.
Since postgresql doesn't seem to provide a syntax for actually specifying an empty list, which could solve this completely, there are two workarounds particularly worth mentioning, namely:
Use postgresql-simple's
Valuestype instead, which can handle the empty case correctly. Note however that while specifying the postgresql type"int4"is mandatory in the empty case, specifying the haskell typeValues (Only Int)would not normally be needed in realistic use cases.query c "select * from whatever where id not in ?" (Only (Values ["int4"] [] :: Values (Only Int)))Use sql's
COALESCEoperator to turn a logicalnullinto the correct boolean. Note however that the correct boolean depends on the use case:query c "select * from whatever where coalesce(id NOT in ?, TRUE)" (Only (In [] :: In [Int]))query c "select * from whatever where coalesce(id IN ?, FALSE)" (Only (In [] :: In [Int]))Note that at as of PostgreSQL 9.4, the query planner cannot see inside the
COALESCEoperator, so if you have an index onidthen you probably don't want to write the last example withCOALESCE, which would result in a table scan. There are further caveats ifidcan be null or you want null treated sensibly as a component ofINorNOT IN.
Constructors
| In a |
Wrap binary data for use as a bytea value.
Constructors
| Binary | |
Fields
| |
Instances
| Functor Binary | |
| Read a => Read (Binary a) | |
| Show a => Show (Binary a) | |
| Eq a => Eq (Binary a) | |
| Ord a => Ord (Binary a) | |
Defined in Database.PostgreSQL.Simple.Types | |
| FromField (Binary ByteString) | bytea |
Defined in Database.PostgreSQL.Simple.FromField Methods | |
| FromField (Binary ByteString) | bytea |
Defined in Database.PostgreSQL.Simple.FromField Methods | |
| ToField (Binary ByteString) | |
Defined in Database.PostgreSQL.Simple.ToField Methods toField :: Binary ByteString -> Action # | |
| ToField (Binary ByteString) | |
Defined in Database.PostgreSQL.Simple.ToField Methods toField :: Binary ByteString -> Action # | |
connect :: ConnectInfo -> IO Connection #
Connect with the given username to the given database. Will throw an exception if it cannot connect.
data Connection #
Instances
| Eq Connection | |
Defined in Database.PostgreSQL.Simple.Internal | |
data ExecStatus #
Constructors
| EmptyQuery | The string sent to the server was empty. |
| CommandOk | Successful completion of a command returning no data. |
| TuplesOk | Successful completion of a command returning data (such as a SELECT or SHOW). |
| CopyOut | Copy Out (from server) data transfer started. |
| CopyIn | Copy In (to server) data transfer started. |
| CopyBoth | Copy In/Out data transfer started. |
| BadResponse | The server's response was not understood. |
| NonfatalError | A nonfatal error (a notice or warning) occurred. |
| FatalError | A fatal error occurred. |
| SingleTuple | The |
| PipelineSync | The Since: postgresql-libpq-0.11.0.0 |
| PipelineAbort | The Since: postgresql-libpq-0.11.0.0 |
Instances
| Enum ExecStatus | |
Defined in Database.PostgreSQL.LibPQ.Enums Methods succ :: ExecStatus -> ExecStatus # pred :: ExecStatus -> ExecStatus # toEnum :: Int -> ExecStatus # fromEnum :: ExecStatus -> Int # enumFrom :: ExecStatus -> [ExecStatus] # enumFromThen :: ExecStatus -> ExecStatus -> [ExecStatus] # enumFromTo :: ExecStatus -> ExecStatus -> [ExecStatus] # enumFromThenTo :: ExecStatus -> ExecStatus -> ExecStatus -> [ExecStatus] # | |
| Show ExecStatus | |
Defined in Database.PostgreSQL.LibPQ.Enums Methods showsPrec :: Int -> ExecStatus -> ShowS # show :: ExecStatus -> String # showList :: [ExecStatus] -> ShowS # | |
| Eq ExecStatus | |
Defined in Database.PostgreSQL.LibPQ.Enums | |
| FromCInt ExecStatus | |
Defined in Database.PostgreSQL.LibPQ.Enums Methods fromCInt :: CInt -> Maybe ExecStatus | |
| ToCInt ExecStatus | |
Defined in Database.PostgreSQL.LibPQ.Enums Methods toCInt :: ExecStatus -> CInt | |
commit :: Connection -> IO () #
Commit a transaction.
A composite type to parse your custom data structures without having to define dummy newtype wrappers every time.
instance FromRow MyData where ...
instance FromRow MyData2 where ...
then I can do the following for free:
res <- query' c "..."
forM res $ \(MyData{..} :. MyData2{..}) -> do
....
Constructors
| h :. t infixr 3 |
Instances
| (Read h, Read t) => Read (h :. t) | |
| (Show h, Show t) => Show (h :. t) | |
| (Eq h, Eq t) => Eq (h :. t) | |
| (Ord h, Ord t) => Ord (h :. t) | |
Defined in Database.PostgreSQL.Simple.Types | |
| (FromRow a, FromRow b) => FromRow (a :. b) | |
Defined in Database.PostgreSQL.Simple.FromRow | |
| (ToRow a, ToRow b) => ToRow (a :. b) | |
Defined in Database.PostgreSQL.Simple.ToRow | |
A query string. This type is intended to make it difficult to construct a SQL query by concatenating string fragments, as that is an extremely common way to accidentally introduce SQL injection vulnerabilities into an application.
This type is an instance of IsString, so the easiest way to
construct a query is to enable the OverloadedStrings language
extension and then simply write the query in double quotes.
{-# LANGUAGE OverloadedStrings #-}
import Database.PostgreSQL.Simple
q :: Query
q = "select ?"The underlying type is a ByteString, and literal Haskell strings
that contain Unicode characters will be correctly transformed to
UTF-8.
A collection type that can be turned into a list of rendering
Actions.
Instances should use the toField method of the ToField class
to perform conversion of each element of the collection.
You can derive ToRow for your data type using GHC generics, like this:
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics (Generic)
import Database.PostgreSQL.Simple (ToRow)
data User = User { name :: String, fileQuota :: Int }
deriving (Generic, ToRow)
Note that this only works for product types (e.g. records) and does not support sum types or recursive types.
Instances
A collection type that can be converted from a sequence of fields. Instances are provided for tuples up to 10 elements and lists of any length.
Note that instances can be defined outside of postgresql-simple, which is often useful. For example, here's an instance for a user-defined pair:
data User = User { name :: String, fileQuota :: Int }
instance FromRow User where
fromRow = User <$> field <*> field
The number of calls to field must match the number of fields returned
in a single row of the query result. Otherwise, a ConversionFailed
exception will be thrown.
You can also derive FromRow for your data type using GHC generics, like
this:
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics (Generic)
import Database.PostgreSQL.Simple (FromRow)
data User = User { name :: String, fileQuota :: Int }
deriving (Generic, FromRow)
Note that this only works for product types (e.g. records) and does not support sum types or recursive types.
Note that field evaluates its result to WHNF, so the caveats listed in
mysql-simple and very early versions of postgresql-simple no longer apply.
Instead, look at the caveats associated with user-defined implementations
of fromField.
Instances
data ConnectInfo #
Constructors
| ConnectInfo | |
Fields
| |
Instances
data FormatError #
Exception thrown if a Query could not be formatted correctly.
This may occur if the number of '?' characters in the query
string does not match the number of parameters provided.
Constructors
| FormatError | |
Fields
| |
Instances
| Exception FormatError | |
Defined in Database.PostgreSQL.Simple.Internal Methods toException :: FormatError -> SomeException # fromException :: SomeException -> Maybe FormatError # displayException :: FormatError -> String # backtraceDesired :: FormatError -> Bool # | |
| Show FormatError | |
Defined in Database.PostgreSQL.Simple.Internal Methods showsPrec :: Int -> FormatError -> ShowS # show :: FormatError -> String # showList :: [FormatError] -> ShowS # | |
| Eq FormatError | |
Defined in Database.PostgreSQL.Simple.Internal | |
data QueryError #
Exception thrown if query is used to perform an INSERT-like
operation, or execute is used to perform a SELECT-like operation.
Constructors
| QueryError | |
Instances
| Exception QueryError | |
Defined in Database.PostgreSQL.Simple.Internal Methods toException :: QueryError -> SomeException # fromException :: SomeException -> Maybe QueryError # displayException :: QueryError -> String # backtraceDesired :: QueryError -> Bool # | |
| Show QueryError | |
Defined in Database.PostgreSQL.Simple.Internal Methods showsPrec :: Int -> QueryError -> ShowS # show :: QueryError -> String # showList :: [QueryError] -> ShowS # | |
| Eq QueryError | |
Defined in Database.PostgreSQL.Simple.Internal | |
Constructors
| SqlError | |
Fields | |
Instances
| Exception SqlError | |
Defined in Database.PostgreSQL.Simple.Internal Methods toException :: SqlError -> SomeException # fromException :: SomeException -> Maybe SqlError # displayException :: SqlError -> String # backtraceDesired :: SqlError -> Bool # | |
| Show SqlError | |
| Eq SqlError | |
data SomePostgreSqlException #
Superclass for postgresql exceptions
Constructors
| Exception e => SomePostgreSqlException e |
Instances
| Exception SomePostgreSqlException | |
| Show SomePostgreSqlException | |
Defined in Database.PostgreSQL.Simple.Internal Methods showsPrec :: Int -> SomePostgreSqlException -> ShowS # show :: SomePostgreSqlException -> String # showList :: [SomePostgreSqlException] -> ShowS # | |
defaultConnectInfo :: ConnectInfo #
Default information for setting up a connection.
Defaults are as follows:
- Server on
localhost - Port on
5432 - User
postgres - No password
- Database
postgres
Use as in the following example:
connect defaultConnectInfo { connectHost = "db.example.com" }withConnect :: ConnectInfo -> (Connection -> IO c) -> IO c #
connectPostgreSQL :: ByteString -> IO Connection #
Attempt to make a connection based on a libpq connection string. See https://www.postgresql.org/docs/9.5/static/libpq-connect.html#LIBPQ-CONNSTRING for more information. Also note that environment variables also affect parameters not provided, parameters provided as the empty string, and a few other things; see https://www.postgresql.org/docs/9.5/static/libpq-envars.html for details. Here is an example with some of the most commonly used parameters:
host='db.somedomain.com' port=5432 ...
This attempts to connect to db.somedomain.com:5432. Omitting the port
will normally default to 5432.
On systems that provide unix domain sockets, omitting the host parameter
will cause libpq to attempt to connect via unix domain sockets.
The default filesystem path to the socket is constructed from the
port number and the DEFAULT_PGSOCKET_DIR constant defined in the
pg_config_manual.h header file. Connecting via unix sockets tends
to use the peer authentication method, which is very secure and
does not require a password.
On Windows and other systems without unix domain sockets, omitting
the host will default to localhost.
... dbname='postgres' user='postgres' password='secret \' \\ pw'
This attempts to connect to a database named postgres with
user postgres and password secret ' \ pw. Backslash
characters will have to be double-quoted in literal Haskell strings,
of course. Omitting dbname and user will both default to the
system username that the client process is running as.
Omitting password will default to an appropriate password found
in the pgpass file, or no password at all if a matching line is
not found. The path of the pgpass file may be specified by setting
the PGPASSFILE environment variable. See
https://www.postgresql.org/docs/9.5/static/libpq-pgpass.html for
more information regarding this file.
As all parameters are optional and the defaults are sensible, the empty connection string can be useful for development and exploratory use, assuming your system is set up appropriately.
On Unix, such a setup would typically consist of a local postgresql server listening on port 5432, as well as a system user, database user, and database sharing a common name, with permissions granted to the user on the database.
On Windows, in addition you will either need pg_hba.conf
to specify the use of the trust authentication method for
the connection, which may not be appropriate for multiuser
or production machines, or you will need to use a pgpass file
with the password or md5 authentication methods.
See https://www.postgresql.org/docs/9.5/static/client-authentication.html for more information regarding the authentication process.
SSL/TLS will typically "just work" if your postgresql server supports or
requires it. However, note that libpq is trivially vulnerable to a MITM
attack without setting additional SSL connection parameters. In
particular, sslmode needs to be set to require, verify-ca, or
verify-full in order to perform certificate validation. When sslmode
is require, then you will also need to specify a sslrootcert file,
otherwise no validation of the server's identity will be performed.
Client authentication via certificates is also possible via the
sslcert and sslkey parameters. See
https://www.postgresql.org/docs/9.5/static/libpq-ssl.html
for detailed information regarding libpq and SSL.
postgreSQLConnectionString :: ConnectInfo -> ByteString #
Turns a ConnectInfo data structure into a libpq connection string.
withTransaction :: Connection -> IO a -> IO a #
Execute an action inside a SQL transaction.
This function initiates a transaction with a "begin
transaction" statement, then executes the supplied action. If
the action succeeds, the transaction will be completed with
commit before this function returns.
If the action throws any kind of exception (not just a
PostgreSQL-related exception), the transaction will be rolled back using
rollback, then the exception will be rethrown.
For nesting transactions, see withSavepoint.
rollback :: Connection -> IO () #
Rollback a transaction.
begin :: Connection -> IO () #
Begin a transaction.
withSavepoint :: Connection -> IO a -> IO a #
Create a savepoint, and roll back to it if an error occurs. This may only be used inside of a transaction, and provides a sort of "nested transaction".
See https://www.postgresql.org/docs/9.5/static/sql-savepoint.html
data ResultError #
Exception thrown if conversion from a SQL value to a Haskell value fails.
Constructors
| Incompatible | The SQL and Haskell types are not compatible. |
Fields
| |
| UnexpectedNull | A SQL |
Fields
| |
| ConversionFailed | The SQL value could not be parsed, or could not be represented as a valid Haskell value, or an unexpected low-level error occurred (e.g. mismatch between metadata and actual data in a row). |
Fields
| |
Instances
| Exception ResultError | |
Defined in Database.PostgreSQL.Simple.FromField Methods toException :: ResultError -> SomeException # fromException :: SomeException -> Maybe ResultError # displayException :: ResultError -> String # backtraceDesired :: ResultError -> Bool # | |
| Show ResultError | |
Defined in Database.PostgreSQL.Simple.FromField Methods showsPrec :: Int -> ResultError -> ShowS # show :: ResultError -> String # showList :: [ResultError] -> ShowS # | |
| Eq ResultError | |
Defined in Database.PostgreSQL.Simple.FromField | |
data FoldOptions #
Constructors
| FoldOptions | |
Fields | |
formatQuery :: ToRow q => Connection -> Query -> q -> IO ByteString #
Format a query string.
This function is exposed to help with debugging and logging. Do not use it to prepare queries for execution.
String parameters are escaped according to the character set in use
on the Connection.
Throws FormatError if the query string could not be formatted
correctly.
formatMany :: ToRow q => Connection -> Query -> [q] -> IO ByteString #
Format a query string with a variable number of rows.
This function is exposed to help with debugging and logging. Do not use it to prepare queries for execution.
The query string must contain exactly one substitution group,
identified by the SQL keyword "VALUES" (case insensitive)
followed by an "(" character, a series of one or more "?"
characters separated by commas, and a ")" character. White
space in a substitution group is permitted.
Throws FormatError if the query string could not be formatted
correctly.
defaultFoldOptions :: FoldOptions #
defaults to Automatic, and TransactionMode ReadCommitted ReadOnly
Utility functions
pgsSpan :: HasCallStack => Connection -> ByteString -> IO a -> IO a Source #
Function to help with wrapping functions in postgresql-simple