Safe Haskell | None |
---|---|
Language | Haskell98 |
- initPersist :: SqlPersistT (NoLoggingT IO) a -> SnapletInit b PersistState
- initPersistGeneric :: Initializer b PersistState (Pool SqlBackend) -> SqlPersistT (NoLoggingT IO) a -> SnapletInit b PersistState
- newtype PersistState = PersistState {}
- class MonadIO m => HasPersistPool m where
- mkPgPool :: MonadIO m => Config -> m ConnectionPool
- mkSnapletPgPool :: (MonadIO (m b v), MonadSnaplet m) => m b v ConnectionPool
- runPersist :: HasPersistPool m => SqlPersistT (ResourceT (NoLoggingT IO)) b -> m b
- withPool :: MonadIO m => ConnectionPool -> SqlPersistT (ResourceT (NoLoggingT IO)) a -> m a
- mkKey :: ToBackendKey SqlBackend entity => Int -> Key entity
- mkKeyBS :: ToBackendKey SqlBackend entity => ByteString -> Key entity
- mkKeyT :: ToBackendKey SqlBackend entity => Text -> Key entity
- showKey :: ToBackendKey SqlBackend e => Key e -> Text
- showKeyBS :: ToBackendKey SqlBackend e => Key e -> ByteString
- mkInt :: ToBackendKey SqlBackend a => Key a -> Int
- mkWord64 :: ToBackendKey SqlBackend a => Key a -> Word64
- followForeignKey :: (PersistEntity a, HasPersistPool m, PersistEntityBackend a ~ SqlBackend) => (t -> Key a) -> Entity t -> m (Maybe (Entity a))
- fromPersistValue' :: PersistField c => PersistValue -> c
Documentation
initPersist :: SqlPersistT (NoLoggingT IO) a -> SnapletInit b PersistState Source #
Initialize Persistent with an initial SQL function called right after the connection pool has been created. This is most useful for calling migrations upfront right after initialization.
Example:
initPersist (runMigrationUnsafe migrateAll)
where migrateAll is the migration function that was auto-generated
by the QQ statement in your persistent schema definition in the
call to mkMigrate
.
initPersistGeneric :: Initializer b PersistState (Pool SqlBackend) -> SqlPersistT (NoLoggingT IO) a -> SnapletInit b PersistState Source #
Backend-agnostic initalization with an initial SQL function called right after the connection pool has been created. This is most useful for calling migrations upfront right after initialization.
Example:
initPersist mkPool (runMigrationUnsafe migrateAll)
where migrateAll is the migration function that was auto-generated
by the QQ statement in your persistent schema definition in the
call to mkMigrate
.
mkPool is a function to construct a pool of connections to your database
newtype PersistState Source #
class MonadIO m => HasPersistPool m where Source #
Implement this type class to have any monad work with snaplet-persistent. A default instance is provided for (Handler b PersistState).
HasPersistPool m => HasPersistPool (NoLoggingT m) Source # | |
HasPersistPool (Handler b PersistState) Source # | |
MonadIO m => HasPersistPool (ReaderT * ConnectionPool m) Source # | |
mkPgPool :: MonadIO m => Config -> m ConnectionPool Source #
Constructs a connection pool from Config.
mkSnapletPgPool :: (MonadIO (m b v), MonadSnaplet m) => m b v ConnectionPool Source #
Conscruts a connection pool in a snaplet context.
:: HasPersistPool m | |
=> SqlPersistT (ResourceT (NoLoggingT IO)) b | Run given Persistent action in the defined monad. |
-> m b |
Runs a SqlPersist action in any monad with a HasPersistPool instance.
withPool :: MonadIO m => ConnectionPool -> SqlPersistT (ResourceT (NoLoggingT IO)) a -> m a Source #
Run a database action
Utility Functions
mkKey :: ToBackendKey SqlBackend entity => Int -> Key entity Source #
Make a Key from an Int.
mkKeyBS :: ToBackendKey SqlBackend entity => ByteString -> Key entity Source #
Makes a Key from a ByteString. Calls error on failure.
mkKeyT :: ToBackendKey SqlBackend entity => Text -> Key entity Source #
Makes a Key from Text. Calls error on failure.
showKey :: ToBackendKey SqlBackend e => Key e -> Text Source #
Makes a Text representation of a Key.
showKeyBS :: ToBackendKey SqlBackend e => Key e -> ByteString Source #
Makes a ByteString representation of a Key.
mkInt :: ToBackendKey SqlBackend a => Key a -> Int Source #
Converts a Key to Int. Fails with error if the conversion fails.
mkWord64 :: ToBackendKey SqlBackend a => Key a -> Word64 Source #
Converts a Key to Word64. Fails with error if the conversion fails.
followForeignKey :: (PersistEntity a, HasPersistPool m, PersistEntityBackend a ~ SqlBackend) => (t -> Key a) -> Entity t -> m (Maybe (Entity a)) Source #
Follows a foreign key field in one entity and retrieves the corresponding entity from the database.
fromPersistValue' :: PersistField c => PersistValue -> c Source #