groundhog-0.4.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

getQueriesSource

Arguments

:: Bool

True - support unsafe queries

-> SingleMigration 
-> Either [String] [String] 

Returns either a list of errors in migration or a list of queries

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 actions

class (MonadIO m, MonadLogger 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

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

It helps to run database operations within your application monad.

runDbConn :: (MonadBaseControl IO m, MonadIO m, ConnectionManager cm conn) => DbPersist conn (NoLoggingT m) a -> cm -> m aSource

Runs action within connection. It can handle a simple connection, a pool of them, etc.

runDbConnNoTransaction :: (MonadBaseControl IO m, MonadIO m, ConnectionManager cm conn) => DbPersist conn (NoLoggingT m) a -> cm -> m aSource

It is similar to runDbConn but runs action without transaction. It can be useful if you use Groundhog within IO monad or in other cases when you cannot put PersistBackend instance into your monad stack.

 flip withConn cm $ \conn -> liftIO $ do
   -- transaction is already opened by withConn at this point
   someIOAction
   getValuesFromIO $ \value -> runDbConnNoTransaction (insert_ value) conn

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

deleteByKey :: (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m ()Source

Deprecated: Use deleteBy instead