Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data PostgresOptions = PostgresOptions {}
- postgresOptions :: (AsEmpty e, AsUnread e, AsUnset e) => Parser e PostgresOptions
- withPostgresqlPool :: (MonadBaseControl IO m, MonadLogger m, MonadIO m) => PostgresOptions -> Int -> (Pool SqlBackend -> m a) -> m a
- withPostgresqlConn :: (MonadBaseControl IO m, MonadLogger m, MonadIO m) => PostgresOptions -> (SqlBackend -> m a) -> m a
- runMigrations :: FilePath -> Q Exp
Connecting to PostgreSQL
The bindings in this section are re-exported from Genesis.Persist.Base.
data PostgresOptions Source #
Connection options needed to connect to PostgreSQL. You can use
postgresOptions
to parse these options from the environment.
postgresOptions :: (AsEmpty e, AsUnread e, AsUnset e) => Parser e PostgresOptions Source #
An envparse
Parser
that parses PostgresOptions
from the environment,
looking for the environment variables PG_HOST
, PG_PORT
, PG_USER
,
PG_USER
, PG_DB_NAME
, and PG_PASSWORD
. All of them are optional except
for PG_DB_NAME
.
:: (MonadBaseControl IO m, MonadLogger m, MonadIO m) | |
=> PostgresOptions | Options to connect 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 |
Like withPostgresqlPool
from Database.Persist.Postgresql, except using
PostgresOptions
.
withPostgresqlConn :: (MonadBaseControl IO m, MonadLogger m, MonadIO m) => PostgresOptions -> (SqlBackend -> m a) -> m a Source #
Like withPostgresqlConn
from Database.Persist.Postgresql, except using
PostgresOptions
.
Compiling and running SQL migrations
The bindings in this section are re-exported from Genesis.Persist.Migrate.
runMigrations :: FilePath -> Q Exp Source #
Compiles a set of .sql files in a particular directory into your application,
then runs them against a database at runtime. This function is implemented
with Template Haskell so that it can read the migration files at compile-time,
but it semantically has the type
(
. Migrations
will be executed in order based on their filename, according to MonadLogger
m, MonadSqlPersist
m) => FilePath
-> m ()sort
.
The FilePath
provided should be relative to your project root, and it will
detect all files within the immediate directory (that is, not in
subdirectories) with the suffix .sql
.
Example:
main :: IO () main =runStderrLoggingT
$ withSqliteConn ":memory:" (runSqlPersistT
$(runMigrations
"db/migrations"))