-- =============================================================================
-- Actions
-- =============================================================================

getPost :: (MonadReader Config m, MonadIO m) => String -> m (Maybe PostField)
getPost slug = do
  config <- ask
  let conn = _configConnection config
  results <- liftIO $ query conn slug
  return $ listToMaybe results
  where
    query :: Simple.Connection -> String -> IO [PostField]
    query c slug =
      Simple.query c "SELECT * FROM POST WHERE slug = ?" (Simple.Only slug)
getPost :: (MonadReader Config m, MonadIO m) => String -> m (Maybe PostField)
getPost slug = do
  config <- ask
  let conn = _configConnection config
  results <- liftIO $ query conn slug
  return $ listToMaybe results
  where
    query :: Simple.Connection -> String -> IO [PostField]
    query c slug =
      Simple.query c "SELECT * FROM POST WHERE slug = ?" (Simple.Only slug)
getPost slug = do
  config <- ask
  let conn = _configConnection config
  results <- liftIO $ query conn slug
  return $ listToMaybe results
  where
    query :: Simple.Connection -> String -> IO [PostField]
    query c slug =
      Simple.query c "SELECT * FROM POST WHERE slug = ?" (Simple.Only slug)