class NoSE::Delete
A representation of a delete in the workload
Public Class Methods
new(params, text, group: nil, label: nil)
click to toggle source
Calls superclass method
NoSE::Statement::new
# File lib/nose/statements/delete.rb, line 9 def initialize(params, text, group: nil, label: nil) super params, text, group: group, label: label populate_conditions params end
parse(tree, params, text, group: nil, label: nil)
click to toggle source
Build a new delete from a provided parse tree @return [Delete]
# File lib/nose/statements/delete.rb, line 17 def self.parse(tree, params, text, group: nil, label: nil) conditions_from_tree tree, params Delete.new params, text, group: group, label: label end
Public Instance Methods
==(other)
click to toggle source
# File lib/nose/statements/delete.rb, line 33 def ==(other) other.is_a?(Delete) && @graph == other.graph && entity == other.entity && @conditions == other.conditions end
Also aliased as: eql?
given_fields()
click to toggle source
The condition fields are provided with the deletion
# File lib/nose/statements/delete.rb, line 79 def given_fields @conditions.each_value.map(&:field) end
hash()
click to toggle source
# File lib/nose/statements/delete.rb, line 41 def hash @hash ||= [@graph, entity, @conditions].hash end
modifies_index?(index)
click to toggle source
Index
contains the entity to be deleted
# File lib/nose/statements/delete.rb, line 46 def modifies_index?(index) index.graph.entities.include? entity end
requires_delete?(_index)
click to toggle source
Specifies that deletes require deletion
# File lib/nose/statements/delete.rb, line 51 def requires_delete?(_index) true end
support_queries(index)
click to toggle source
Get the support queries for deleting from an index
# File lib/nose/statements/delete.rb, line 56 def support_queries(index) return [] unless modifies_index? index select = (index.hash_fields + index.order_fields.to_set) - @conditions.each_value.map(&:field).to_set return [] if select.empty? support_queries = [] # Build a support query which gets the IDs of the entities being deleted graph = @graph.dup support_fields = select.select do |field| field.parent == entity end.to_set support_fields << entity.id_field \ unless @conditions.each_value.map(&:field).include? entity.id_field conditions = Hash[@conditions.map { |k, v| [k.dup, v.dup] }] support_queries << build_support_query(entity, index, graph, support_fields, conditions) support_queries.compact + support_queries_for_entity(index, select) end
unparse()
click to toggle source
Produce the SQL text corresponding to this delete @return [String]
# File lib/nose/statements/delete.rb, line 25 def unparse delete = "DELETE #{entity.name} " delete += "FROM #{from_path @key_path}" delete << where_clause delete end