Safe Haskell | None |
---|---|
Language | Haskell98 |
- initPersist :: SqlPersistT (NoLoggingT IO) a -> SnapletInit b PersistState
- initPersistGeneric :: Initializer b PersistState (Pool Connection) -> 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 :: 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 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 Connection) -> 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) | |
MonadIO m => HasPersistPool (ReaderT ConnectionPool m) | |
HasPersistPool (Handler b PersistState) |
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
mkKeyBS :: ByteString -> Key entity Source
Makes a Key from a ByteString. Calls error on failure.
showKeyBS :: Key e -> ByteString Source
Makes a ByteString representation of a Key.
mkWord64 :: 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