请,..如何从一张桌子获得数量(*)?我试图连接一些代码片段,但到目前为止还没有成功。
这就是我所拥有的:
fetchSimple :: FromRow r => Pool Connection -> Query -> IO [r]
fetchSimple pool sql = withResource pool retrieve
where retrieve conn = query_ conn sql
getUsersCount :: Pool Connection -> IO (Int)
getUsersCount pool = do
res <- fetchSimple pool "SELECT count(*) FROM article" :: IO [Int]
let f = head res
return f
这给了我以下错误:
No instance for (FromRow Int) arising from a use of ‘fetchSimple’
In a stmt of a 'do' block:
res <- fetchSimple pool "SELECT count(*) FROM article" :: IO [Int]
In the expression:
do { res <- fetchSimple pool "SELECT count(*) FROM article" ::
IO [Int];
let f = head res;
return f }
In an equation for ‘getUsersCount’:
getUsersCount pool
= do { res <- fetchSimple pool "SELECT count(*) FROM article" ::
IO [Int];
let f = ...;
return f }