Class: NoSE::Statement

Inherits:
Object show all
Defined in:
lib/nose/indexes.rb,
lib/nose/statements.rb

Overview

A CQL statement and its associated data

Direct Known Subclasses

Connection, Delete, Insert, Query, Update

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, text, group: nil, label: nil) ⇒ Statement

Returns a new instance of Statement.



399
400
401
402
403
404
405
406
407
408
# File 'lib/nose/statements.rb', line 399

def initialize(params, text, group: nil, label: nil)
  @entity = params[:entity]
  @key_path = params[:key_path]
  @longest_entity_path = @key_path.entities
  @graph = params[:graph]
  @model = params[:model]
  @text = text
  @group = group
  @label = label
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



276
277
278
# File 'lib/nose/statements.rb', line 276

def comment
  @comment
end

#entityObject (readonly)

Returns the value of attribute entity.



276
277
278
# File 'lib/nose/statements.rb', line 276

def entity
  @entity
end

#eq_fieldsObject (readonly)

Returns the value of attribute eq_fields.



276
277
278
# File 'lib/nose/statements.rb', line 276

def eq_fields
  @eq_fields
end

#graphObject (readonly)

Returns the value of attribute graph.



276
277
278
# File 'lib/nose/statements.rb', line 276

def graph
  @graph
end

#groupObject (readonly)

Returns the value of attribute group.



276
277
278
# File 'lib/nose/statements.rb', line 276

def group
  @group
end

#key_pathObject (readonly)

Returns the value of attribute key_path.



276
277
278
# File 'lib/nose/statements.rb', line 276

def key_path
  @key_path
end

#labelObject (readonly)

Returns the value of attribute label.



276
277
278
# File 'lib/nose/statements.rb', line 276

def label
  @label
end

#range_fieldObject (readonly)

Returns the value of attribute range_field.



276
277
278
# File 'lib/nose/statements.rb', line 276

def range_field
  @range_field
end

#textObject (readonly)

Returns the value of attribute text.



276
277
278
# File 'lib/nose/statements.rb', line 276

def text
  @text
end

Class Method Details

.parse(text, model, group: nil, label: nil, support: false) ⇒ Object

Parse either a query or an update



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/nose/statements.rb', line 280

def self.parse(text, model, group: nil, label: nil, support: false)
  klass = statement_class text, support
  tree = parse_tree text, klass

  # Ensure we have a valid path in the parse tree
  tree[:path] ||= [tree[:entity]]
  fail InvalidStatementException,
       "FROM clause must start with #{tree[:entity]}" \
       if tree[:entity] && tree[:path].first != tree[:entity]

  params = statement_parameters tree, model
  statement = klass.parse tree, params, text, group: group, label: label
  statement.instance_variable_set :@comment, tree[:comment].to_s

  # Support queries need to populate extra values before finalizing
  unless support
    statement.hash
    statement.freeze
  end

  statement
end

Instance Method Details

#materialize_viewIndex

Construct an index which acts as a materialized view for a query

Returns:



201
202
203
204
205
206
207
# File 'lib/nose/indexes.rb', line 201

def materialize_view
  eq = materialized_view_eq join_order.first
  order_fields = materialized_view_order(join_order.first) - eq

  Index.new(eq, order_fields,
            all_fields - (@eq_fields + @order).to_set, @graph)
end

#read_only?Boolean

Specifies if the statement modifies any data

Returns:

  • (Boolean)


412
413
414
# File 'lib/nose/statements.rb', line 412

def read_only?
  false
end

#requires_delete?(_index) ⇒ Boolean

Specifies if the statement will require data to be deleted

Returns:

  • (Boolean)


424
425
426
# File 'lib/nose/statements.rb', line 424

def requires_delete?(_index)
  false
end

#requires_insert?(_index) ⇒ Boolean

Specifies if the statement will require data to be inserted

Returns:

  • (Boolean)


418
419
420
# File 'lib/nose/statements.rb', line 418

def requires_insert?(_index)
  false
end

#to_colorObject

:nocov:



429
430
431
# File 'lib/nose/statements.rb', line 429

def to_color
  "#{@text} [magenta]#{@longest_entity_path.map(&:name).join ', '}[/]"
end