groundhog-0.8.0.1: 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 #

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

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

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

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

Execute the migrations. Fails when an unsafe migration occurs.

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

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

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

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 () #

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 () #

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

getQueries #

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 () #

Pretty print the migrations

mergeMigrations :: [SingleMigration] -> SingleMigration #

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

Helper functions for defining *PersistValue instances

toPersistValuesUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u))) => u (UniqueMarker v) -> v -> m ([PersistValue] -> [PersistValue]) #

Other

bracket #

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 #

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 #

data PSFieldDef str #

Constructors

PSFieldDef 

Fields

Instances

Eq str => Eq (PSFieldDef str) # 

Methods

(==) :: PSFieldDef str -> PSFieldDef str -> Bool #

(/=) :: PSFieldDef str -> PSFieldDef str -> Bool #

Show str => Show (PSFieldDef str) # 

Methods

showsPrec :: Int -> PSFieldDef str -> ShowS #

show :: PSFieldDef str -> String #

showList :: [PSFieldDef str] -> ShowS #

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

replaceOne :: (Eq x, Show x) => String -> (a -> x) -> (b -> x) -> (a -> b -> b) -> a -> [b] -> [b] #

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

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 #

phantomDb :: PersistBackend m => m (proxy (Conn m)) #

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

firstRow :: MonadIO m => RowStream a -> m (Maybe a) #

streamToList :: MonadIO m => RowStream a -> m [a] #

mapStream :: PersistBackendConn conn => (a -> Action conn b) -> RowStream a -> Action conn (RowStream b) #

joinStreams :: [Action conn (RowStream a)] -> Action conn (RowStream a) #

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

Deprecated: Use deleteBy instead