我正试图从SQLite DB(HDBC.sqlite3
)中获取信息,以便使用Scotty框架将其提供给web视图。我目前正在尝试完成一个"抓取所有",或者更确切地说,从表中选择所有信息,然后将其返回到通过Scotty运行的网页上显示。我遇到了一个错误,我很难弄清楚如何修复它。
这是我的错误:
Controllers/Home.hs:42:44:
Couldn't match expected type `Data.Text.Lazy.Internal.Text'
with actual type `IO [[(String, SqlValue)]]'
In the expression: getUsersDB
In the first argument of `mconcat', namely
`["<p>/users/all</p><p>", getUsersDB, "</p>"]'
In the second argument of `($)', namely
`mconcat ["<p>/users/all</p><p>", getUsersDB, "</p>"]'
这是我的代码:
import Control.Monad
import Web.Scotty (ScottyM, ActionM, get, html, param, text)
import Data.Monoid (mconcat)
import Controllers.CreateDb (createUserDB)
import Database.HDBC
import Database.HDBC.Sqlite3
import Control.Monad.Trans ( MonadIO(liftIO) )
import Data.Convertible
getAllUsers :: ScottyM()
getAllUsers = get "/users/all" $ do
html $ mconcat ["<p>/users/all</p><p>", getUsersDB , "</p>"]
getUsersDB = do
conn <- connectSqlite3 databaseFilePath
stmt <- prepare conn "SELECT name FROM users VALUES"
results <- fetchAllRowsAL stmt
disconnect conn
return (results)
run
返回修改的行数:https://hackage.haskell.org/package/HDBC-2.4.0.0/docs/Database-HDBC.html#v:run