snaplet-persistent-0.3: persistent snaplet for the Snap Framework

Safe HaskellNone





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.


 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.

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).

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

mkKey :: Int -> Key entitySource

Make a Key from an Int.

mkKeyBS :: ByteString -> Key entitySource

Makes a Key from a ByteString. Calls error on failure.

mkKeyT :: Text -> Key entitySource

Makes a Key from Text. Calls error on failure.

showKey :: Key e -> TextSource

Makes a Text representation of a Key.

showKeyBS :: Key e -> ByteStringSource

Makes a ByteString representation of a Key.

mkInt :: Key a -> IntSource

Converts a Key to Int. Fails with error if the conversion fails.

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.