Drkcore

20 12 2012 Haskell Tweet

Haskellのpersistentが動かない

persistent-1.1.0.1,persistent-template-1.1.1が入っている。

Persistentのsynopsisの例を実行すると

No instance for (Control.Monad.Trans.Resource.MonadResource IO)
  arising from a use of `selectList'
Possible fix:
  add an instance declaration for
  (Control.Monad.Trans.Resource.MonadResource IO)
In a stmt of a 'do' block:
  oneJohnPost <- selectList [BlogPostAuthorId ==. johnId] [LimitTo 1]
In the second argument of `($)', namely
  `do { runMigration migrateAll;
        johnId <- insert $ Person "John Doe" $ Just 35;
        janeId <- insert $ Person "Jane Doe" Nothing;
        insert $ BlogPost "My fr1st p0st" johnId;
        .... }'
In the second argument of `($)', namely
  `runSqlConn
   $ do { runMigration migrateAll;
          johnId <- insert $ Person "John Doe" $ Just 35;
          janeId <- insert $ Person "Jane Doe" Nothing;
          insert $ BlogPost "My fr1st p0st" johnId;
          .... }'

困った。

ProductName Developing Web Applications With Haskell and Yesod
Michael Snoyman
Oreilly & Associates Inc / 2805円 ( 2012-05-04 )


追記 121220

これは動く

{-# 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
|]

main :: IO ()
main = withSqliteConn "test.db" $ runSqlConn $ do
    runMigration migrateAll
    -- johnId <- insert $ Person "John Doe" $ Just 35
    -- liftIO $ print johnId

insertしたりselectListしたりするとNo instance for (Control.Monad.Trans.Resource.MonadResource IO)が出る。

追記 121220

これか? - Simplified Persistent Types

追記 121220

バージョンを下げたら動いたので当分この組み合わせで使う

  • persistent-1.0.2.2
  • persistent-sqlite-1.0.1
  • persistent-template-1.0.0.2

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021