Safe Haskell | None |
---|
- initPersist :: 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 -> SqlPersist (ResourceT (NoLoggingT IO)) a -> m a
- mkKey :: Int -> Key entity
- mkKeyBS :: ByteString -> Key entity
- mkKeyT :: Text -> Key entity
- showKey :: Key e -> Text
- showKeyBS :: Key e -> ByteString
- mkInt :: Key a -> Int
- mkWord64 :: 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 PersistStateSource
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
.
newtype PersistState Source
class MonadIO m => HasPersistPool m whereSource
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) | |
MonadIO m => HasPersistPool (ReaderT ConnectionPool m) | |
HasPersistPool (Handler b PersistState) |
mkPgPool :: MonadIO m => Config -> m ConnectionPoolSource
Constructs a connection pool from Config.
mkSnapletPgPool :: (MonadIO (m b v), MonadSnaplet m) => m b v ConnectionPoolSource
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 -> SqlPersist (ResourceT (NoLoggingT IO)) a -> m aSource
Run a database action
Utility Functions
mkKeyBS :: ByteString -> Key entitySource
Makes a Key from a ByteString. Calls error on failure.
showKeyBS :: Key e -> ByteStringSource
Makes a ByteString representation of a Key.
mkWord64 :: Key a -> Word64Source
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 -> cSource