4
我試圖在Yesod書(第10章)中運行持久性示例。我在.hs文件中輸入了初始示例,創建了一個cabal文件,並嘗試編譯。編譯器抱怨它找不到「堅持」。我認爲這個函數已經轉移到一個新的包(我沒有包括)或者已經被棄用了,但是我不知道哪個和哪個包還沒有解決這個問題。任何幫助將非常感激。也許我應該回到本書基於的Yesod版本。我應該爲此安裝哪個yesod平臺?謝謝,蒂姆Yesod書中的第一個持久性示例將無法編譯 - 找不到持久
以下是錯誤消息:
perry$ cabal install
Resolving dependencies...
Configuring chapter10-0.1.0.0...
Building chapter10-0.1.0.0...
Preprocessing executable 'chapter10' for chapter10-0.1.0.0...
[1 of 1] Compiling Main (ex1.hs, dist/build/chapter10/chapter10-tmp/Main.o)
ex1.hs:8:55: Not in scope: `persist'
cabal: Error: some packages failed to install:
chapter10-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1
這裏是我的chapter10.cabal文件:
-- Initial chapter10.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: chapter10
version: 0.1.0.0
license-file: LICENSE
cabal-version: >=1.8
build-type: Simple
executable chapter10
main-is: ex1.hs
-- other-modules:
build-depends: base ==4.5.*
, yesod-platform
, yesod
, persistent-sqlite
, transformers
, persistent-template
, persistent
這裏是我的ex1.hs文件:
{-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies, OverloadedStrings #-}
{-# LANGUAGE GADTs, FlexibleContexts #-}
import Database.Persist
import Database.Persist.Sqlite
import Database.Persist.TH
import Control.Monad.IO.Class (liftIO)
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persist|
Person
name String
age Int Maybe
deriving Show
BlogPost
title String
authorId PersonId
deriving Show
|]
main :: IO()
main = withSqliteConn ":memory:" $ runSqlConn $ do
runMigration migrateAll
johnId <- insert $ Person "John Doe" $ Just 35
janeId <- insert $ Person "Jane Doe" Nothing
insert $ BlogPost "My fr1st p0st" johnId
insert $ BlogPost "One more for good measure" johnId
oneJohnPost <- selectList [BlogPostAuthorId ==. johnId] [LimitTo 1]
liftIO $ print (oneJohnPost :: [Entity BlogPost])
john <- get johnId
liftIO $ print (john :: Maybe Person)
delete janeId
deleteWhere [BlogPostAuthorId ==. johnId]
以下是我的yesod和persistent軟件包的版本:
perry$ ghc-pkg list| grep -i -e yesod -e persist
persistent-1.2.0.1
persistent-sqlite-1.2.0
persistent-template-1.2.0.1
yesod-1.2.1
yesod-auth-1.2.0.1
yesod-core-1.2.2
yesod-form-1.3.0
yesod-persistent-1.2.1
yesod-platform-1.2.1
yesod-routes-1.2.0.1
yesod-static-1.2.0
yesod-test-1.2.0
啊......我從來沒有想過檢查舊的文檔。我只看了1.2.0.0和1.2.0.1。感謝您爲我思考! – tim93422