genesis- Opinionated bootstrapping for Haskell web services.

Safe HaskellNone




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.

withPostgresqlPool Source #


:: (MonadBaseControl IO m, MonadLogger 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 

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 (MonadLogger m, MonadSqlPersist m) => FilePath -> m (). Migrations will be executed in order based on their filename, according to 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.


 main :: IO ()
 main = runStderrLoggingT $ withSqliteConn ":memory:" (runSqlPersistT $(runMigrations "db/migrations"))