所以我刨使用持久0.9.0.1使用SQLite,和我經歷的教程:http://www.yesodweb.com/book/persistent新手問題持續
簡單的片段,以插入和查詢編譯失敗:
-- START
{-# LANGUAGE QuasiQuotes, TypeFamilies, GeneralizedNewtypeDeriving, TemplateHaskell,
OverloadedStrings, GADTs, FlexibleContexts #-}
import Database.Persist
import Database.Persist.TH
import Database.Persist.Sqlite
import Control.Monad.IO.Class (liftIO)
share [mkPersist sqlSettings, mkSave "entityDefs"] [persist|
Person
name String
age Int
|]
main = withSqliteConn ":memory:" $ runSqlConn $ do
runMigration $ migrate entityDefs (undefined :: Person) -- this line added: that's it!
michaelId <- insert $ Person "Michael" 26
michael <- get michaelId
liftIO $ print michael
-- STOP
傾銷拼接顯示沒有答應Eq
,Show
實例爲生成的人,奇道:
data PersonGeneric (backend :: (* -> *) -> * -> *)
= Person {personName :: String, personAge :: Int}
type Person =
PersonGeneric Database.Persist.GenericSql.Raw.SqlPersist
我砍它是這樣的:
liftIO $ putStrLn $ "name: " ++ (personName $ fromJust michael) ++ ", age: " ++ (show $ personAge $ fromJust michael)
,然後插入無法從SQLite的獲取主鍵回:
Migrating: CREATE TABLE "person"("id" INTEGER PRIMARY KEY,"name" VARCHAR NOT NULL,"age" INTEGER NOT NULL)
proto: Pattern match failure in do expression at Database/Persist/GenericSql.hs:109:25-45
任何想法?持續使用Sqlite嗎?
您能否包含錯誤消息?是「沒有實例嗎?(Show Person)'」? – hammar 2012-04-17 06:27:36
@hammar是的,它是在邁克爾的幫助下解決的。 – 2012-04-18 05:15:25