-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple modules for writing apps with Snap, abstracted from hpaste. -- -- Simple modules for writing apps with Snap, abstracted from hpaste. @package snap-app @version 0.1.5 -- | Model-view-controller app types. module Snap.App.Types -- | The controller monad. newtype Controller config state a Controller :: ReaderT (ControllerState config state) Snap a -> Controller config state a runController :: Controller config state a -> ReaderT (ControllerState config state) Snap a -- | The model monad (limited access to IO, only DB access). newtype Model config state a Model :: ReaderT (ModelState config state) IO a -> Model config state a runModel :: Model config state a -> ReaderT (ModelState config state) IO a -- | The state accessible to the controller (DB/session stuff). data ControllerState config state ControllerState :: config -> Connection -> state -> ControllerState config state controllerStateConfig :: ControllerState config state -> config controllerStateConn :: ControllerState config state -> Connection controllerState :: ControllerState config state -> state -- | The state accessible to the model (just DB connection). data ModelState config state ModelState :: Connection -> state -> config -> ModelState config state modelStateConn :: ModelState config state -> Connection modelStateAnns :: ModelState config state -> state modelStateConfig :: ModelState config state -> config class AppConfig config getConfigDomain :: AppConfig config => config -> String class AppLiftModel c s liftModel :: AppLiftModel c s => Model c s a -> Controller c s a -- | Pagination data. data Pagination Pagination :: Integer -> Integer -> URI -> Integer -> Integer -> Pagination pnPage :: Pagination -> Integer pnLimit :: Pagination -> Integer pnURI :: Pagination -> URI pnResults :: Pagination -> Integer pnTotal :: Pagination -> Integer instance Monad (Controller config state) instance Functor (Controller config state) instance Applicative (Controller config state) instance Alternative (Controller config state) instance MonadReader (ControllerState config state) (Controller config state) instance MonadSnap (Controller config state) instance MonadIO (Controller config state) instance MonadPlus (Controller config state) instance MonadCatchIO (Controller config state) instance Monad (Model config state) instance Functor (Model config state) instance Applicative (Model config state) instance MonadReader (ModelState config state) (Model config state) instance MonadIO (Model config state) instance Show Pagination -- | Controller routing/handling. module Snap.App.Controller -- | Run a controller handler. runHandler :: s -> c -> Pool -> Controller c s () -> Snap () -- | Strictly renders HTML to Text before outputting it via Snap. This -- ensures that any lazy exceptions are caught by the Snap handler. output :: Html -> Controller c s () -- | Strictly renders text before outputting it via Snap. This ensures that -- any lazy exceptions are caught by the Snap handler. outputText :: Text -> Controller c s () -- | Generic redirect to home page. goHome :: Controller c s () -- | Extract a Just value or go home. justOrGoHome :: Maybe a -> (a -> Controller c s ()) -> Controller c s () -- | Get integer parmater. getInteger :: ByteString -> Integer -> Controller c s Integer -- | Get string. getString :: ByteString -> String -> Controller c s String -- | Get string (maybe). getStringMaybe :: ByteString -> Controller c s (Maybe String) -- | Get pagination data. getPagination :: AppConfig c => Controller c s Pagination getMyURI :: AppConfig c => Controller c s URI -- | Model running. module Snap.App.Model -- | Run a model action from within a controller. model :: AppLiftModel c s => Model c s a -> Controller c s a -- | Run a model action at the top-level. runDB :: s -> c -> Pool -> Model c s () -> IO () -- | Query with some parameters. query :: (QueryParams ps, QueryResults r) => [String] -> ps -> Model c s [r] -- | Query a single field from a single result. single :: (QueryParams ps, QueryResults (Only r)) => [String] -> ps -> Model c s (Maybe r) -- | Query a single field from a single result (no params). singleNoParams :: QueryResults (Only r) => [String] -> Model c s (Maybe r) -- | Query with no parameters. queryNoParams :: QueryResults r => [String] -> Model c s [r] -- | Process a query for later use. processQuery :: (QueryParams q, QueryResults r) => Query -> q -> Model c s (ProcessedQuery r) -- | A version of query that does not perform query substitution. queryProcessed :: QueryResults r => ProcessedQuery r -> Model c s [r] -- | Execute some SQL returning the rows affected. exec :: QueryParams ps => [String] -> ps -> Model c s Integer -- | A single-value "collection". -- -- This is useful if you need to supply a single parameter to a SQL -- query, or extract a single column from a SQL result. -- -- Parameter example: -- --
-- query c "select x from scores where x > ?" (Only (42::Int)) ---- -- Result example: -- --
-- xs <- query_ c "select id from users"
-- forM_ xs $ \(Only id) -> {- ... -}
--
newtype Only a :: * -> *
Only :: a -> Only a
fromOnly :: Only a -> a
-- | Migration library
module Snap.App.Migrate
-- | Migrate the DB to the latest version.
migrate :: Bool -> [(Int, Model c s Integer)] -> Model c s ()
-- | Set the current database version.
setVersion :: Int -> Model c s ()
-- | Ensure the version table exists.
ensureExists :: Model c s ()
-- | Create the version number.
createVersion :: Model c s ()
-- | Just print to stdout for now.
echo :: String -> Model c s ()
module Snap.App