开发者

Snap web application connect with MySQL

I've been working with Haskell in the last few days. I created a small web app using Haskell and Snap. I added an HTML form to get user data and configured a mysql db with Haskell. I can retrieve data using Haskell. I want to know how I can insert user input into the database.

echo :: Application ()
echo = do      
  firstName <- decodedParam "firstname" 
  heistLocal (bindSplices echoSplices) $ render "echo"
  where   
    decodedParam p = fromMaybe "" <$> getParam p    

The following is how I made the database开发者_如何转开发 connection in my web application. Now I want to connect these two functions, but I cannot use sqlExe within echo, so how can insert data into the db. What point is missing here??

sqlExe :: IO [[SqlValue]]
sqlExe =
  do conn <- connectMySQL defaultMySQLConnectInfo {
                  mysqlHost = "localhost",
                  mysqlDatabase = "test",
                  mysqlUser = "root",
                  mysqlPassword = "password",
                  mysqlUnixSocket = "/var/lib/mysql/mysql.sock" }               
     quickQuery conn "select* from Test" []

I really appreciate if someone can help me to get out of this problem.


Application is an instance of MonadIO, so you can call sqlExe from within echo like this:

result <- liftIO sqlExe

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