Safe Haskell | None |
---|---|
Language | Haskell98 |
This helper module is intended for use by the backend creators
- createMigration :: Monad m => Migration m -> m NamedMigrations
- executeMigration :: (PersistBackend m, MonadIO m) => NamedMigrations -> m ()
- executeMigrationSilent :: (PersistBackend m, MonadIO m) => NamedMigrations -> m ()
- executeMigrationUnsafe :: (PersistBackend m, MonadIO m) => NamedMigrations -> m ()
- runMigration :: (PersistBackend m, MonadIO m) => Migration m -> m ()
- runMigrationSilent :: (PersistBackend m, MonadIO m) => Migration m -> m ()
- runMigrationUnsafe :: (PersistBackend m, MonadIO m) => Migration m -> m ()
- getQueries :: Bool -> SingleMigration -> Either [String] [String]
- printMigration :: MonadIO m => NamedMigrations -> m ()
- mergeMigrations :: [SingleMigration] -> SingleMigration
- class (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadReader cm m, ConnectionManager cm conn) => HasConn m cm conn
- runDb :: HasConn m cm conn => DbPersist conn m a -> m a
- runDbConn :: (MonadBaseControl IO m, MonadIO m, ConnectionManager cm conn) => DbPersist conn (NoLoggingT m) a -> cm -> m a
- runDbConnNoTransaction :: (MonadBaseControl IO m, MonadIO m, ConnectionManager cm conn) => DbPersist conn (NoLoggingT m) a -> cm -> m a
- withSavepoint :: (HasConn m cm conn, SingleConnectionManager cm conn, Savepoint conn) => String -> m a -> m a
- primToPersistValue :: (PersistBackend m, PrimitivePersistField a) => a -> m ([PersistValue] -> [PersistValue])
- primFromPersistValue :: (PersistBackend m, PrimitivePersistField a) => [PersistValue] -> m (a, [PersistValue])
- primToPurePersistValues :: (DbDescriptor db, PrimitivePersistField a) => proxy db -> a -> [PersistValue] -> [PersistValue]
- primFromPurePersistValues :: (DbDescriptor db, PrimitivePersistField a) => proxy db -> [PersistValue] -> (a, [PersistValue])
- primToSinglePersistValue :: (PersistBackend m, PrimitivePersistField a) => a -> m PersistValue
- primFromSinglePersistValue :: (PersistBackend m, PrimitivePersistField a) => PersistValue -> m a
- pureToPersistValue :: (PersistBackend m, PurePersistField a) => a -> m ([PersistValue] -> [PersistValue])
- pureFromPersistValue :: (PersistBackend m, PurePersistField a) => [PersistValue] -> m (a, [PersistValue])
- singleToPersistValue :: (PersistBackend m, SinglePersistField a) => a -> m ([PersistValue] -> [PersistValue])
- singleFromPersistValue :: (PersistBackend m, SinglePersistField a) => [PersistValue] -> m (a, [PersistValue])
- toSinglePersistValueUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u)), PrimitivePersistField (Key v (Unique u))) => u (UniqueMarker v) -> v -> m PersistValue
- fromSinglePersistValueUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u)), PrimitivePersistField (Key v (Unique u))) => u (UniqueMarker v) -> PersistValue -> m v
- toPersistValuesUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u))) => u (UniqueMarker v) -> v -> m ([PersistValue] -> [PersistValue])
- fromPersistValuesUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u))) => u (UniqueMarker v) -> [PersistValue] -> m (v, [PersistValue])
- toSinglePersistValueAutoKey :: forall m v. (PersistBackend m, PersistEntity v, PrimitivePersistField (AutoKey v)) => v -> m PersistValue
- fromSinglePersistValueAutoKey :: forall m v. (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => PersistValue -> m v
- failMessage :: PersistField a => a -> [PersistValue] -> String
- failMessageNamed :: String -> [PersistValue] -> String
- bracket :: MonadBaseControl IO m => m a -> (a -> m b) -> (a -> m c) -> m c
- finally :: MonadBaseControl IO m => m a -> m b -> m a
- onException :: MonadBaseControl IO m => m a -> m b -> m a
- data PSFieldDef str = PSFieldDef {
- psFieldName :: str
- psDbFieldName :: Maybe str
- psDbTypeName :: Maybe str
- psExprName :: Maybe str
- psEmbeddedDef :: Maybe [PSFieldDef str]
- psDefaultValue :: Maybe str
- psReferenceParent :: Maybe (Maybe ((Maybe str, str), [str]), Maybe ReferenceActionType, Maybe ReferenceActionType)
- applyDbTypeSettings :: PSFieldDef String -> DbType -> DbType
- 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)])
- haveSameElems :: Show a => (a -> b -> Bool) -> [a] -> [b] -> Bool
- mapAllRows :: Monad m => ([PersistValue] -> m a) -> RowPopper m -> m [a]
- phantomDb :: PersistBackend m => m (proxy (PhantomDb m))
- getAutoKeyType :: DbDescriptor db => proxy db -> DbTypePrimitive
- getUniqueFields :: UniqueDef' str (Either field str) -> [field]
- isSimple :: [ConstructorDef] -> Bool
- deleteByKey :: (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m ()
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
:: 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.
(MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadReader cm m, ConnectionManager cm conn) => HasConn m cm conn |
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
primToPersistValue :: (PersistBackend m, PrimitivePersistField a) => a -> m ([PersistValue] -> [PersistValue]) Source
primFromPersistValue :: (PersistBackend m, PrimitivePersistField a) => [PersistValue] -> m (a, [PersistValue]) Source
primToPurePersistValues :: (DbDescriptor db, PrimitivePersistField a) => proxy db -> a -> [PersistValue] -> [PersistValue] Source
primFromPurePersistValues :: (DbDescriptor db, PrimitivePersistField a) => proxy db -> [PersistValue] -> (a, [PersistValue]) Source
primToSinglePersistValue :: (PersistBackend m, PrimitivePersistField a) => a -> m PersistValue Source
primFromSinglePersistValue :: (PersistBackend m, PrimitivePersistField a) => PersistValue -> m a Source
pureToPersistValue :: (PersistBackend m, PurePersistField a) => a -> m ([PersistValue] -> [PersistValue]) Source
pureFromPersistValue :: (PersistBackend m, PurePersistField a) => [PersistValue] -> m (a, [PersistValue]) Source
singleToPersistValue :: (PersistBackend m, SinglePersistField a) => a -> m ([PersistValue] -> [PersistValue]) Source
singleFromPersistValue :: (PersistBackend m, SinglePersistField a) => [PersistValue] -> m (a, [PersistValue]) Source
toSinglePersistValueUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u)), PrimitivePersistField (Key v (Unique u))) => u (UniqueMarker v) -> v -> m PersistValue Source
fromSinglePersistValueUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u)), PrimitivePersistField (Key v (Unique u))) => u (UniqueMarker v) -> PersistValue -> m v Source
toPersistValuesUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u))) => u (UniqueMarker v) -> v -> m ([PersistValue] -> [PersistValue]) Source
fromPersistValuesUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u))) => u (UniqueMarker v) -> [PersistValue] -> m (v, [PersistValue]) Source
toSinglePersistValueAutoKey :: forall m v. (PersistBackend m, PersistEntity v, PrimitivePersistField (AutoKey v)) => v -> m PersistValue Source
fromSinglePersistValueAutoKey :: forall m v. (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => PersistValue -> m v Source
failMessage :: PersistField a => a -> [PersistValue] -> String Source
failMessageNamed :: String -> [PersistValue] -> String Source
Other
:: 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 |
:: 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
PSFieldDef | |
|
Eq str => Eq (PSFieldDef str) | |
Show str => Show (PSFieldDef str) |
applyDbTypeSettings :: PSFieldDef String -> DbType -> DbType 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
phantomDb :: PersistBackend m => m (proxy (PhantomDb m)) Source
getAutoKeyType :: DbDescriptor db => proxy db -> DbTypePrimitive Source
getUniqueFields :: UniqueDef' str (Either field str) -> [field] Source
isSimple :: [ConstructorDef] -> Bool Source
deleteByKey :: (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => Key v BackendSpecific -> m () Source
Deprecated: Use deleteBy instead