2016-01-05 72 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中詳細描述了這種情況。