【发布时间】:2018-01-27 10:23:39
【问题描述】:
您好,我是 Haskell 的新手,我一直在使用 Scotty 和 Sqlite 开发一个小型 Web 应用程序。
我在 Scotty Actions 中执行 Sqlite 操作时遇到问题。 单独使用这两个库时,我有点理解。
这是我的代码的 MVP
-- imports ...
routes :: ScottyM ()
routes = do
post "data/:id" $ do
id <- param "id"
-- HERE IS WHERE I GET CONFUSED
-- This is what I want to do
db <- open "store.db"
exec db "INSERT INTO Store (id, value) VALUES (" <> id <> ", 'Test Value');" -- I know there is SQL Injection here I will learn about parameterized queries in haskell next
close db
-- END THE PART I AM CONFUSED BY
text $ "created a record with " <> id <> " id."
main :: IO()
scotty 3000 routes
所以如你所见,我仍然坚持思考过于迫切。 我知道帖子的类型是 ActionM () -> ScottyM () 我知道close db的类型是IO()
所以我认为我需要的是一个复合函数 ActionM () -> IO () -> ScottyM () 我只是不知道该怎么写。
这是在正确的轨道上吗?
非常感谢任何和所有建议。
【问题讨论】:
标签: sqlite haskell functional-programming monads scotty