Q:

Haskell - persistent error while trying to query just-created table

I'm trying to query a sqlite table using persistent, but getting a message saying the table doesn't exist, right after the message saying it was created.
Migrating: CREATE TABLE "Post"("id" INTEGER PRIMARY KEY,"content" VARCHAR NOT NULL)
user error (SQLite3 returned ErrorError while attempting to perform prepare "SELECT \"content\" FROM \"Post\" WHERE \"id\"=?": no such table: Post)

This is the code I am running (it's for a scotty web app so there is some scotty specific stuff in here)
runDb $ runMigration migrateAll --to create the table
liftIO $ runDb $ insert $ Post $ decodeUtf8 $ toStrict image --to attempt to insert the data, this is what fails

Here are my definitions of those functions:
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistUpperCase|
Post
    content Text
|]

runDb :: SqlPersist (ResourceT IO) a -> IO a
runDb query = runResourceT . withSqliteConn ":memory:" . runSqlConn $ query

It seems to be claiming to create the table but not actually doing so.

A:

You are creating the table in memory, therefore, after each run of runDb the data is thrown away.
There are two possible solutions:

Use a file to store the data (ie- change ":memory:" to "filename.sqlite3").  The data will persist from run to run also.
Run the code to create and populate the data in a single runDb.  The code will work, but the data will be lost from run to run.

