-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | PostgreSQL backend for the Selda database EDSL.
--   
--   PostgreSQL backend for the Selda database EDSL. Requires the
--   PostgreSQL <tt>libpq</tt> development libraries to be installed.
@package selda-postgresql
@version 0.1.7.2


-- | PostgreSQL backend for Selda.
module Database.Selda.PostgreSQL

-- | PostgreSQL connection information.
data PGConnectInfo
PGConnectInfo :: Text -> Int -> Text -> Maybe Text -> Maybe Text -> Maybe Text -> PGConnectInfo

-- | Host to connect to.
[pgHost] :: PGConnectInfo -> Text

-- | Port to connect to.
[pgPort] :: PGConnectInfo -> Int

-- | Name of database to use.
[pgDatabase] :: PGConnectInfo -> Text

-- | Schema to use upon connection.
[pgSchema] :: PGConnectInfo -> Maybe Text

-- | Username for authentication, if necessary.
[pgUsername] :: PGConnectInfo -> Maybe Text

-- | Password for authentication, if necessary.
[pgPassword] :: PGConnectInfo -> Maybe Text

-- | Perform the given computation over a PostgreSQL database. The database
--   connection is guaranteed to be closed when the computation terminates.
withPostgreSQL :: (MonadIO m, MonadThrow m, MonadMask m) => PGConnectInfo -> SeldaT m a -> m a

-- | Connect to the given database on the given host, on the default
--   PostgreSQL port (5432):
--   
--   <pre>
--   withPostgreSQL ("my_db" `on` "example.com") $ do
--     ...
--   </pre>
on :: Text -> Text -> PGConnectInfo
infixl 7 `on`

-- | Add the given username and password to the given connection
--   information:
--   
--   <pre>
--   withPostgreSQL ("my_db" `on` "example.com" `auth` ("user", "pass")) $ do
--     ...
--   </pre>
--   
--   For more precise control over the connection options, you should
--   modify the <a>PGConnectInfo</a> directly.
auth :: PGConnectInfo -> (Text, Text) -> PGConnectInfo
infixl 4 `auth`

-- | Open a new PostgreSQL connection. The connection will persist across
--   calls to <a>runSeldaT</a>, and must be explicitly closed using
--   <a>seldaClose</a> when no longer needed.
pgOpen :: (MonadIO m, MonadMask m) => PGConnectInfo -> m SeldaConnection
pgOpen' :: (MonadIO m, MonadMask m) => Maybe Text -> ByteString -> m SeldaConnection

-- | Close a reusable Selda connection. Closing a connection while in use
--   is undefined. Passing a closed connection to <a>runSeldaT</a> results
--   in a <a>SeldaError</a> being thrown. Closing a connection more than
--   once is a no-op.
seldaClose :: MonadIO m => SeldaConnection -> m ()

-- | Convert <a>PGConnectInfo</a> into <tt>ByteString</tt>
pgConnString :: PGConnectInfo -> ByteString
pgPPConfig :: PPConfig
