Class: Cassie::Query

Inherits:
Object show all
Extended by:
Connection::ClassMethods, Statements::Core::ClassMethods, Statements::Query::ClassMethods
Includes:
Connection, Statements::Core, Statements::Query
Defined in:
lib/cassie/query.rb

Overview

A concrete implementation of a functional base class used to make CQL SELECT queries. Inherit from this class to create application query classes.

See the README for information on usage and examples.

Examples:

Selecting a record from a Table

class UsersByUsernameQuery < Cassie::Query

  select_from :users_by_username

  where :username, :eq

  def build_result(row)
    User.new(row)
  end
end

user = UsersByUsernameQuery.new(username: 'eprothro').fetch_first
#=> #<User:0x007fedec219cd8 @id=123, @username="eprothro">

Direct Known Subclasses

FakeQuery, Schema::SelectVersionsQuery

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cqlObject (readonly) Originally defined in module Statements::Statement

The CQL string portion for the statment

Examples:

statement.cql
#=> "SELECT * FROM table WHERE first=? AND middle=? and last=?"

#paramsObject (readonly) Originally defined in module Statements::Statement

The positional values portion for the statment

Examples:

statement.params
#=> ['evan', 'thomas', 'prothro']

#result_classObject Originally defined in module Statements::Execution::ClassMethods

The class to use for decorating the Cassandra::Result

Class Method Details

.keyspace(val = NilClass) ⇒ Object Originally defined in module Connection::ClassMethods

.keyspace=(val) ⇒ Object Originally defined in module Connection::ClassMethods

Instance Method Details

#build_partition_linkerObject Originally defined in module Statements::Execution::PartitionLinking

#consistencyObject Originally defined in module Statements::Execution::Consistency

#executeBoolean Originally defined in module Statements::Execution

Executes the statment and populates result

Returns:

  • (Boolean)

    indicating a successful execution or not

#execute!Boolean Originally defined in module Statements::Execution

Same as #execute. Raises if not succesfull.

Returns:

  • (Boolean)

    true if sucessful

Raises:

#execution_optionsHash{Symbol => Object} Originally defined in module Statements::Execution

The session exection options configured for statement execution

Returns:

#idempotent(val = :get) ⇒ Boolean Originally defined in module Statements::Statement::Idempotency::ClassMethods

DSL to set a statement as idempotent

Parameters:

  • val (Boolean) (defaults to: :get)

    The value to set for idempotency. Returns the current value if no parameter is given.

Returns:

  • (Boolean)

    idempotent value

#idempotent=(val) ⇒ Object Originally defined in module Statements::Statement::Idempotency::ClassMethods

#idempotent?Boolean Originally defined in module Statements::Statement::Idempotency::ClassMethods

Indicates where the statement has no negative side-effect if issued multiple times.

Returns:

#inherited(subclass) ⇒ Object Originally defined in module Statements::Execution::ClassMethods

#initialize(params = {}) ⇒ Object Originally defined in module Statements::Core

Create a new statement-based object, sending all options passed as a hash to attribute setters Similar to ActiveModel::Model initialization

#keyspaceObject Originally defined in module Connection

#loggerObject Originally defined in module Statements::Statement

#non_idempotentBoolean Originally defined in module Statements::Statement::Idempotency::ClassMethods

DSL to set a satement as non-idempotent

Returns:

  • (Boolean)

    false

#partition_linker?Boolean Originally defined in module Statements::Execution::PartitionLinking

Returns:

  • (Boolean)

#sessionObject Originally defined in module Connection

#statementCassandra::Statement Originally defined in module Statements::Statement

A bound statment with type hint and idempotent options, ready for execution ready for execution with a [Cassandra::Session]

Returns:

  • (Cassandra::Statement)

#tableObject Originally defined in module Statements::Statement

#to_cqlString Originally defined in module Statements::Statement

Note:

This CQL string does not include execution options like type hinting, idempotency, consistency level, etc – just the raw CQL instruction and values.

A CQL string with inline parameters, representing the current statement as it would be executed in a CQL shell

Examples:

statement.to_cql
#=> "SELECT * FROM table WHERE first='evan' AND middle='thomas' and last='prothro"

Returns:

  • (String)

#type_hints(hints = :get) ⇒ Array, Hash Originally defined in module Statements::Statement::TypeHinting::ClassMethods

DSL to set the type hints execution option Defaults to nil if none are set

Parameters:

  • hints (Array, Hash) (defaults to: :get)

    Hints to use for value serialization. Array for positional arguments, Hash for named arguments.

Returns:

  • (Array, Hash)

    hints to use for value serialization. Array for positional arguments, Hash for named arguments.

#type_hints=(val) ⇒ Object Originally defined in module Statements::Statement::TypeHinting::ClassMethods