Safe Haskell | None |
---|---|
Language | Haskell2010 |
Database.Persist.Postgresql
Description
A postgresql backend for persistent.
Synopsis
- withPostgresqlPool :: (MonadLogger m, MonadUnliftIO m) => ConnectionString -> Int -> (Pool SqlBackend -> m a) -> m a
- withPostgresqlPoolWithVersion :: (MonadUnliftIO m, MonadLogger m) => (Connection -> IO (Maybe Double)) -> ConnectionString -> Int -> (Pool SqlBackend -> m a) -> m a
- withPostgresqlConn :: (MonadUnliftIO m, MonadLogger m) => ConnectionString -> (SqlBackend -> m a) -> m a
- withPostgresqlConnWithVersion :: (MonadUnliftIO m, MonadLogger m) => (Connection -> IO (Maybe Double)) -> ConnectionString -> (SqlBackend -> m a) -> m a
- createPostgresqlPool :: (MonadUnliftIO m, MonadLogger m) => ConnectionString -> Int -> m (Pool SqlBackend)
- createPostgresqlPoolModified :: (MonadUnliftIO m, MonadLogger m) => (Connection -> IO ()) -> ConnectionString -> Int -> m (Pool SqlBackend)
- createPostgresqlPoolModifiedWithVersion :: (MonadUnliftIO m, MonadLogger m) => (Connection -> IO (Maybe Double)) -> (Connection -> IO ()) -> ConnectionString -> Int -> m (Pool SqlBackend)
- module Database.Persist.Sql
- type ConnectionString = ByteString
- data PostgresConf = PostgresConf {}
- openSimpleConn :: LogFunc -> Connection -> IO SqlBackend
- openSimpleConnWithVersion :: (Connection -> IO (Maybe Double)) -> LogFunc -> Connection -> IO SqlBackend
- tableName :: PersistEntity record => record -> Text
- fieldName :: PersistEntity record => EntityField record typ -> Text
- mockMigration :: Migration -> IO ()
- migrateEnableExtension :: Text -> Migration
Documentation
Arguments
:: (MonadLogger m, MonadUnliftIO m) | |
=> ConnectionString | Connection string to the database. |
-> Int | Number of connections to be kept open in the pool. |
-> (Pool SqlBackend -> m a) | Action to be executed that uses the connection pool. |
-> m a |
Create a PostgreSQL connection pool and run the given action. The pool is
properly released after the action finishes using it. Note that you should
not use the given ConnectionPool
outside the action since it may already
have been released.
The provided action should use runSqlConn
and *not* runReaderT
because
the former brackets the database action with transaction begin/commit.
withPostgresqlPoolWithVersion Source #
Arguments
:: (MonadUnliftIO m, MonadLogger m) | |
=> (Connection -> IO (Maybe Double)) | Action to perform to get the server version. |
-> ConnectionString | Connection string to the database. |
-> Int | Number of connections to be kept open in the pool. |
-> (Pool SqlBackend -> m a) | Action to be executed that uses the connection pool. |
-> m a |
Same as withPostgresPool
, but takes a callback for obtaining
the server version (to work around an Amazon Redshift bug).
Since: 2.6.2
withPostgresqlConn :: (MonadUnliftIO m, MonadLogger m) => ConnectionString -> (SqlBackend -> m a) -> m a Source #
Same as withPostgresqlPool
, but instead of opening a pool
of connections, only one connection is opened.
The provided action should use runSqlConn
and *not* runReaderT
because
the former brackets the database action with transaction begin/commit.
withPostgresqlConnWithVersion :: (MonadUnliftIO m, MonadLogger m) => (Connection -> IO (Maybe Double)) -> ConnectionString -> (SqlBackend -> m a) -> m a Source #
Same as withPostgresqlConn
, but takes a callback for obtaining
the server version (to work around an Amazon Redshift bug).
Since: 2.6.2
Arguments
:: (MonadUnliftIO m, MonadLogger m) | |
=> ConnectionString | Connection string to the database. |
-> Int | Number of connections to be kept open in the pool. |
-> m (Pool SqlBackend) |
Create a PostgreSQL connection pool. Note that it's your
responsibility to properly close the connection pool when
unneeded. Use withPostgresqlPool
for an automatic resource
control.
createPostgresqlPoolModified Source #
Arguments
:: (MonadUnliftIO m, MonadLogger m) | |
=> (Connection -> IO ()) | Action to perform after connection is created. |
-> ConnectionString | Connection string to the database. |
-> Int | Number of connections to be kept open in the pool. |
-> m (Pool SqlBackend) |
Same as createPostgresqlPool
, but additionally takes a callback function
for some connection-specific tweaking to be performed after connection
creation. This could be used, for example, to change the schema. For more
information, see:
https://groups.google.com/d/msg/yesodweb/qUXrEN_swEo/O0pFwqwQIdcJ
Since: 2.1.3
createPostgresqlPoolModifiedWithVersion Source #
Arguments
:: (MonadUnliftIO m, MonadLogger m) | |
=> (Connection -> IO (Maybe Double)) | Action to perform to get the server version. |
-> (Connection -> IO ()) | Action to perform after connection is created. |
-> ConnectionString | Connection string to the database. |
-> Int | Number of connections to be kept open in the pool. |
-> m (Pool SqlBackend) |
Same as other similarly-named functions in this module, but takes callbacks for obtaining the server version (to work around an Amazon Redshift bug) and connection-specific tweaking (to change the schema).
Since: 2.6.2
module Database.Persist.Sql
type ConnectionString = ByteString Source #
A libpq
connection string. A simple example of connection
string would be "host=localhost port=5432 user=test
dbname=test password=test"
. Please read libpq's
documentation at
https://www.postgresql.org/docs/current/static/libpq-connect.html
for more details on how to create such strings.
data PostgresConf Source #
Information required to connect to a PostgreSQL database
using persistent
's generic facilities. These values are the
same that are given to withPostgresqlPool
.
Constructors
PostgresConf | |
Fields
|
Instances
openSimpleConn :: LogFunc -> Connection -> IO SqlBackend Source #
Generate a SqlBackend
from a Connection
.
openSimpleConnWithVersion :: (Connection -> IO (Maybe Double)) -> LogFunc -> Connection -> IO SqlBackend Source #
Generate a SqlBackend
from a Connection
, but takes a callback for
obtaining the server version.
Since: 2.9.1
tableName :: PersistEntity record => record -> Text Source #
Get the SQL string for the table that a PeristEntity represents. Useful for raw SQL queries.
fieldName :: PersistEntity record => EntityField record typ -> Text Source #
Get the SQL string for the field that an EntityField represents. Useful for raw SQL queries.
mockMigration :: Migration -> IO () Source #
Mock a migration even when the database is not present.
This function performs the same functionality of printMigration
with the difference that an actual database is not needed.
migrateEnableExtension :: Text -> Migration Source #
Enable a Postgres extension. See https://www.postgresql.org/docs/current/static/contrib.html for a list.