-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A primitive yet easy to use sqlite library. -- -- A primitive yet easy to use sqlite library built using sqlite-direct, -- resource-pool and migrant. @package sqlite-easy @version 1.0.1.0 -- | The implementation of sqlite-easy. -- -- This module is unstable and may change at any time. module Database.Sqlite.Easy.Internal -- | A SQLite3 connection string newtype ConnectionString ConnectionString :: Text -> ConnectionString [unConnectionString] :: ConnectionString -> Text -- | Create a pool of a sqlite3 db with a specific connection string. createSqlitePool :: ConnectionString -> IO (Pool Database) -- | Open a database, run some stuff, close the database. withDb :: ConnectionString -> SQLite a -> IO a -- | Use an active database connection to run some stuff on a database. withDatabase :: Database -> SQLite a -> IO a -- | Use a resource pool to run some stuff on a database. withPool :: Pool Database -> SQLite a -> IO a -- | A SQL statement newtype SQL SQL :: Text -> SQL [unSQL] :: SQL -> Text -- | Run a SQL statement on a database and fetch the results. run :: SQL -> SQLite [[SQLData]] -- | Run a SQL statement with certain parameters on a database and fetch -- the results. runWith :: SQL -> [SQLData] -> SQLite [[SQLData]] -- | Run a statement and fetch all of the data. fetchAll :: Statement -> IO [[SQLData]] -- | The type of actions to run on a SQLite database. In essence, it is -- almost the same as Database -> IO a. -- -- SQLite actions can be created with the run and -- runWith functions, and can be composed using the type class -- instances. -- -- SQLite actions can be run with the withDb, -- withDatabase, and withPool functions. newtype SQLite a SQLite :: (SQLiteStuff -> IO a) -> SQLite a [unSQLite] :: SQLite a -> SQLiteStuff -> IO a data SQLiteStuff SQLiteStuff :: Database -> Maybe Int -> SQLiteStuff [dbConn] :: SQLiteStuff -> Database [transactionNumber] :: SQLiteStuff -> Maybe Int getDB :: SQLite Database runSQLite :: Database -> SQLite a -> IO a -- | Run operations as a transaction. If the action throws an error, the -- transaction is rolled back. For more information, visit: -- https://www.sqlite.org/lang_transaction.html transaction :: Typeable a => SQLite a -> SQLite a asTransaction' :: Database -> IO a -> IO a -- | Rollback the current (inner-most) transaction by supplying the return -- value. To be used inside transactions. rollback :: Typeable a => a -> SQLite a -- | Rollback all transaction structure by supplying the return value. To -- be used inside transactions. rollbackAll :: Typeable a => a -> SQLite a data RollbackCurrent a RollbackCurrent :: a -> RollbackCurrent a data RollbackAll a RollbackAll :: a -> RollbackAll a instance GHC.Base.Applicative Database.Sqlite.Easy.Internal.SQLite instance Data.Typeable.Internal.Typeable a => GHC.Exception.Type.Exception (Database.Sqlite.Easy.Internal.RollbackAll a) instance Data.Typeable.Internal.Typeable a => GHC.Exception.Type.Exception (Database.Sqlite.Easy.Internal.RollbackCurrent a) instance GHC.Base.Functor Database.Sqlite.Easy.Internal.SQLite instance Data.String.IsString Database.Sqlite.Easy.Internal.ConnectionString instance Data.String.IsString Database.Sqlite.Easy.Internal.SQL instance Control.Monad.Fail.MonadFail Database.Sqlite.Easy.Internal.SQLite instance Control.Monad.IO.Class.MonadIO Database.Sqlite.Easy.Internal.SQLite instance GHC.Base.Monad Database.Sqlite.Easy.Internal.SQLite instance Control.Monad.IO.Unlift.MonadUnliftIO Database.Sqlite.Easy.Internal.SQLite instance GHC.Base.Monoid a => GHC.Base.Monoid (Database.Sqlite.Easy.Internal.SQLite a) instance GHC.Base.Semigroup Database.Sqlite.Easy.Internal.SQL instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Database.Sqlite.Easy.Internal.SQLite a) instance GHC.Show.Show Database.Sqlite.Easy.Internal.ConnectionString instance GHC.Show.Show (Database.Sqlite.Easy.Internal.RollbackAll a) instance GHC.Show.Show (Database.Sqlite.Easy.Internal.RollbackCurrent a) instance GHC.Show.Show Database.Sqlite.Easy.Internal.SQL -- | Migrations support based on migrant-core. module Database.Sqlite.Easy.Migrant -- | Execute a migration against the database. A wrapper around migrant's -- migrate for SQLite. migrate :: [MigrationName] -> (MigrationName -> SQLite ()) -> (MigrationName -> SQLite ()) -> SQLite () instance Database.Migrant.Driver.Class.Driver Database.SQLite3.Direct.Database -- | Easy to use interface for SQLite3 using the direct-sqlite -- library. -- -- This can be useful for your toy, hobby projects. module Database.Sqlite.Easy -- | Open a database, run some stuff, close the database. withDb :: ConnectionString -> SQLite a -> IO a -- | Use an active database connection to run some stuff on a database. withDatabase :: Database -> SQLite a -> IO a -- | A SQLite3 connection string newtype ConnectionString ConnectionString :: Text -> ConnectionString [unConnectionString] :: ConnectionString -> Text data Database -- | Striped resource pool based on Control.Concurrent.QSem. data Pool a -- | Create a pool of a sqlite3 db with a specific connection string. createSqlitePool :: ConnectionString -> IO (Pool Database) -- | Use a resource pool to run some stuff on a database. withPool :: Pool Database -> SQLite a -> IO a -- | Take a resource from the pool, perform an action with it and return it -- to the pool afterwards. -- -- -- -- If the action throws an exception of any type, the resource is -- destroyed and not returned to the pool. -- -- It probably goes without saying that you should never manually destroy -- a pooled resource, as doing so will almost certainly cause a -- subsequent user (who expects the resource to be valid) to throw an -- exception. withResource :: Pool a -> (a -> IO r) -> IO r -- | Destroy all resources in all stripes in the pool. -- -- Note that this will ignore any exceptions in the destroy function. -- -- This function is useful when you detect that all resources in the pool -- are broken. For example after a database has been restarted all -- connections opened before the restart will be broken. In that case -- it's better to close those connections so that takeResource -- won't take a broken connection from the pool but will open a new -- connection instead. -- -- Another use-case for this function is that when you know you are done -- with the pool you can destroy all idle resources immediately instead -- of waiting on the garbage collector to destroy them, thus freeing up -- those resources sooner. destroyAllResources :: Pool a -> IO () -- | Run a SQL statement on a database and fetch the results. run :: SQL -> SQLite [[SQLData]] -- | Run a SQL statement with certain parameters on a database and fetch -- the results. runWith :: SQL -> [SQLData] -> SQLite [[SQLData]] -- | The type of actions to run on a SQLite database. In essence, it is -- almost the same as Database -> IO a. -- -- SQLite actions can be created with the run and -- runWith functions, and can be composed using the type class -- instances. -- -- SQLite actions can be run with the withDb, -- withDatabase, and withPool functions. data SQLite a -- | Lift a computation from the IO monad. This allows us to run IO -- computations in any monadic stack, so long as it supports these kinds -- of operations (i.e. IO is the base monad for the stack). -- --

