postgresql-simple-0.5.3.0: Mid-Level PostgreSQL client library

Copyright (c) 2011-2015 Leon P Smith BSD3 Leon P Smith experimental None Haskell98

Database.PostgreSQL.Simple.Internal

Description

Internal bits. This interface is less stable and can change at any time. In particular this means that while the rest of the postgresql-simple package endeavors to follow the package versioning policy, this module does not. Also, at the moment there are things in here that aren't particularly internal and are exported elsewhere; these will eventually disappear from this module.

Synopsis

# Documentation

data Field Source #

You don't particularly want to retain these structures for a long period of time, as they will retain the entire query result, not just the field metadata

Constructors

 Field Fieldsresult :: !Result column :: !Column typeOid :: !OidThis returns the type oid associated with the column. Analogous to libpq's PQftype.

Constructors

 Connection Fields

Instances

 Source # Methods

data SqlError Source #

Constructors

 SqlError Fields

Instances

 Source # Methods Source # MethodsshowList :: [SqlError] -> ShowS # Source # Methods

Exception thrown if query is used to perform an INSERT-like operation, or execute is used to perform a SELECT-like operation.

Constructors

 QueryError FieldsqeMessage :: String qeQuery :: Query

Instances

 Source # Methods Source # MethodsshowList :: [QueryError] -> ShowS # Source # Methods

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 FieldsfmtMessage :: String fmtQuery :: Query fmtParams :: [ByteString]

Instances

 Source # Methods Source # MethodsshowList :: [FormatError] -> ShowS # Source # Methods

Constructors

 ConnectInfo Fields

Instances

 Source # Methods Source # Methods Source # MethodsshowList :: [ConnectInfo] -> ShowS #

Default information for setting up a connection.

Defaults are as follows:

• Server on localhost
• Port on 5432
• User postgres
• Database postgres

Use as in the following example:

connect defaultConnectInfo { connectHost = "db.example.com" }

Connect with the given username to the given database. Will throw an exception if it cannot connect.

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. 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.

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.

Turns a ConnectInfo data structure into a libpq connection string.

A version of execute that does not perform query substitution.

withConnection :: Connection -> (Connection -> IO a) -> IO a Source #

Atomically perform an action with the database handle, if there is one.

data Row Source #

Constructors

 Row Fieldsrow :: !Row rowresult :: !Result

newtype RowParser a Source #

Constructors

 RP FieldsunRP :: ReaderT Row (StateT Column Conversion) a

Instances

 Source # Methods(>>=) :: RowParser a -> (a -> RowParser b) -> RowParser b #(>>) :: RowParser a -> RowParser b -> RowParser b #return :: a -> RowParser a #fail :: String -> RowParser a # Source # Methodsfmap :: (a -> b) -> RowParser a -> RowParser b #(<$) :: a -> RowParser b -> RowParser a # Source # Methodspure :: a -> RowParser a #(<*>) :: RowParser (a -> b) -> RowParser a -> RowParser b #(*>) :: RowParser a -> RowParser b -> RowParser b #(<*) :: RowParser a -> RowParser b -> RowParser a # Source # Methods(<|>) :: RowParser a -> RowParser a -> RowParser a #some :: RowParser a -> RowParser [a] #many :: RowParser a -> RowParser [a] # newtype Conversion a Source # Constructors  Conversion FieldsrunConversion :: Connection -> IO (Ok a) Instances  Source # Methods(>>=) :: Conversion a -> (a -> Conversion b) -> Conversion b #(>>) :: Conversion a -> Conversion b -> Conversion b #return :: a -> Conversion a # Source # Methodsfmap :: (a -> b) -> Conversion a -> Conversion b #(<$) :: a -> Conversion b -> Conversion a # Source # Methodspure :: a -> Conversion a #(<*>) :: Conversion (a -> b) -> Conversion a -> Conversion b #(*>) :: Conversion a -> Conversion b -> Conversion b #(<*) :: Conversion a -> Conversion b -> Conversion a # Source # Methods(<|>) :: Conversion a -> Conversion a -> Conversion a #some :: Conversion a -> Conversion [a] #many :: Conversion a -> Conversion [a] # Source # Methodsmplus :: Conversion a -> Conversion a -> Conversion a #

Quote bytestring or throw FormatError

Arguments

 :: Connection Connection for string escaping -> Query Query for message error -> [Action] List of parameters for message error -> Action Action to build -> IO Builder