2016-01-05 22 views
-3

我一直在寻找在网络上工作示例Yesod连接 - Persistent到MySQL数据库,我发现这个resource on GitHub耶索德和MySQL连接问题

{-# LANGUAGE EmptyDataDecls    #-} 
{-# LANGUAGE FlexibleContexts   #-} 
{-# LANGUAGE GADTs      #-} 
{-# LANGUAGE GeneralizedNewtypeDeriving #-} 
{-# LANGUAGE MultiParamTypeClasses  #-} 
{-# LANGUAGE OverloadedStrings   #-} 
{-# LANGUAGE QuasiQuotes    #-} 
{-# LANGUAGE TemplateHaskell   #-} 
{-# LANGUAGE TypeFamilies    #-} 
import   Control.Monad.IO.Class (liftIO) 
import   Control.Monad.Logger (runStderrLoggingT) 
import   Database.Persist 
import   Database.Persist.MySQL 
import   Database.Persist.TH 

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| 
Person 
    name String 
    age Int Maybe 
    address Int 
    deriving Show 
BlogPost 
    title String 
    authorId PersonId 
    deriving Show 
|] 

connectionInfo = defaultConnectInfo { connectPort = 5000, 
             connectPassword = "password", 
             connectDatabase = "database"} 

main :: IO() 
main = runStderrLoggingT $ withMySQLPool connectionInfo 10 $ \pool -> liftIO $ do 
     flip runSqlPersistMPool pool $ do 
      printMigration migrateAll 

当我尝试这个代码ghci我得到以下错误:

Prelude> :l test3.hs 
[1 of 1] Compiling Main    (test3.hs, interpreted) 

test3.hs:35:27: 
    Couldn't match type `persistent-2.2.2.1:Database.Persist.Sql.Types.SqlBackend' 
        with `SqlBackend' 
    Expected type: Migration 
     Actual type: persistent-2.2.2.1:Database.Persist.Sql.Types.Migration 
    In the first argument of `printMigration', namely `migrateAll' 
    In a stmt of a 'do' block: printMigration migrateAll 
    In the second argument of `($)', namely 
     `do { printMigration migrateAll }' 
Failed, modules loaded: none. 

而我陷入了它。

我的另一个问题是:有没有人有Yesod + MySQL的经验?如果是的话,我想知道这是一个好还是有问题的选择。

+0

请阅读[我可以问哪些主题](http://stackoverflow.com/help/on-topic) 和[如何提出一个好问题](http://stackoverflow.com/help/how - 问) 和[完美的问题](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) – RiggsFolly

+0

@RiggsFolly它可能对其他用户有用,那里网络上的资源非常少。 – FtheBuilder

+0

这很好,另外4人不得不同意我接近被采取的行动 – RiggsFolly

回答

3

它看起来像你有两个版本的软件包安装。如果您使用Stack进行安装,它将确保您在范围内只有单个版本的每个软件包。我在this blog post中详细描述了这种情况。