Example

-- --
--   import Control.Monad.Trans.State -- from the "transformers" library
--   
--   printState :: Show s => StateT s IO ()
--   printState = do
--     state <- get
--     liftIO $ print state
--   
-- -- Had we omitted liftIO, we would have ended up with -- this error: -- --
--   • Couldn't match type ‘IO’ with ‘StateT s IO’
--    Expected type: StateT s IO ()
--      Actual type: IO ()
--   
-- -- The important part here is the mismatch between StateT s IO -- () and IO (). -- -- Luckily, we know of a function that takes an IO a and -- returns an (m a): liftIO, enabling us to run -- the program and see the expected results: -- --
--   > evalStateT printState "hello"
--   "hello"
--   
--   > evalStateT printState 3
--   3
--   
liftIO :: MonadIO m => IO a -> m a fromString :: IsString a => String -> a -- | A SQL statement data SQL data SQLData SQLInteger :: !Int64 -> SQLData SQLFloat :: !Double -> SQLData SQLText :: !Text -> SQLData SQLBlob :: !ByteString -> SQLData SQLNull :: SQLData -- | Exception thrown when SQLite3 reports an error. -- -- direct-sqlite may throw other types of exceptions if you misuse the -- API. data SQLError SQLError :: !Error -> Text -> Text -> SQLError -- | Error code returned by API call [sqlError] :: SQLError -> !Error -- | Text describing the error [sqlErrorDetails] :: SQLError -> Text -- | Indicates what action produced this error, e.g. exec "SELECT * -- FROM foo" [sqlErrorContext] :: SQLError -> Text -- | https://www.sqlite.org/c3ref/c_blob.html data ColumnType IntegerColumn :: ColumnType FloatColumn :: ColumnType TextColumn :: ColumnType BlobColumn :: ColumnType NullColumn :: ColumnType -- | Run operations as a transaction. If the action throws an error, the -- transaction is rolled back. For more information, visit: -- https://www.sqlite.org/lang_transaction.html transaction :: Typeable a => SQLite a -> SQLite a -- | Rollback the current (inner-most) transaction by supplying the return -- value. To be used inside transactions. rollback :: Typeable a => a -> SQLite a -- | Rollback all transaction structure by supplying the return value. To -- be used inside transactions. rollbackAll :: Typeable a => a -> SQLite a data MigrationName data MigrationDirection -- | Create a migration plan based on the current situation on the -- database, and the specified target. plan :: Driver d => [MigrationName] -> d -> IO [(MigrationDirection, MigrationName)] -- | void value discards or ignores the result of -- evaluation, such as the return value of an IO action. -- --

Examples

-- -- Replace the contents of a Maybe Int with unit: -- --
--   >>> void Nothing
--   Nothing
--   
--   >>> void (Just 3)
--   Just ()
--   
-- -- Replace the contents of an Either Int -- Int with unit, resulting in an Either -- Int (): -- --
--   >>> void (Left 8675309)
--   Left 8675309
--   
--   >>> void (Right 8675309)
--   Right ()
--   
-- -- Replace every element of a list with unit: -- --
--   >>> void [1,2,3]
--   [(),(),()]
--   
-- -- Replace the second element of a pair with unit: -- --
--   >>> void (1,2)
--   (1,())
--   
-- -- Discard the result of an IO action: -- --
--   >>> mapM print [1,2]
--   1
--   2
--   [(),()]
--   
--   >>> void $ mapM print [1,2]
--   1
--   2
--   
void :: Functor f => f a -> f () -- | 64-bit signed integer type data Int64 -- | A space efficient, packed, unboxed Unicode text type. data Text -- | A space-efficient representation of a Word8 vector, supporting -- many efficient operations. -- -- A ByteString contains 8-bit bytes, or by using the operations -- from Data.ByteString.Char8 it can be interpreted as containing -- 8-bit characters. data ByteString