Class: Cassie::Definition

Inherits:
Object show all
Includes:
Connection, Statements::Core
Defined in:
lib/cassie/definition.rb

Overview

A concrete implementation of a functional base class used to make CQL DDL or generic queries without any DSL. Inherit from this class to create application query classes.

  • The Cassandra connection is provided and managed by Connection

  • Generic statement functionality is provided by Statements::Core

  • Defining the statement and options is up the subclass's responsibility (e.g. no DSL is provided)

See the README for information on usage and examples.

Examples:

Inserting a record into a Table

class CreateKeyspaceQuery < Cassie::Definition
  attr_accessor :name

  self.prepare = false

  def statement
    cql = %(
      CREATE KEYSPACE #{name}
      WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}
      AND durable_writes = true;
     )
  end
end

CreateKeyspaceQuery.new(name: "my keyspace").excecute
#=> true

Instance Attribute 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

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

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

Same as #execute. Raises if not succesfull.

Raises:

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

The session exection options configured for statement execution

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

DSL to set a statement as idempotent

#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.

#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

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

#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]

#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"

#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

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