-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Backend for the persistent library using sqlite3. -- -- This package includes a thin sqlite3 wrapper based on the -- direct-sqlite package, as well as the entire C library, so there are -- no system dependencies. @package persistent-sqlite @version 2.10.6.1 -- | Utterly unsafe internals of the Database.Sqlite module. Useful -- for people who want access to the SQLite database pointer to manually -- call SQLite API functions via the FFI. -- -- Types and functions in this module are *NOT* covered by the PVP and -- may change breakingly in any future version of the package. module Database.Sqlite.Internal -- | SQLite connection type, consist of an IORef tracking whether the -- connection has been closed and the raw SQLite C API pointer, wrapped -- in a 'Connection\'' newtype. data Connection Connection :: !IORef Bool -> Connection' -> Connection -- | Newtype wrapping SQLite C API pointer for a database connection. newtype Connection' Connection' :: Ptr () -> Connection' -- | Newtype wrapping SQLite C API pointer for a prepared statement. newtype Statement Statement :: Ptr () -> Statement -- | A port of the direct-sqlite package for dealing directly with -- PersistValues. module Database.Sqlite -- | SQLite connection type, consist of an IORef tracking whether the -- connection has been closed and the raw SQLite C API pointer, wrapped -- in a 'Connection\'' newtype. data Connection -- | Newtype wrapping SQLite C API pointer for a prepared statement. data Statement data Error ErrorOK :: Error ErrorError :: Error ErrorInternal :: Error ErrorPermission :: Error ErrorAbort :: Error ErrorBusy :: Error ErrorLocked :: Error ErrorNoMemory :: Error ErrorReadOnly :: Error ErrorInterrupt :: Error ErrorIO :: Error ErrorNotFound :: Error ErrorCorrupt :: Error ErrorFull :: Error ErrorCan'tOpen :: Error ErrorProtocol :: Error ErrorEmpty :: Error ErrorSchema :: Error ErrorTooBig :: Error ErrorConstraint :: Error ErrorMismatch :: Error ErrorMisuse :: Error ErrorNoLargeFileSupport :: Error ErrorAuthorization :: Error ErrorFormat :: Error ErrorRange :: Error ErrorNotAConnection :: Error ErrorRow :: Error ErrorDone :: Error -- | A custom exception type to make it easier to catch exceptions. data SqliteException SqliteException :: !Error -> !Text -> !Text -> SqliteException [seError] :: SqliteException -> !Error [seFunctionName] :: SqliteException -> !Text [seDetails] :: SqliteException -> !Text data StepResult Row :: StepResult Done :: StepResult -- | Configuration option for SQLite to be used together with the -- config function. data Config -- | A function to be used for logging ConfigLogFn :: LogFunction -> Config data LogFunction -- | Return type of the status function data SqliteStatus SqliteStatus :: Maybe Int -> Maybe Int -> SqliteStatus -- | The current value of the parameter. Some parameters do not record -- current value. [sqliteStatusCurrent] :: SqliteStatus -> Maybe Int -- | The highest recorded value. Some parameters do not record the highest -- value. [sqliteStatusHighwater] :: SqliteStatus -> Maybe Int -- | Run-time status parameter that can be returned by status -- function. data SqliteStatusVerb -- | This parameter is the current amount of memory checked out using -- sqlite3_malloc(), either directly or indirectly. The figure includes -- calls made to sqlite3_malloc() by the application and internal memory -- usage by the SQLite library. Scratch memory controlled by -- SQLITE_CONFIG_SCRATCH and auxiliary page-cache memory controlled by -- SQLITE_CONFIG_PAGECACHE is not included in this parameter. The amount -- returned is the sum of the allocation sizes as reported by the xSize -- method in sqlite3_mem_methods. SqliteStatusMemoryUsed :: SqliteStatusVerb -- | This parameter returns the number of pages used out of the pagecache -- memory allocator that was configured using SQLITE_CONFIG_PAGECACHE. -- The value returned is in pages, not in bytes. SqliteStatusPagecacheUsed :: SqliteStatusVerb -- | This parameter returns the number of bytes of page cache allocation -- which could not be satisfied by the SQLITE_CONFIG_PAGECACHE buffer and -- where forced to overflow to sqlite3_malloc(). The returned value -- includes allocations that overflowed because they where too large -- (they were larger than the "sz" parameter to SQLITE_CONFIG_PAGECACHE) -- and allocations that overflowed because no space was left in the page -- cache. SqliteStatusPagecacheOverflow :: SqliteStatusVerb -- | This parameter returns the number of allocations used out of the -- scratch memory allocator configured using SQLITE_CONFIG_SCRATCH. The -- value returned is in allocations, not in bytes. Since a single thread -- may only have one scratch allocation outstanding at time, this -- parameter also reports the number of threads using scratch memory at -- the same time. SqliteStatusScratchUsed :: SqliteStatusVerb -- | This parameter returns the number of bytes of scratch memory -- allocation which could not be satisfied by the SQLITE_CONFIG_SCRATCH -- buffer and where forced to overflow to sqlite3_malloc(). The values -- returned include overflows because the requested allocation was too -- larger (that is, because the requested allocation was larger than the -- "sz" parameter to SQLITE_CONFIG_SCRATCH) and because no scratch buffer -- slots were available. SqliteStatusScratchOverflow :: SqliteStatusVerb -- | This parameter records the largest memory allocation request handed to -- sqlite3_malloc() or sqlite3_realloc() (or their internal equivalents). -- Only the value returned in sqliteStatusHighwater field of -- SqliteStatus record is of interest. The value written into the -- sqliteStatusCurrent field is Nothing. SqliteStatusMallocSize :: SqliteStatusVerb -- | This parameter records the largest memory allocation request handed to -- pagecache memory allocator. Only the value returned in the -- sqliteStatusHighwater field of SqliteStatus record is of -- interest. The value written into the sqliteStatusCurrent field -- is Nothing. SqliteStatusPagecacheSize :: SqliteStatusVerb -- | This parameter records the largest memory allocation request handed to -- scratch memory allocator. Only the value returned in the -- sqliteStatusHighwater field of SqliteStatus record is of -- interest. The value written into the sqliteStatusCurrent field -- is Nothing. SqliteStatusScratchSize :: SqliteStatusVerb -- | This parameter records the number of separate memory allocations -- currently checked out. SqliteStatusMallocCount :: SqliteStatusVerb open :: Text -> IO Connection close :: Connection -> IO () prepare :: Connection -> Text -> IO Statement -- | Execute a database statement. It's recommended to use stepConn -- instead, because it gives better error messages. step :: Statement -> IO StepResult -- | Execute a database statement. This function uses the Connection -- passed to it to give better error messages than step. stepConn :: Connection -> Statement -> IO StepResult reset :: Connection -> Statement -> IO () finalize :: Statement -> IO () bindBlob :: Statement -> Int -> ByteString -> IO () bindDouble :: Statement -> Int -> Double -> IO () bindInt :: Statement -> Int -> Int -> IO () bindInt64 :: Statement -> Int -> Int64 -> IO () bindNull :: Statement -> Int -> IO () bindText :: Statement -> Int -> Text -> IO () bind :: Statement -> [PersistValue] -> IO () column :: Statement -> Int -> IO PersistValue columns :: Statement -> IO [PersistValue] changes :: Connection -> IO Int64 -- | Wraps a given function to a LogFunction to be further used with -- ConfigLogFn. First argument of given function will take error -- code, second - log message. Returned value should be released with -- freeLogFunction when no longer required. mkLogFunction :: (Int -> String -> IO ()) -> IO LogFunction -- | Releases a native FunPtr for the LogFunction. freeLogFunction :: LogFunction -> IO () -- | Sets SQLite global configuration parameter. See SQLite documentation -- for the sqlite3_config function. In short, this must be called -- prior to any other SQLite function if you want the call to succeed. config :: Config -> IO () -- | Retrieves runtime status information about the performance of SQLite, -- and optionally resets various highwater marks. The first argument is a -- status parameter to measure, the second is reset flag. If reset flag -- is True then the highest recorded value is reset after being returned -- from this function. status :: SqliteStatusVerb -> Bool -> IO SqliteStatus -- | Sets and/or queries the soft limit on the amount of heap memory that -- may be allocated by SQLite. If the argument is zero then the soft heap -- limit is disabled. If the argument is negative then no change is made -- to the soft heap limit. Hence, the current size of the soft heap limit -- can be determined by invoking this function with a negative argument. softHeapLimit :: Int64 -> IO Int64 enableExtendedResultCodes :: Connection -> IO () disableExtendedResultCodes :: Connection -> IO () instance GHC.Show.Show Database.Sqlite.SqliteStatus instance GHC.Classes.Eq Database.Sqlite.SqliteStatus instance GHC.Show.Show Database.Sqlite.ColumnType instance GHC.Classes.Eq Database.Sqlite.ColumnType instance GHC.Show.Show Database.Sqlite.StepResult instance GHC.Classes.Eq Database.Sqlite.StepResult instance GHC.Show.Show Database.Sqlite.Error instance GHC.Classes.Eq Database.Sqlite.Error instance GHC.Show.Show Database.Sqlite.SqliteException instance GHC.Exception.Type.Exception Database.Sqlite.SqliteException -- | A sqlite backend for persistent. -- -- Note: If you prepend WAL=off to your connection string, it -- will disable the write-ahead log. This functionality is now deprecated -- in favour of using SqliteConnectionInfo. module Database.Persist.Sqlite -- | Run the given action with a connection pool. -- -- Like createSqlitePool, this should not be used with -- :memory:. withSqlitePool :: (MonadUnliftIO m, MonadLogger m) => Text -> Int -> (Pool SqlBackend -> m a) -> m a -- | Run the given action with a connection pool. -- -- Like createSqlitePool, this should not be used with -- :memory:. withSqlitePoolInfo :: (MonadUnliftIO m, MonadLogger m) => SqliteConnectionInfo -> Int -> (Pool SqlBackend -> m a) -> m a withSqliteConn :: (MonadUnliftIO m, MonadLogger m) => Text -> (SqlBackend -> m a) -> m a withSqliteConnInfo :: (MonadUnliftIO m, MonadLogger m) => SqliteConnectionInfo -> (SqlBackend -> m a) -> m a -- | 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. createSqlitePool :: (MonadLogger m, MonadUnliftIO m) => Text -> Int -> m (Pool SqlBackend) -- | 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. createSqlitePoolFromInfo :: (MonadLogger m, MonadUnliftIO m) => SqliteConnectionInfo -> Int -> m (Pool SqlBackend) -- | Information required to setup a connection pool. data SqliteConf SqliteConf :: Text -> Int -> SqliteConf [sqlDatabase] :: SqliteConf -> Text [sqlPoolSize] :: SqliteConf -> Int SqliteConfInfo :: SqliteConnectionInfo -> Int -> SqliteConf [sqlConnInfo] :: SqliteConf -> SqliteConnectionInfo [sqlPoolSize] :: SqliteConf -> Int -- | Information required to connect to a sqlite database. We export lenses -- instead of fields to avoid being limited to the current -- implementation. data SqliteConnectionInfo -- | Creates a SqliteConnectionInfo from a connection string, with the -- default settings. mkSqliteConnectionInfo :: Text -> SqliteConnectionInfo sqlConnectionStr :: Lens' SqliteConnectionInfo Text walEnabled :: Lens' SqliteConnectionInfo Bool fkEnabled :: Lens' SqliteConnectionInfo Bool extraPragmas :: Lens' SqliteConnectionInfo [Text] -- | 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. runSqlite :: MonadUnliftIO m => Text -> ReaderT SqlBackend (NoLoggingT (ResourceT m)) a -> 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. runSqliteInfo :: MonadUnliftIO m => SqliteConnectionInfo -> ReaderT SqlBackend (NoLoggingT (ResourceT m)) a -> m a -- | Wrap up a raw Connection as a Persistent SQL -- Connection. -- --

