I'm trying to run the Persistent examples in the Yesod book (Chapter 10). I entered the initial example in a .hs file, created a cabal file, and tried to compile. The compiler complains it can't find "persist". I assume the function persist has moved to a new package (which I haven't included) or has been deprecated, but I don't know which and hoogle hasn't shed any light on the issue. Any help would be much appreciated. Perhaps I should revert to the version of Yesod that the book is based on. Which yesod-platform should I install for that? Thanks, Tim
Here is the error message:
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
Here is my chapter10.cabal file:
-- 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
Here is my ex1.hs file:
{-# 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]
Here are the versions of my yesod and persistent packages:
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