persistent-sqlite-2.6.0.1: Backend for the persistent library using sqlite3.

Safe Haskell | None
Language | Haskell98

Database.Persist.Sqlite

Description

A sqlite backend for persistent.

Note: If you prepend `WAL=off` to your connection string, it will disable the write-ahead log. For more information, see https://github.com/yesodweb/persistent/issues/363.

Synopsis

- withSqlitePool :: (MonadBaseControl IO m, MonadIO m, MonadLogger m, IsSqlBackend backend) => Text -> Int -> (Pool backend -> m a) -> m a
- withSqliteConn :: (MonadBaseControl IO m, MonadIO m, MonadLogger m, IsSqlBackend backend) => Text -> (backend -> m a) -> m a
- createSqlitePool :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, IsSqlBackend backend) => Text -> Int -> m (Pool backend)
- module Database.Persist.Sql
- data SqliteConf = SqliteConf {
  - sqlDatabase :: Text
  - sqlPoolSize :: Int
  }
- runSqlite :: (MonadBaseControl IO m, MonadIO m, IsSqlBackend backend) => Text -> ReaderT backend (NoLoggingT (ResourceT m)) a -> m a
- wrapConnection :: IsSqlBackend backend => Connection -> LogFunc -> IO backend
- mockMigration :: Migration -> IO ()

# Documentation

withSqlitePool #

Arguments

:: (MonadBaseControl IO m, MonadIO m, MonadLogger m, IsSqlBackend backend) |
=> Text |
-> Int | number of connections to open
-> (Pool backend -> m a) |
-> m a |

Run the given action with a connection pool.

Like `createSqlitePool`, this should not be used with `:memory:`.

withSqliteConn :: (MonadBaseControl IO m, MonadIO m, MonadLogger m, IsSqlBackend backend) => Text -> (backend -> m a) -> m a #

createSqlitePool :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, IsSqlBackend backend) => Text -> Int -> m (Pool backend) #

Create a pool of SQLite connections.

Note that this should not be used with the `:memory:` connection string, as the pool will regularly remove connections, destroying your database. Instead, use `withSqliteConn`.

module Database.Persist.Sql

data SqliteConf #

Information required to connect to a sqlite database

Constructors

SqliteConf |
Fields sqlDatabase :: Text sqlPoolSize :: Int

Instances

Show SqliteConf # |
Methods showsPrec :: Int -> SqliteConf -> ShowS # show :: SqliteConf -> String # showList :: [SqliteConf] -> ShowS #
FromJSON SqliteConf # |
Methods parseJSON :: Value -> Parser SqliteConf # parseJSONList :: Value -> Parser [SqliteConf] #
PersistConfig SqliteConf # |
Associated Types type PersistConfigBackend SqliteConf :: (* -> *) -> * -> * # type PersistConfigPool SqliteConf :: * # Methods loadConfig :: Value -> Parser SqliteConf # applyEnv :: SqliteConf -> IO SqliteConf # createPoolConfig :: SqliteConf -> IO (PersistConfigPool SqliteConf) # runPool :: (MonadBaseControl IO m, MonadIO m) => SqliteConf -> PersistConfigBackend SqliteConf m a -> PersistConfigPool SqliteConf -> m a #
type PersistConfigPool SqliteConf # |
type PersistConfigPool SqliteConf = ConnectionPool
type PersistConfigBackend SqliteConf # |
type PersistConfigBackend SqliteConf = SqlPersistT

runSqlite #

Arguments

:: (MonadBaseControl IO m, MonadIO m, IsSqlBackend backend) |
=> Text | connection string
-> ReaderT backend (NoLoggingT (ResourceT m)) a | database action
-> m a |

A convenience helper which creates a new database connection and runs the given block, handling `MonadResource` and `MonadLogger` requirements. Note that all log messages are discarded.

Since 1.1.4

wrapConnection :: IsSqlBackend backend => Connection -> LogFunc -> IO backend #

Wrap up a raw `Connection` as a Persistent SQL `Connection`.

Since 1.1.5

mockMigration :: Migration -> IO () #

Mock a migration even when the database is not present. This function performs the same functionality of `printMigration` with the difference that an actualy database isn't needed for it.