因此,我计划与Sqlite使用0.9.0.1,我正在通过辅导:。
添加和盘问的简单幻灯没有汇编成册:
-- 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持续合作?