[英]Retrieving values from SQLite3 Database for Scotty
I'm trying to get information from a SQLite DB ( HDBC.sqlite3
) to feed to a web view using the Scotty framework. 我正在尝试从SQLite数据库( HDBC.sqlite3
)获取信息,以使用Scotty框架将其提供给Web视图。 I'm currently trying to complete a "grab all" or rather select all the information from the table and then return it to display on my web page that is running via Scotty. 我当前正在尝试完成“全部获取”,或者更确切地说是从表中选择所有信息,然后将其返回以显示在通过Scotty运行的我的网页上。 I've encountered an error and I'm having some trouble figuring out how to fix it. 我遇到了一个错误,并且在寻找解决方法时遇到了一些麻烦。
Here is my error: 这是我的错误:
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>"]'
Here is my code: 这是我的代码:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.