sqliteInit :: SnapletInit b Sqlite
sqliteInit = makeSnaplet "sqlite-simple" description datadir $ do
    config <- getSnapletUserConfig
    (mci,errs) <- runWriterT $
        logErr "Must specify db filename" $ C.lookup config "db"
    let ci = fromMaybe (error $ intercalate "\n" errs) mci
    tracing <- liftIO $ C.lookupDefault False config "enableSqlTracing"
    conn <- liftIO (S.open ci >>= setTracing tracing >>= newMVar)
    return $ Sqlite conn
  where
    description = "Sqlite abstraction"

    datadir = Just $ liftM (++"/resources/db") getDataDir

    setTracing tracing conn = do
      when tracing (S.setTrace conn (Just (putStrLn . T.unpack)))
      return conn

------------------------------------------------------------------------------
-- | Convenience function for executing a function that needs a database
-- connection.
--
-- /Multi-threading considerations/: The database connection is mutexed
-- such that only a single thread can read or write at any given time.
-- This means we lose database access parallelism.  Please see
-- <https://github.com/nurpax/snaplet-sqlite-simple/issues/5> for more
-- information.
sqliteInit :: SnapletInit b Sqlite
sqliteInit = makeSnaplet "sqlite-simple" description datadir $ do
    config <- getSnapletUserConfig
    (mci,errs) <- runWriterT $
        logErr "Must specify db filename" $ C.lookup config "db"
    let ci = fromMaybe (error $ intercalate "\n" errs) mci
    tracing <- liftIO $ C.lookupDefault False config "enableSqlTracing"
    conn <- liftIO (S.open ci >>= setTracing tracing >>= newMVar)
    return $ Sqlite conn
  where
    description = "Sqlite abstraction"

    datadir = Just $ liftM (++"/resources/db") getDataDir

    setTracing tracing conn = do
      when tracing (S.setTrace conn (Just (putStrLn . T.unpack)))
      return conn

------------------------------------------------------------------------------
-- | Convenience function for executing a function that needs a database
-- connection.
--
-- /Multi-threading considerations/: The database connection is mutexed
-- such that only a single thread can read or write at any given time.
-- This means we lose database access parallelism.  Please see
-- <https://github.com/nurpax/snaplet-sqlite-simple/issues/5> for more
-- information.
sqliteInit = makeSnaplet "sqlite-simple" description datadir $ do
    config <- getSnapletUserConfig
    (mci,errs) <- runWriterT $
        logErr "Must specify db filename" $ C.lookup config "db"
    let ci = fromMaybe (error $ intercalate "\n" errs) mci
    tracing <- liftIO $ C.lookupDefault False config "enableSqlTracing"
    conn <- liftIO (S.open ci >>= setTracing tracing >>= newMVar)
    return $ Sqlite conn
  where
    description = "Sqlite abstraction"

    datadir = Just $ liftM (++"/resources/db") getDataDir

    setTracing tracing conn = do
      when tracing (S.setTrace conn (Just (putStrLn . T.unpack)))
      return conn

------------------------------------------------------------------------------
-- | Convenience function for executing a function that needs a database
-- connection.
--
-- /Multi-threading considerations/: The database connection is mutexed
-- such that only a single thread can read or write at any given time.
-- This means we lose database access parallelism.  Please see
-- <https://github.com/nurpax/snaplet-sqlite-simple/issues/5> for more
-- information.