Example usage

-- --
--   {-# LANGUAGE GADTs #-}
--   {-# LANGUAGE ScopedTypeVariables #-}
--   {-# LANGUAGE OverloadedStrings #-}
--   {-# LANGUAGE MultiParamTypeClasses #-}
--   {-# LANGUAGE TypeFamilies #-}
--   {-# LANGUAGE TemplateHaskell #-}
--   {-# LANGUAGE QuasiQuotes #-}
--   {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--   
--   import Control.Monad.IO.Class  (liftIO)
--   import Database.Persist
--   import Database.Sqlite
--   import Database.Persist.Sqlite
--   import Database.Persist.TH
--   
--   share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
--   Person
--     name String
--     age Int Maybe
--     deriving Show
--   |]
--   
--   main :: IO ()
--   main = do
--     conn <- open "/home/sibi/test.db"
--     (backend :: SqlBackend) <- wrapConnection conn (\_ _ _ _ -> return ())
--     flip runSqlPersistM backend $ do
--            runMigration migrateAll
--            insert_ $ Person "John doe" $ Just 35
--            insert_ $ Person "Hema" $ Just 36
--            (pers :: [Entity Person]) <- selectList [] []
--            liftIO $ print pers
--     close' backend
--   
-- -- On executing it, you get this output: -- --
--   Migrating: CREATE TABLE "person"("id" INTEGER PRIMARY KEY,"name" VARCHAR NOT NULL,"age" INTEGER NULL)
--   [Entity {entityKey = PersonKey {unPersonKey = SqlBackendKey {unSqlBackendKey = 1}}, entityVal = Person {personName = "John doe", personAge = Just 35}},Entity {entityKey = PersonKey {unPersonKey = SqlBackendKey {unSqlBackendKey = 2}}, entityVal = Person {personName = "Hema", personAge = Just 36}}]
--   
wrapConnection :: Connection -> LogFunc -> IO SqlBackend -- | Wrap up a raw Connection as a Persistent SQL -- Connection, allowing full control over WAL and FK -- constraints. wrapConnectionInfo :: SqliteConnectionInfo -> Connection -> LogFunc -> IO SqlBackend -- | Mock a migration even when the database is not present. This function -- performs the same functionality of printMigration with the -- difference that an actual database isn't needed for it. mockMigration :: Migration -> IO () -- | Retry if a Busy is thrown, following an exponential backoff strategy. retryOnBusy :: (MonadUnliftIO m, MonadLogger m) => m a -> m a -- | Wait until some noop action on the database does not return an -- ErrorBusy. See retryOnBusy. waitForDatabase :: (MonadUnliftIO m, MonadLogger m, BackendCompatible SqlBackend backend) => ReaderT backend m () -- | Wrapper for persistent SqlBackends that carry the corresponding -- Connection. data RawSqlite backend persistentBackend :: forall backend_atXB backend_au5F. Lens (RawSqlite backend_atXB) (RawSqlite backend_au5F) backend_atXB backend_au5F rawSqliteConnection :: forall backend_atXB. Lens' (RawSqlite backend_atXB) Connection -- | Like withSqliteConnInfo, but exposes the internal -- Connection. For power users who want to manually interact with -- SQLite's C API via internals exposed by -- Database.Sqlite.Internal withRawSqliteConnInfo :: (MonadUnliftIO m, MonadLogger m) => SqliteConnectionInfo -> (RawSqlite SqlBackend -> m a) -> m a -- | Like createSqlitePoolFromInfo, but like -- withRawSqliteConnInfo it exposes the internal -- Connection. -- -- For power users who want to manually interact with SQLite's C API via -- internals exposed by Database.Sqlite.Internal. The callback can -- be used to run arbitrary actions on the connection upon allocation -- from the pool. createRawSqlitePoolFromInfo :: (MonadLogger m, MonadUnliftIO m) => SqliteConnectionInfo -> (RawSqlite SqlBackend -> m ()) -> Int -> m (Pool (RawSqlite SqlBackend)) -- | Like createRawSqlitePoolFromInfo, but doesn't require a -- callback operating on the connection. createRawSqlitePoolFromInfo_ :: (MonadLogger m, MonadUnliftIO m) => SqliteConnectionInfo -> Int -> m (Pool (RawSqlite SqlBackend)) -- | Like createSqlitePoolInfo, but based on -- createRawSqlitePoolFromInfo. withRawSqlitePoolInfo :: (MonadUnliftIO m, MonadLogger m) => SqliteConnectionInfo -> (RawSqlite SqlBackend -> m ()) -> Int -> (Pool (RawSqlite SqlBackend) -> m a) -> m a -- | Like createSqlitePoolInfo, but based on -- createRawSqlitePoolFromInfo_. withRawSqlitePoolInfo_ :: (MonadUnliftIO m, MonadLogger m) => SqliteConnectionInfo -> Int -> (Pool (RawSqlite SqlBackend) -> m a) -> m a instance GHC.Show.Show (Database.Persist.Class.PersistStore.BackendKey b) => GHC.Show.Show (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance GHC.Read.Read (Database.Persist.Class.PersistStore.BackendKey b) => GHC.Read.Read (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance GHC.Classes.Eq (Database.Persist.Class.PersistStore.BackendKey b) => GHC.Classes.Eq (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance GHC.Classes.Ord (Database.Persist.Class.PersistStore.BackendKey b) => GHC.Classes.Ord (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance GHC.Num.Num (Database.Persist.Class.PersistStore.BackendKey b) => GHC.Num.Num (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance GHC.Real.Integral (Database.Persist.Class.PersistStore.BackendKey b) => GHC.Real.Integral (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance Database.Persist.Class.PersistField.PersistField (Database.Persist.Class.PersistStore.BackendKey b) => Database.Persist.Class.PersistField.PersistField (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance Database.Persist.Sql.Class.PersistFieldSql (Database.Persist.Class.PersistStore.BackendKey b) => Database.Persist.Sql.Class.PersistFieldSql (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance GHC.Real.Real (Database.Persist.Class.PersistStore.BackendKey b) => GHC.Real.Real (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance GHC.Enum.Enum (Database.Persist.Class.PersistStore.BackendKey b) => GHC.Enum.Enum (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance GHC.Enum.Bounded (Database.Persist.Class.PersistStore.BackendKey b) => GHC.Enum.Bounded (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance Data.Aeson.Types.ToJSON.ToJSON (Database.Persist.Class.PersistStore.BackendKey b) => Data.Aeson.Types.ToJSON.ToJSON (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance Data.Aeson.Types.FromJSON.FromJSON (Database.Persist.Class.PersistStore.BackendKey b) => Data.Aeson.Types.FromJSON.FromJSON (Database.Persist.Class.PersistStore.BackendKey (Database.Persist.Sqlite.RawSqlite b)) instance Database.Persist.Class.PersistStore.HasPersistBackend b => Database.Persist.Class.PersistStore.HasPersistBackend (Database.Persist.Sqlite.RawSqlite b) instance Database.Persist.Class.PersistStore.BackendCompatible b (Database.Persist.Sqlite.RawSqlite b) instance Database.Persist.Class.PersistStore.PersistCore b => Database.Persist.Class.PersistStore.PersistCore (Database.Persist.Sqlite.RawSqlite b) instance Database.Persist.Class.PersistStore.PersistStoreRead b => Database.Persist.Class.PersistStore.PersistStoreRead (Database.Persist.Sqlite.RawSqlite b) instance Database.Persist.Class.PersistQuery.PersistQueryRead b => Database.Persist.Class.PersistQuery.PersistQueryRead (Database.Persist.Sqlite.RawSqlite b) instance Database.Persist.Class.PersistQuery.PersistQueryWrite b => Database.Persist.Class.PersistQuery.PersistQueryWrite (Database.Persist.Sqlite.RawSqlite b) instance Database.Persist.Class.PersistUnique.PersistUniqueRead b => Database.Persist.Class.PersistUnique.PersistUniqueRead (Database.Persist.Sqlite.RawSqlite b) instance Database.Persist.Class.PersistStore.PersistStoreWrite b => Database.Persist.Class.PersistStore.PersistStoreWrite (Database.Persist.Sqlite.RawSqlite b) instance Database.Persist.Class.PersistUnique.PersistUniqueWrite b => Database.Persist.Class.PersistUnique.PersistUniqueWrite (Database.Persist.Sqlite.RawSqlite b) instance GHC.Show.Show Database.Persist.Sqlite.SqliteConf instance GHC.Show.Show Database.Persist.Sqlite.SqliteConnectionInfo instance Data.Aeson.Types.FromJSON.FromJSON Database.Persist.Sqlite.SqliteConf instance Database.Persist.Class.PersistConfig.PersistConfig Database.Persist.Sqlite.SqliteConf instance Data.Aeson.Types.FromJSON.FromJSON Database.Persist.Sqlite.SqliteConnectionInfo