Skip to content

Commit

Permalink
Attempting to remove CypherTranslator
Browse files Browse the repository at this point in the history
  • Loading branch information
cheerfulstoic committed Aug 6, 2015
1 parent abcf8aa commit 3924f9f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 66 deletions.
35 changes: 35 additions & 0 deletions lib/neo4j-core/graph_json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Neo4j
module Core
module GraphJSON
def self.to_graph_json(objects)
nodes = {}
edges = {}

objects.each do |object|
case object
when Neo4j::ActiveNode, Neo4j::Server::CypherNode
nodes[object.neo_id] = {
id: object.neo_id,
labels: (object.is_a?(Neo4j::ActiveNode) ? [object.class.name] : object.labels),
properties: object.attributes
}
when Neo4j::ActiveRel, Neo4j::Server::CypherRelationship
edges[[object.start_node.neo_id, object.end_node.neo_id]] = {
source: object.start_node.neo_id,
target: object.end_node.neo_id,
type: object.rel_type,
properties: object.props
}
else
fail "Invalid value found: #{object.inspect}"
end
end

{
nodes: nodes.values,
edges: edges.values
}.to_json
end
end
end
end
1 change: 0 additions & 1 deletion lib/neo4j-core/query_clauses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def initialize(arg_part = nil)


class Clause
include CypherTranslator
UNDERSCORE = '_'
COMMA_SPACE = ', '
AND = ' AND '
Expand Down
1 change: 0 additions & 1 deletion lib/neo4j-server/cypher_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Neo4j
module Server
class CypherNode < Neo4j::Node
include Neo4j::Server::Resource
include Neo4j::Core::CypherTranslator
include Neo4j::Core::ActiveEntity

def initialize(session, value)
Expand Down
14 changes: 10 additions & 4 deletions lib/neo4j-server/cypher_relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Neo4j
module Server
class CypherRelationship < Neo4j::Relationship
include Neo4j::Server::Resource
include Neo4j::Core::CypherTranslator
include Neo4j::Core::ActiveEntity

def initialize(session, value)
Expand Down Expand Up @@ -93,10 +92,17 @@ def props=(properties)
# (see Neo4j::Relationship#update_props)
def update_props(properties)
return if properties.empty?
q = "#{match_start} SET " + properties.keys.map do |k|
"n.`#{k}`= #{escape_value(properties[k])}"

params = {}
q = "#{match_start} SET " + properties.keys.each_with_index.map do |k, i|
param = k.to_s.tr_s('^a-zA-Z0-9', '_').gsub(/^_+|_+$/, '')
params[param] = properties[k]

"n.`#{k}`= {#{param}}"
end.join(',')
@session._query_or_fail(q, false, neo_id: neo_id)

@session._query_or_fail(q, false, params.merge(neo_id: neo_id))

properties
end

Expand Down
7 changes: 5 additions & 2 deletions lib/neo4j-server/cypher_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Server

class CypherSession < Neo4j::Session
include Resource
include Neo4j::Core::CypherTranslator

alias_method :super_query, :query
attr_reader :connection
Expand Down Expand Up @@ -102,7 +101,11 @@ def begin_tx
end

def create_node(props = nil, labels = [])
id = _query_or_fail(cypher_string(labels, props), true, cypher_prop_list!(props))
label_string = labels.empty? ? '' : (":" + labels.map { |k| "`#{k}`" }.join(':'))
prop_identifier = '{props}' unless props.nil?
cypher_string = "CREATE (n#{label_string} #{prop_identifier}) RETURN ID(n)"

id = _query_or_fail(cypher_string, true, props: props)
value = props.nil? ? id : {id: id, metadata: {labels: labels}, data: props}
CypherNode.new(self, value)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j-server/cypher_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Server
# If a transaction is created and then closed without performing any queries, an OpenStruct is returned that behaves like a successfully closed query.
class CypherTransaction
include Neo4j::Transaction::Instance
include Neo4j::Core::CypherTranslator
include Neo4j::Core::CypherTranslator ##!!!!
include Resource

attr_reader :commit_url, :query_url, :base_url, :connection
Expand Down
1 change: 0 additions & 1 deletion lib/neo4j/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def drop_constraint(property, constraint, session = Neo4j::Session.current)
end

class << self
include Neo4j::Core::CypherTranslator
INDEX_PATH = '/db/data/schema/index/'
CONSTRAINT_PATH = '/db/data/schema/constraint/'

Expand Down
56 changes: 0 additions & 56 deletions spec/neo4j-core/unit/cypher_translator_spec.rb

This file was deleted.

0 comments on commit 3924f9f

Please sign in to comment.