Closed ghost closed 6 years ago
Thanks for your PR! Is there any reason why you have introduced the helper function runSqlite'
function ? This seems to work fine for me:
#!/usr/bin/env stack
{- stack
--resolver lts-12.1
--install-ghc
runghc
--package persistent
--package persistent-sqlite
--package persistent-template
-}
{-# 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
import Control.Monad.IO.Unlift
import Data.Text
import Control.Monad.Reader
import Control.Monad.Logger
import Conduit
share [mkPersist sqlSettings, mkSave "entityDefs"] [persistLowerCase|
Person
name String
age Int Maybe
deriving Show
|]
main :: IO ()
main = runSqlite ":memory:" $ do
runMigration $ migrate entityDefs $ entityDef (Nothing :: Maybe Person)
michaelId <- insert $ Person "Michael" $ Just 26
michael <- get michaelId
liftIO $ print michael
oke, on the last one with the migration your code works. The code before it , do not work without the helper function.
I see then this error message as described in #213
Configuring GHCi with the following packages:
GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from C:\Users\rwobb\AppData\Local\Temp\haskell-stack-ghci\2a3bbd58\ghci-script
[1 of 1] Compiling Main ( createDatabase.hs, interpreted )
createDatabase.hs:29:8: error:
* 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
|
29 | main = runSqlite ":memory:" $ do
| ^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
So should I delete the helper function in the code with the migration and let it stay in the code without the migration.
@RoelofWobben Sorry for my late reply.
So should I delete the helper function in the code with the migration and let it stay in the code without the migration.
Yes.
Oke I will do that after my holydays.
Thanks!
In the first example I changed some typos. The migration part had a wrong identation and it had a type definition that was not needed.
In the second example made some changes so it solves #213