Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
This module exports components from Cassandra's Database.CQL.IO, adding a few functions we find useful, that are built on top of it.
Synopsis
- params :: Consistency -> a -> QueryParams a
- paramsP :: Consistency -> a -> Int32 -> QueryParams a
- x5 :: RetrySettings
- x1 :: RetrySettings
- paginateC :: (Tuple a, Tuple b, RunQ q, MonadClient m) => q R a b -> QueryParams a -> RetrySettings -> ConduitM () [b] m ()
- data PageWithState a = PageWithState {
- pwsResults :: [a]
- pwsState :: Maybe PagingState
- paginateWithState :: (MonadClient m, Tuple a, Tuple b, RunQ q) => q R a b -> QueryParams a -> m (PageWithState b)
- paginateWithStateC :: forall m a. Monad m => (Maybe PagingState -> m (PageWithState a)) -> ConduitT () [a] m ()
- paramsPagingState :: Consistency -> a -> Int32 -> Maybe PagingState -> QueryParams a
- pwsHasMore :: PageWithState a -> Bool
- data Row
- data PrepQuery k a b
- data ClientState
- class (MonadIO m, MonadThrow m) => MonadClient (m :: Type -> Type) where
- liftClient :: Client a -> m a
- localState :: (ClientState -> ClientState) -> m a -> m a
- data Client a
- data BatchM a
- data Page a = Page {}
- retry :: MonadClient m => RetrySettings -> m a -> m a
- write :: (MonadClient m, Tuple a, RunQ q) => q W a () -> QueryParams a -> m ()
- shutdown :: MonadIO m => ClientState -> m ()
- init :: MonadIO m => Settings -> m ClientState
- trans :: (MonadClient m, Tuple a, RunQ q) => q W a Row -> QueryParams a -> m [Row]
- prepared :: QueryString k a b -> PrepQuery k a b
- queryString :: PrepQuery k a b -> QueryString k a b
- adjustConsistency :: Consistency -> RetrySettings -> RetrySettings
- adjustSendTimeout :: NominalDiffTime -> RetrySettings -> RetrySettings
- adjustResponseTimeout :: NominalDiffTime -> RetrySettings -> RetrySettings
- runClient :: MonadIO m => ClientState -> Client a -> m a
- addQuery :: (Show a, Tuple a, Tuple b) => QueryString W a b -> a -> BatchM ()
- addPrepQuery :: (Show a, Tuple a, Tuple b) => PrepQuery W a b -> a -> BatchM ()
- setType :: BatchType -> BatchM ()
- setConsistency :: Consistency -> BatchM ()
- setSerialConsistency :: SerialConsistency -> BatchM ()
- query :: (MonadClient m, Tuple a, Tuple b, RunQ q) => q R a b -> QueryParams a -> m [b]
- query1 :: (MonadClient m, Tuple a, Tuple b, RunQ q) => q R a b -> QueryParams a -> m (Maybe b)
- schema :: (MonadClient m, Tuple a, RunQ q) => q S a () -> QueryParams a -> m (Maybe SchemaChange)
- batch :: MonadClient m => BatchM () -> m ()
- emptyPage :: Page a
- paginate :: (MonadClient m, Tuple a, Tuple b, RunQ q) => q R a b -> QueryParams a -> m (Page b)
Documentation
params :: Consistency -> a -> QueryParams a Source #
paramsP :: Consistency -> a -> Int32 -> QueryParams a Source #
x5 :: RetrySettings Source #
x5
must only be used for idempotent queries, or for cases
when a duplicate write has no severe consequences in
the context of the application's data model.
For more info see e.g.
https://docs.datastax.com/en/developer/java-driver//3.6/manual/idempotence/
The eager retry policy permits 5 retries with exponential backoff (base-2) with an initial delay of 100ms, i.e. the retries will be performed with 100ms, 200ms, 400ms, 800ms and 1.6s delay, respectively, for a maximum delay of ~3s.
x1 :: RetrySettings Source #
Single, immediate retry, always safe.
The defRetryHandlers
used are safe also with non-idempotent queries.
paginateC :: (Tuple a, Tuple b, RunQ q, MonadClient m) => q R a b -> QueryParams a -> RetrySettings -> ConduitM () [b] m () Source #
Stream results of a query.
You can execute this conduit by doing transPipe (runClient ...)
.
data PageWithState a Source #
PageWithState | |
|
Instances
Functor PageWithState Source # | |
Defined in Cassandra.Exec fmap :: (a -> b) -> PageWithState a -> PageWithState b # (<$) :: a -> PageWithState b -> PageWithState a # |
paginateWithState :: (MonadClient m, Tuple a, Tuple b, RunQ q) => q R a b -> QueryParams a -> m (PageWithState b) Source #
Like paginate
but exposes the paging state. This paging state can be
serialised and sent to consumers of the API. The state is not good for long
term storage as the bytestring format may change when the schema of a table
changes or when cassandra is upgraded.
paginateWithStateC :: forall m a. Monad m => (Maybe PagingState -> m (PageWithState a)) -> ConduitT () [a] m () Source #
Like paginateWithState
but returns a conduit instead of one page.
This can be used with paginateWithState
like this:
main :: IO ()
main = do
runConduit $
paginateWithStateC getUsers
.| mapC doSomethingWithAPageOfUsers
where
getUsers state = paginateWithState getUsersQuery (paramsPagingState Quorum () 10000 state)
paramsPagingState :: Consistency -> a -> Int32 -> Maybe PagingState -> QueryParams a Source #
pwsHasMore :: PageWithState a -> Bool Source #
A row is a vector of Value
s.
Instances
RunQ PrepQuery | |
Defined in Database.CQL.IO runQ :: (MonadClient m, Tuple a, Tuple b) => PrepQuery k a b -> QueryParams a -> m (HostResponse k a b) Source # | |
IsString (PrepQuery k a b) | |
Defined in Database.CQL.IO.PrepQuery fromString :: String -> PrepQuery k a b # |
data ClientState #
Instances
MonadReader ClientState Client | |
Defined in Database.CQL.IO.Client ask :: Client ClientState # local :: (ClientState -> ClientState) -> Client a -> Client a # reader :: (ClientState -> a) -> Client a # |
class (MonadIO m, MonadThrow m) => MonadClient (m :: Type -> Type) where #
liftClient :: Client a -> m a #
localState :: (ClientState -> ClientState) -> m a -> m a #
Instances
MonadClient Client | |
Defined in Database.CQL.IO.Client liftClient :: Client a -> Client a # localState :: (ClientState -> ClientState) -> Client a -> Client a # | |
MonadClient m => MonadClient (ExceptT e m) | |
Defined in Database.CQL.IO.Client liftClient :: Client a -> ExceptT e m a # localState :: (ClientState -> ClientState) -> ExceptT e m a -> ExceptT e m a # | |
MonadClient m => MonadClient (ReaderT r m) | |
Defined in Database.CQL.IO.Client liftClient :: Client a -> ReaderT r m a # localState :: (ClientState -> ClientState) -> ReaderT r m a -> ReaderT r m a # | |
MonadClient m => MonadClient (StateT s m) | |
Defined in Database.CQL.IO.Client liftClient :: Client a -> StateT s m a # localState :: (ClientState -> ClientState) -> StateT s m a -> StateT s m a # | |
MonadClient m => MonadClient (StateT s m) | |
Defined in Database.CQL.IO.Client liftClient :: Client a -> StateT s m a # localState :: (ClientState -> ClientState) -> StateT s m a -> StateT s m a # |
Instances
Return value of paginate
. Contains the actual result values as well
as an indication of whether there is more data available and the actual
action to fetch the next page.
retry :: MonadClient m => RetrySettings -> m a -> m a #
write :: (MonadClient m, Tuple a, RunQ q) => q W a () -> QueryParams a -> m () Source #
Run a CQL write-only query (e.g. insert/update/delete), returning no result.
/Note: If the write operation is conditional, i.e. is in fact a "lightweight
transaction" returning a result, trans
must be used instead./
shutdown :: MonadIO m => ClientState -> m () #
init :: MonadIO m => Settings -> m ClientState #
trans :: (MonadClient m, Tuple a, RunQ q) => q W a Row -> QueryParams a -> m [Row] Source #
Run a CQL conditional write query (e.g. insert/update/delete) as a
"lightweight transaction", returning the result Row
s describing the
outcome.
prepared :: QueryString k a b -> PrepQuery k a b #
queryString :: PrepQuery k a b -> QueryString k a b #
runClient :: MonadIO m => ClientState -> Client a -> m a #
setConsistency :: Consistency -> BatchM () #
setSerialConsistency :: SerialConsistency -> BatchM () #
query :: (MonadClient m, Tuple a, Tuple b, RunQ q) => q R a b -> QueryParams a -> m [b] Source #
Run a CQL read-only query returning a list of results.
query1 :: (MonadClient m, Tuple a, Tuple b, RunQ q) => q R a b -> QueryParams a -> m (Maybe b) Source #
Run a CQL read-only query returning a single result.
schema :: (MonadClient m, Tuple a, RunQ q) => q S a () -> QueryParams a -> m (Maybe SchemaChange) Source #
Run a CQL schema query, returning SchemaChange
information, if any.
batch :: MonadClient m => BatchM () -> m () Source #
Run a batch query against a Cassandra node.
paginate :: (MonadClient m, Tuple a, Tuple b, RunQ q) => q R a b -> QueryParams a -> m (Page b) Source #
Run a CQL read-only query against a Cassandra node.
This function is like query
, but limits the result size to 10000
(default) unless there is an explicit size restriction given in
QueryParams
. The returned Page
can be used to continue the query.
Please note that -- as of Cassandra 2.1.0 -- if your requested page size
is equal to the result size, hasMore
might be true and a subsequent
nextPage
will return an empty list in result
.