refurb-0.3.0.2: Tools for maintaining a database
Safe HaskellNone
LanguageHaskell2010

Refurb.MigrationUtils

Description

Utilities for writing migrations.

Synopsis

Documentation

qqSql :: QuasiQuoter Source #

Simple quasiquoter which just makes it easier to embed literal chunks of SQL in migrations.

For example:

  createStuffIndex :: MonadMigration m => m ()
  createStuffIndex =
    execute_
      [qqSql|
        create index stuff_index
          on stuff (things)
          where is_what_we_want_to_index = t
      |]

qqSqls :: QuasiQuoter Source #

Quasiquoter which takes a block of literal SQL and converts it into a list of Query values, e.g. to pass to executeSeries_. A semicolon at the beginning or end of a line (sans whitespace) separates SQL statements.

For example:

  createStuff :: MonadMigration m => m ()
  createStuff =
    executeSeries_ [qqSqls|
      create sequence stuff_seq;
      create table stuff
        ( id bigint not null primary key default nextval(stuff_seq)
        );
      |]

execute :: (MonadMigration m, ToRow q) => Query -> q -> m Int64 Source #

Execute some parameterized SQL against the database connection. Wraps execute using the MonadMigration reader to get the connection.

executeMany :: (MonadMigration m, ToRow q) => Query -> [q] -> m Int64 Source #

Execute some parameterized SQL against the database connection. Wraps executeMany using the MonadMigration reader to get the connection.

execute_ :: MonadMigration m => Query -> m Int64 Source #

Execute some fixed SQL against the database connection. Wraps execute_ using the MonadMigration reader to get the connection.

executeSeries_ :: MonadMigration m => [Query] -> m () Source #

Execute a series of fixed SQL statements against the database connection. Equivalent to `traverse_ (void . execute_)`

query :: (MonadMigration m, ToRow q, FromRow r) => Query -> q -> m [r] Source #

Run a parameterized query against the database connection. Wraps query using the MonadMigration reader to get the connection.

query_ :: (MonadMigration m, FromRow r) => Query -> m [r] Source #

Run a fixed query against the database connection. Wraps query_ using the MonadMigration reader to get the connection.

runQuery :: (MonadMigration m, Default Unpackspec columns columns, Default FromFields columns haskells) => Select columns -> m [haskells] Source #

Run an Opaleye query against the database connection. Wraps runSelect using the MonadMigration reader to get the connection.

runInsertMany :: MonadMigration m => Table columns columns' -> [columns] -> m Int64 Source #

Run an Opaleye runInsert against the database connection.

runUpdate :: MonadMigration m => Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Field SqlBool) -> m Int64 Source #

Run an Opaleye runUpdate against the database connection.

runDelete :: MonadMigration m => Table columnsW columnsR -> (columnsR -> Field SqlBool) -> m Int64 Source #

Run an Opaleye runDelete against the database connection.

doesSchemaExist :: MonadMigration m => Text -> m Bool Source #

Check if a schema exists using the information_schema views.

doesTableExist :: MonadMigration m => Text -> Text -> m Bool Source #

Check if a table exists in a schema using the information_schema views.

doesColumnExist :: MonadMigration m => Text -> Text -> Text -> m Bool Source #

Check if a column exists in a schema on a table using the information_schema views.