-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A minimalistic general high level API for relational databases -- -- A robust and concise yet powerful API for communication with arbitrary -- relational databases using SQL. -- -- Features: -- --
-- bracket (acquirePool bkndStngs poolStngs) (releasePool) $ \pool -> do -- session pool $ do -- ... -- ... any other IO code --acquirePool :: Cx c => CxSettings c -> PoolSettings -> IO (Pool c) -- | Release all connections acquired by the pool. releasePool :: Pool c -> IO () -- | Settings of a pool. data PoolSettings -- | A smart constructor for pool settings. poolSettings :: Int -> Int -> Maybe PoolSettings -- | A convenience wrapper around ReaderT, which provides a shared -- context for execution and error-handling of transactions. data Session c m r -- | Execute a session using an established connection pool. -- -- This is merely a wrapper around runReaderT, so you can run it -- around every transaction, if you want. session :: Pool c -> Session c m a -> m (Either (SessionError c) a) data SessionError c -- | A backend-specific connection acquisition error. E.g., a failure to -- establish a connection. CxError :: (CxError c) -> SessionError c -- | A backend-specific transaction error. It should cover all possible -- failures related to an established connection, including the loss of -- connection, query errors and database failures. TxError :: (TxError c) -> SessionError c -- | Attempt to parse a result into an incompatible type. Indicates either -- a mismatching schema or an incorrect query. ResultError :: Text -> SessionError c -- | A statement template packed with its values and settings. data Stmt c :: * -> * -- | Produces a lambda-expression, which takes as many parameters as there -- are placeholders in the quoted text and results in a Stmt. -- -- E.g.: -- --
-- selectSum :: Int -> Int -> Stmt c -- selectSum = [stmt|SELECT (? + ?)|] ---- -- It also allows to directly refer to free variables like so: -- --
-- selectSum :: Int -> Int -> Stmt c -- selectSum a b = [stmt|SELECT ($a + $b)|] --stmt :: QuasiQuoter -- | Statement executor. -- -- Just an alias to a function, which executes a statement in Tx. type Ex c s r = Stmt c -> Tx c s r -- | Execute a statement without processing the result. unitEx :: Ex c s () -- | Execute a statement and count the amount of affected rows. Useful for -- resolving how many rows were updated or deleted. countEx :: CxValue c Word64 => Ex c s Word64 -- | Execute a statement, which produces exactly one result row. E.g., -- INSERT, which returns an autoincremented identifier, or -- SELECT COUNT, or SELECT EXISTS. -- -- Please note that using this executor for selecting rows is -- conceptually wrong, since in that case the results are always -- optional. Use maybeEx, listEx or vectorEx -- instead. -- -- If the result is empty this executor will raise ResultError. singleEx :: CxRow c r => Ex c s r -- | Execute a statement, which optionally produces a single result row. maybeEx :: CxRow c r => Ex c s (Maybe r) -- | Execute a statement, and produce a list of results. listEx :: CxRow c r => Ex c s [r] -- | Execute a statement, and produce a vector of results. vectorEx :: CxRow c r => Ex c s (Vector r) -- | Given a batch size, execute a statement with a cursor, and produce a -- result stream. -- -- The cursor allows you to fetch virtually limitless results in a -- constant memory at a cost of a small overhead. -- -- The batch size parameter controls how many rows will be fetched during -- every roundtrip to the database. A minimum value of 256 seems to be -- sane. -- -- Note that in most databases cursors require establishing a database -- transaction, so depending on a backend the transaction may result in -- an error, if you run it improperly. streamEx :: CxRow c r => Int -> Ex c s (TxStream c s r) -- | A transaction specialized for a backend connection c, -- associated with its intermediate results using an anonymous -- type-argument s (same trick as in ST) and producing a -- result r. -- -- Running IO in Tx is prohibited. The motivation is -- identical to STM: the Tx block may get executed multiple -- times if any transaction conflicts arise. This will result in your -- effectful IO code being executed an unpredictable amount of -- times as well, which, chances are, is not what you want. data Tx c s r -- | Execute a transaction in a session. -- -- This function ensures on the type level, that it's impossible to -- return TxStreamListT s m r from it. tx :: (CxTx c, MonadBaseControl IO m) => TxMode -> (forall s. Tx c s r) -> Session c m r -- | A mode, defining how a transaction should be executed. -- --