Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After rereading the question, I think the simple answer is to use <a href="http://hackage.haskell.org/packages/archive/lifted-base/0.2.0.2/doc/html/Control-Exception-Lifted.html#v%3abracket" rel="nofollow">a lifted bracket</a>, which will handle all of the transformer issues. I'll leave my original answer as well, as it might give a bit more insight into what's happening.</p> <hr> <p>The problem in this case is the usage of <code>liftIO</code>. Let's look at the type signature:</p> <pre><code>liftIO :: MonadIO m =&gt; IO a -&gt; m a </code></pre> <p>What this means is that you can take an arbitrary I/O action (e.g., reading from a file) and run it in any monad which allows I/O to be performed, such as the database monad. However, what you're trying to do is really the opposite: run a database monad action as just a normal I/O action. This can't be directly done, since the database actions rely on extra context- specifically a database connection- which the <code>IO</code> monad doesn't provide.</p> <p>So how do you turn a database action into an IO action? We have to <em>unwrap</em>. Unwrapping is a common activity for <em>monad transformers</em>, which can be thought of as layers added on top of each other. Lifting (as in <code>liftIO</code>) allows you to take an action from a lower layer and move it up to a higher layer. Unwrapping takes a layer off. Since how you unwrap depends on the specific transformer, each transformer has its own unwrap functions.</p> <p>In the case of Persistent, you can use withSqliteConn or the equivalent for your backend, see the synopsis in the <a href="http://www.yesodweb.com/book/persistent" rel="nofollow">Persistent chapter</a> for more details.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload