Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

persistent page. Couldn't match type BaseBackend backend0' with SqlBackend' #213

Open
ghost opened this issue Jul 18, 2018 · 4 comments
Open

Comments

@ghost
Copy link

ghost commented Jul 18, 2018

Hello,

When I run the first code from the persistent page I see this error appear,


* Couldn't match type `BaseBackend backend0' with `SqlBackend'
        arising from a use of `runSqlite'
      The type variable `backend0' is ambiguous
    * In the expression: runSqlite ":memory:"
      In the expression:
        runSqlite ":memory:"
          $ do michaelId <- insert $ Person "Michael" $ Just 26
               michael <- get michaelId
               liftIO $ print michael
      In an equation for `main':
          main
            = runSqlite ":memory:"
                $ do michaelId <- insert $ Person "Michael" $ Just 26
                     michael <- get michaelId
                     liftIO $ print michael
   |
24 | main = runSqlite ":memory:" $ do

I can make a PR how to solve this but I need to know where this page can be found.

@snoyberg
Copy link
Member

snoyberg commented Jul 19, 2018 via email

@ghost
Copy link
Author

ghost commented Jul 19, 2018

Moment, this is the code just before the migration is added.
Im talking about this one :

{-# 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           Database.Persist
import           Database.Persist.Sqlite
import           Database.Persist.TH

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person
    name String
    age Int Maybe
    deriving Show
|]

main :: IO ()
main = runSqlite ":memory:" $ do
    michaelId <- insert $ Person "Michael" $ Just 26
    michael <- get michaelId
    liftIO $ print michael

and I solved it with a little help of the slack channel this way :


runSqlite' :: (MonadUnliftIO m) => Text -> ReaderT SqlBackend (NoLoggingT (ResourceT m)) a -> m a
runSqlite' = runSqlite

main :: IO ()
main = runSqlite' ":memory:" $ do
    michaelId <- insert $ Person "Michael" $ Just 26
    michael <- get michaelId
    liftIO $ print michael

@ghost
Copy link
Author

ghost commented Jul 19, 2018

and yes, I can try to make a PR but as I said earlier have to know which file this exactly is.

@snoyberg
Copy link
Member

The source is available here:

https://github.com/yesodweb/yesodweb.com-content/blob/master/book/asciidoc/persistent.asciidoc

For future reference, each chapter in the book has a (relatively small) link at the top that says "View source on Github".

@ghost ghost mentioned this issue Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant