Safe Haskell | None |
---|---|
Language | Haskell98 |
This helper module is intended for use by the backend creators
Synopsis
- 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
- primToPersistValue :: (PersistBackend m, PrimitivePersistField a) => a -> m ([PersistValue] -> [PersistValue])
- primFromPersistValue :: (PersistBackend m, PrimitivePersistField a) => [PersistValue] -> m (a, [PersistValue])
- primToPurePersistValues :: PrimitivePersistField a => a -> [PersistValue] -> [PersistValue]
- primFromPurePersistValues :: PrimitivePersistField a => [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)
- psFieldConverter :: Maybe str
- 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
- phantomDb :: PersistBackend m => m (proxy (Conn m))
- getDefaultAutoKeyType :: DbDescriptor db => proxy db -> DbTypePrimitive
- getUniqueFields :: UniqueDef' str (Either field str) -> [field]
- isSimple :: [ConstructorDef] -> Bool
- 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)
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
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 :: PrimitivePersistField a => a -> [PersistValue] -> [PersistValue] Source #
primFromPurePersistValues :: PrimitivePersistField a => [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 | |
|
Instances
Eq str => Eq (PSFieldDef str) Source # | |
Defined in Database.Groundhog.Generic (==) :: PSFieldDef str -> PSFieldDef str -> Bool # (/=) :: PSFieldDef str -> PSFieldDef str -> Bool # | |
Show str => Show (PSFieldDef str) Source # | |
Defined in Database.Groundhog.Generic showsPrec :: Int -> PSFieldDef str -> ShowS # show :: PSFieldDef str -> String # showList :: [PSFieldDef str] -> ShowS # |
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).
phantomDb :: PersistBackend m => m (proxy (Conn m)) Source #
getDefaultAutoKeyType :: DbDescriptor db => proxy db -> DbTypePrimitive Source #
getUniqueFields :: UniqueDef' str (Either field str) -> [field] Source #
isSimple :: [ConstructorDef] -> Bool Source #
streamToList :: MonadIO m => RowStream a -> m [a] Source #