Class: Neo4j::Core::QueryClauses::WhereClause

Inherits:
Clause
  • Object
show all
Defined in:
lib/neo4j-core/query_clauses.rb

Constant Summary collapse

KEYWORD =
'WHERE'
ARG_HAS_QUESTION_MARK_REGEX =
/(^|\s)\?(\s|$)/

Constants inherited from Clause

Clause::AND, Clause::COMMA_SPACE, Clause::UNDERSCORE

Constants included from CypherTranslator

CypherTranslator::EMPTY_PROPS, CypherTranslator::SANITIZE_ESCAPED_REGEXP

Instance Attribute Summary

Attributes inherited from Clause

#arg, #params

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Clause

#_nested_value_hash?, #_use_key_for_var?, #attributes_from_key_and_value, from_arg, #from_hash, #from_string, #initialize, keyword, keyword_downcase, #label_from_key_and_value, #node_from_key_and_value, to_cypher, #value, #var_from_key_and_value

Methods included from CypherTranslator

#create_escape_value, #cypher_prop_list!, #cypher_string, #escape_quotes, #escape_value, #label_string, #prop_identifier, #sanitize_escape_sequences, sanitized_column_names, translate_response

Constructor Details

This class inherits a constructor from Neo4j::Core::QueryClauses::Clause

Class Method Details

.clause_string(clauses) ⇒ Object



248
249
250
# File 'lib/neo4j-core/query_clauses.rb', line 248

def clause_string(clauses)
  clauses.map!(&:value).tap(&:flatten!).map! { |value| "(#{value})" }.join(Clause::AND)
end

.from_args(args, options = {}) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/neo4j-core/query_clauses.rb', line 274

def from_args(args, options = {})
  query_string, params = args

  if query_string.is_a?(String) && (query_string.match(ARG_HAS_QUESTION_MARK_REGEX) || params.is_a?(Hash))
    if !params.is_a?(Hash)
      question_mark_params_param = self.question_mark_params_param
      query_string.gsub!(ARG_HAS_QUESTION_MARK_REGEX, "\\1{#{question_mark_params_param}}\\2")
      params = {question_mark_params_param.to_sym => params}
    end

    clause = from_arg(query_string, options).tap do |clause|
      clause.params.merge!(params)
    end

    [clause]
  else
    super
  end
end

.question_mark_params_paramObject



294
295
296
297
298
# File 'lib/neo4j-core/query_clauses.rb', line 294

def question_mark_params_param
  result = "question_mark_param#{@question_mark_param_index}"
  @question_mark_param_index += 1
  result
end

Instance Method Details

#from_key_and_value(key, value, previous_keys = []) ⇒ Object



236
237
238
239
240
241
242
243
244
245
# File 'lib/neo4j-core/query_clauses.rb', line 236

def from_key_and_value(key, value, previous_keys = [])
  case value
  when Hash then hash_key_value_string(key, value, previous_keys)
  when NilClass then "#{key} IS NULL"
  when Regexp then regexp_key_value_string(key, value)
  when Array, Range then key_value_string(key, value, previous_keys)
  else
    key_value_string(key, value, previous_keys)
  end
end