| Stability | experimental |
|---|---|
| Maintainer | Leon P Smith <leon@melding-monads.com> |
| Safe Haskell | None |
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.
- data Field = Field {}
- type TypeInfoCache = IntMap TypeInfo
- data Connection = Connection {
- connectionHandle :: !(MVar Connection)
- connectionObjects :: !(MVar TypeInfoCache)
- connectionTempNameCounter :: !(IORef Int64)
- data SqlError = SqlError {
- sqlState :: ByteString
- sqlExecStatus :: ExecStatus
- sqlErrorMsg :: ByteString
- sqlErrorDetail :: ByteString
- sqlErrorHint :: ByteString
- fatalError :: ByteString -> SqlError
- data QueryError = QueryError {}
- data ConnectInfo = ConnectInfo {
- connectHost :: String
- connectPort :: Word16
- connectUser :: String
- connectPassword :: String
- connectDatabase :: String
- defaultConnectInfo :: ConnectInfo
- connect :: ConnectInfo -> IO Connection
- connectPostgreSQL :: ByteString -> IO Connection
- connectdb :: ByteString -> IO Connection
- postgreSQLConnectionString :: ConnectInfo -> ByteString
- oid2int :: Oid -> Int
- exec :: Connection -> ByteString -> IO Result
- execute_ :: Connection -> Query -> IO Int64
- finishExecute :: Connection -> Query -> Result -> IO Int64
- throwResultError :: ByteString -> Result -> ExecStatus -> IO a
- disconnectedError :: SqlError
- withConnection :: Connection -> (Connection -> IO a) -> IO a
- close :: Connection -> IO ()
- newNullConnection :: IO Connection
- data Row = Row {}
- newtype RowParser a = RP {}
- liftRowParser :: IO a -> RowParser a
- newtype Conversion a = Conversion {
- runConversion :: Connection -> IO (Ok a)
- liftConversion :: IO a -> Conversion a
- conversionMap :: (Ok a -> Ok b) -> Conversion a -> Conversion b
- conversionError :: Exception err => err -> Conversion a
- newTempName :: Connection -> IO Query
- fdError :: ByteString -> IOError
- libPQError :: ByteString -> IOError
- throwLibPQError :: Connection -> ByteString -> IO a
Documentation
A Field represents metadata about a particular field
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
type TypeInfoCache = IntMap TypeInfoSource
data Connection Source
Constructors
| Connection | |
Fields
| |
Constructors
| SqlError | |
Fields
| |
fatalError :: ByteString -> SqlErrorSource
data QueryError Source
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
| Eq QueryError | |
| Show QueryError | |
| Typeable QueryError | |
| Exception QueryError |
data ConnectInfo Source
Constructors
| ConnectInfo | |
Fields
| |
Instances
| Eq ConnectInfo | |
| Read ConnectInfo | |
| Show ConnectInfo | |
| Typeable ConnectInfo |
defaultConnectInfo :: ConnectInfoSource
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" } connect :: ConnectInfo -> IO ConnectionSource
Connect with the given username to the given database. Will throw an exception if it cannot connect.
connectPostgreSQL :: ByteString -> IO ConnectionSource
Attempt to make a connection based on a libpq connection string. See http://www.postgresql.org/docs/9.3/static/libpq-connect.html for more information. 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 http://www.postgresql.org/docs/9.3/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 http://www.postgresql.org/docs/9.3/static/client-authentication.html for more information regarding the authentication process.
connectdb :: ByteString -> IO ConnectionSource
postgreSQLConnectionString :: ConnectInfo -> ByteStringSource
Turns a ConnectInfo data structure into a libpq connection string.
exec :: Connection -> ByteString -> IO ResultSource
execute_ :: Connection -> Query -> IO Int64Source
A version of execute that does not perform query substitution.
finishExecute :: Connection -> Query -> Result -> IO Int64Source
throwResultError :: ByteString -> Result -> ExecStatus -> IO aSource
withConnection :: Connection -> (Connection -> IO a) -> IO aSource
Atomically perform an action with the database handle, if there is one.
close :: Connection -> IO ()Source
liftRowParser :: IO a -> RowParser aSource
newtype Conversion a Source
Constructors
| Conversion | |
Fields
| |
Instances
| Monad Conversion | |
| Functor Conversion | |
| MonadPlus Conversion | |
| Applicative Conversion | |
| Alternative Conversion |
liftConversion :: IO a -> Conversion aSource
conversionMap :: (Ok a -> Ok b) -> Conversion a -> Conversion bSource
conversionError :: Exception err => err -> Conversion aSource
newTempName :: Connection -> IO QuerySource
libPQError :: ByteString -> IOErrorSource
throwLibPQError :: Connection -> ByteString -> IO aSource