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

Safe HaskellNone
LanguageHaskell98

Database.Groundhog.Generic

Contents

Description

This helper module is intended for use by the backend creators

Synopsis

Migration

createMigration :: Monad m => Migration m -> m NamedMigrations Source

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

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

Execute the migrations with printing to stderr. Fails when an unsafe migration occurs.

executeMigrationSilent :: (PersistBackend m, MonadIO m) => NamedMigrations -> m () Source

Execute the migrations. Fails when an unsafe migration occurs.

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

Execute migrations. Executes the unsafe migrations without warnings and prints them to stderr

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

Creates migrations and executes them with printing to stderr. Fails when an unsafe migration occurs. > runMigration m = createMigration m >>= executeMigration

runMigrationSilent :: (PersistBackend m, MonadIO m) => Migration m -> m () Source

Creates migrations and silently executes them. Fails when an unsafe migration occurs. > runMigration m = createMigration m >>= executeMigrationSilent

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

Creates migrations and executes them with printing to stderr. Executes the unsafe migrations without warnings > runMigrationUnsafe m = createMigration m >>= executeMigrationUnsafe

getQueries Source

Arguments

:: Bool

True - support unsafe queries

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

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

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

Pretty print the migrations

mergeMigrations :: [SingleMigration] -> SingleMigration Source

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

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 a Source

It helps to run database operations within an application monad.

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

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 a Source

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 a Source

It helps to run withConnSavepoint within a monad.

Helper functions for defining *PersistValue instances

Other

bracket Source

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 

finally Source

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 a Source

data PSFieldDef str Source

Instances

Eq str => Eq (PSFieldDef str) 
Show str => Show (PSFieldDef str) 

findOne :: (Eq x, Show x) => String -> (a -> x) -> x -> [a] -> a Source

replaceOne :: (Eq x, Show x) => String -> (a -> x) -> (b -> x) -> (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] -> Bool Source

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

getUniqueFields :: UniqueDef' str (Either field str) -> [field] Source

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

Deprecated: Use deleteBy instead