Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Utilities for writing migrations.
Synopsis
- qqSql :: QuasiQuoter
- qqSqls :: QuasiQuoter
- execute :: (MonadMigration m, ToRow q) => Query -> q -> m Int64
- executeMany :: (MonadMigration m, ToRow q) => Query -> [q] -> m Int64
- execute_ :: MonadMigration m => Query -> m Int64
- executeSeries_ :: MonadMigration m => [Query] -> m ()
- query :: (MonadMigration m, ToRow q, FromRow r) => Query -> q -> m [r]
- query_ :: (MonadMigration m, FromRow r) => Query -> m [r]
- runQuery :: (MonadMigration m, Default Unpackspec columns columns, Default FromFields columns haskells) => Select columns -> m [haskells]
- runInsertMany :: MonadMigration m => Table columns columns' -> [columns] -> m Int64
- runUpdate :: MonadMigration m => Table columnsW columnsR -> (columnsR -> columnsW) -> (columnsR -> Field SqlBool) -> m Int64
- runDelete :: MonadMigration m => Table columnsW columnsR -> (columnsR -> Field SqlBool) -> m Int64
- doesSchemaExist :: MonadMigration m => Text -> m Bool
- doesTableExist :: MonadMigration m => Text -> Text -> m Bool
- doesColumnExist :: MonadMigration m => Text -> Text -> Text -> m Bool
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.