Sessions are used for query execution. Each session tracks its current keyspace. A session should be reused as much as possible, however it is ok to create several independent session for interacting with different keyspaces in the same application.
Inherits
ObjectExtends
Forwardable
Methods
Executes a given statement and returns a future result
- Note
- Positional arguments for simple statements are only supported on starting with Apache Cassandra 2.0 and above.
- Overloads:
-
execute_async(statement, *args, options = nil)
Executes a statement using the deprecated splat-style way of passing positional arguments/
- Deprecated
- This style will soon be removed, use the
:argumentsoption to provide positional arguments instead. - Note
- Last argument will be treated as
optionsif it is aHash. Therefore, make sure to pass emptyoptionswhen executing a statement with the last parameter required to be a map datatype.
- Parameters:
-
Name Type Details statement ( String,Statements::Simple,Statements::BoundorStatements::Prepared)statement to execute args * Objectthis style of positional arguments is deprecated, please use the :argumentsoptions instead - positional arguments to paramterized query or prepared statement.options ( nilorHash)(defaults to: nil) a customizable set of options
- Parameters:
-
Name Type Details statement ( String,Statements::Simple,Statements::BoundorStatements::Prepared)statement to execute options ( nilorHash)(defaults to: nil) a customizable set of options - Keys for options:
-
Key Type Details :consistency Symbolconsistency level for the request. Must be one of CONSISTENCIES:page_size Integersize of results page. You can page through results using Result#next_pageorResult#next_page_async:trace Booleandefault: falsewhether to enable request tracing:timeout Numericdefault: nilif specified, it is a number of seconds after which to time out the request if it hasn’t completed:serial_consistency Symboldefault: nilthis option is only relevant for conditional updates and specifies a serial consistency to be used, one ofSERIAL_CONSISTENCIES:paging_state Stringdefault: nilthis option is used for stateless paging, where result paging is resumed some time after the initial request.:arguments Arraydefault: nilpositional arguments for the statement. - Returns:
-
Type Details Future<Result> - See Also:
A blocking wrapper around #execute_async
- Overloads:
-
execute(statement, *args, options = nil)
Executes a statement using the deprecated splat-style way of passing positional arguments/
- Deprecated
- This style will soon be removed, use the
:argumentsoption to provide positional arguments instead. - Note
- Last argument will be treated as
optionsif it is aHash. Therefore, make sure to pass emptyoptionswhen executing a statement with the last parameter required to be a map datatype.
- Parameters:
-
Name Type Details statement ( String,Statements::Simple,Statements::BoundorStatements::Prepared)statement to execute args * Objectthis style of positional arguments is deprecated, please use the :argumentsoptions instead - positional arguments to paramterized query or prepared statement.options ( nilorHash)(defaults to: nil) a customizable set of options
- Parameters:
-
Name Type Details statement ( String,Statements::Simple,Statements::BoundorStatements::Prepared)statement to execute options ( nilorHash)(defaults to: nil) a customizable set of options - Returns:
-
Type Details Resultquery result - Raises:
-
Type Details Errors::NoHostsAvailableif all hosts fail Errors::ExecutionErrorif Cassandra fails to execute Errors::ValidationErrorif Cassandra fails to validate Errors::TimeoutErrorif request has not completed within the :timeoutgiven - See Also:
Prepares a given statement and returns a future prepared statement
- Parameters:
-
Name Type Details statement ( StringorStatements::Simple)a statement to prepare options Hash(defaults to: nil) a customizable set of options - Keys for options:
-
Key Type Details :trace Booleandefault: falsewhether to enable request tracing:timeout Numericdefault: nilif specified, it is a number of seconds after which to time out the request if it hasn’t completed - Returns:
-
Type Details Future<Statements::Prepared>future prepared statement
A blocking wrapper around #prepare_async
- Returns:
-
Type Details Statements::Preparedprepared statement - Raises:
-
Type Details Errors::NoHostsAvailableif none of the hosts can be reached Errors::ExecutionErrorif Cassandra returns an error response - See Also:
- Specifications:
-
-
Session#prepareresolves a promise returned by #prepare_async expect(session).to receive(:prepare_async).with(*args).and_return(promise) expect(promise).to receive(:get).once session.prepare(*args)
-
Returns a logged Statements::Batch instance and optionally yields it to
a given block
- Yield Parameters:
-
Name Type Details batch Statements::Batcha logged batch - Returns:
-
Type Details Statements::Batcha logged batch
Returns a unlogged Statements::Batch instance and optionally yields it
to a given block
- Yield Parameters:
-
Name Type Details batch Statements::Batchan unlogged batch - Returns:
-
Type Details Statements::Batchan unlogged batch - Specifications:
-
-
Session#unlogged_batchcreates an unlogged batch batch = double('batch') expect(Statements::Batch::Unlogged).to receive(:new).once.and_return(batch) expect(session.unlogged_batch).to eq(batch)
-
Returns a counter Statements::Batch instance and optionally yields it
to a given block
- Yield Parameters:
-
Name Type Details batch Statements::Batcha counter batch - Returns:
-
Type Details Statements::Batcha counter batch - Specifications:
-
-
Session#counter_batchcreates a counter batch batch = double('batch') expect(Statements::Batch::Counter).to receive(:new).once.and_return(batch) expect(session.counter_batch).to eq(batch)
-
Asynchronously closes current session
- Returns:
-
Type Details Future<Session>a future that resolves to self once closed - Specifications:
-
-
Session#close_asyncuses Client#close expect(client).to receive(:close).and_return(Ione::Future.resolved) expect(session.close_async).to eq(promise) expect(promise).to have_received(:fulfill).once.with(session)
-
Synchronously closes current session
- Returns:
-
Type Details selfthis session - See Also:
- Specifications:
-
-
Session#closeresolves a promise returned by #close_async expect(session).to receive(:close_async).with(no_args).and_return(promise) expect(promise).to receive(:get).once.and_return('success') expect(session.close).to eq('success')
-