Safe Haskell | None |
---|
This helper module is intended for use by the backend creators
- createMigration :: PersistBackend m => Migration m -> m NamedMigrations
- executeMigration :: (PersistBackend m, MonadIO m) => (String -> IO ()) -> NamedMigrations -> m ()
- executeMigrationUnsafe :: (PersistBackend m, MonadIO m) => (String -> IO ()) -> NamedMigrations -> m ()
- getQueries :: Bool -> SingleMigration -> Either [String] [String]
- runMigration :: (PersistBackend m, MonadIO m) => (String -> IO ()) -> Migration m -> m ()
- runMigrationUnsafe :: (PersistBackend m, MonadIO m) => (String -> IO ()) -> Migration m -> m ()
- printMigration :: MonadIO m => NamedMigrations -> m ()
- mergeMigrations :: [SingleMigration] -> SingleMigration
- silentMigrationLogger :: String -> IO ()
- defaultMigrationLogger :: String -> IO ()
- failMessage :: PersistField a => a -> [PersistValue] -> String
- 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
- 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
- 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 = PSFieldDef {}
- applyDbTypeSettings :: PSFieldDef -> DbType -> DbType
- findOne :: (Eq c, Show c) => String -> (a -> c) -> (b -> c) -> a -> [b] -> b
- replaceOne :: (Eq c, Show c) => String -> (a -> c) -> (b -> c) -> (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))
- isSimple :: [ConstructorDef] -> Bool
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
:: 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
silentMigrationLogger :: String -> IO ()Source
No-op
defaultMigrationLogger :: String -> IO ()Source
Prints the queries to stdout
failMessage :: PersistField a => a -> [PersistValue] -> StringSource
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 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.
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
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 PersistValueSource
primFromSinglePersistValue :: (PersistBackend m, PrimitivePersistField a) => PersistValue -> m aSource
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 PersistValueSource
fromSinglePersistValueUnique :: forall m v u. (PersistBackend m, PersistEntity v, IsUniqueKey (Key v (Unique u)), PrimitivePersistField (Key v (Unique u))) => u (UniqueMarker v) -> PersistValue -> m vSource
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 PersistValueSource
fromSinglePersistValueAutoKey :: forall m v. (PersistBackend m, PersistEntity v, PrimitivePersistField (Key v BackendSpecific)) => PersistValue -> m vSource
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 aSource
data PSFieldDef Source
applyDbTypeSettings :: PSFieldDef -> DbType -> DbTypeSource
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
phantomDb :: PersistBackend m => m (Proxy (PhantomDb m))Source
isSimple :: [ConstructorDef] -> BoolSource