groundhog-0.3.1.1: Type-safe datatype-database mapping library.

Safe HaskellNone

Database.Groundhog.Generic

Contents

Description

This helper module is intended for use by the backend creators

Synopsis

Migration

createMigration :: PersistBackend m => Migration m -> m NamedMigrationsSource

Produce the migrations but not execute them. Fails when an unsafe migration occurs.

executeMigration :: (PersistBackend m, MonadIO m) => (String -> IO ()) -> NamedMigrations -> m ()Source

Execute the migrations and log them.

executeMigrationUnsafe :: (PersistBackend m, MonadIO m) => (String -> IO ()) -> NamedMigrations -> m ()Source

Execute migrations and log them. Executes the unsafe migrations without warnings

runMigration :: (PersistBackend m, MonadIO m) => (String -> IO ()) -> Migration m -> m ()Source

Run migrations and log them. Fails when an unsafe migration occurs.

runMigrationUnsafe :: (PersistBackend m, MonadIO m) => (String -> IO ()) -> Migration m -> m ()Source

Run migrations and log them. Executes the unsafe migrations without warnings

printMigration :: MonadIO m => NamedMigrations -> m ()Source

Pretty print the migrations

mergeMigrations :: [SingleMigration] -> SingleMigrationSource

Joins the migrations. The result is either all error messages or all queries

defaultMigrationLogger :: String -> IO ()Source

Prints the queries to stdout

Helpers for running Groundhog within custom monads

class (MonadIO m, MonadBaseControl IO m, MonadReader cm m, ConnectionManager cm conn) => HasConn m cm conn Source

This class helps to shorten the type signatures of user monadic code.

Instances

(MonadIO m, MonadBaseControl IO m, MonadReader cm m, ConnectionManager cm conn) => HasConn m cm conn 

runDb :: HasConn m cm conn => DbPersist conn IO a -> m aSource

It helps to run database operations within your application monad.

withSavepoint :: (HasConn m cm conn, SingleConnectionManager cm conn, Savepoint conn) => String -> m a -> m aSource

It helps to run withConnSavepoint within a monad.

Helper functions for defining *PersistValue instances

Other

bracketSource

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first (acquire resource)

-> (a -> m b)

computation to run last (release resource)

-> (a -> m c)

computation to run in-between

-> m c 

finallySource

Arguments

:: MonadBaseControl IO m 
=> m a

computation to run first

-> m b

computation to run afterward (even if an exception was raised)

-> m a 

onException :: MonadBaseControl IO m => m a -> m b -> m aSource

findOne :: (Eq c, Show c) => String -> (a -> c) -> (b -> c) -> a -> [b] -> bSource

replaceOne :: (Eq c, Show c) => String -> (a -> c) -> (b -> c) -> (a -> b -> b) -> a -> [b] -> [b]Source

matchElements :: Show a => (a -> b -> Bool) -> [a] -> [b] -> ([a], [b], [(a, b)])Source

Returns only old elements, only new elements, and matched pairs (old, new). The new ones exist only in datatype, the old are present only in DB, match is typically by name (the properties of the matched elements may differ).

haveSameElems :: Show a => (a -> b -> Bool) -> [a] -> [b] -> BoolSource

mapAllRows :: Monad m => ([PersistValue] -> m a) -> RowPopper m -> m [a]Source