Skip to content

Loading…

Expose Cypher Queries on Traversal Methods and Rules #181

Closed
andreasronge opened this Issue · 0 comments

1 participant

@andreasronge
Neo4jRB member

The result of this issue: https://github.com/andreasronge/neo4j/wiki/Neo4j%3A%3AWrapper-Rules-and-Functions

Declared Traversals and Rules

class Monster < Neo4j::Rails::Model
  rule(:dangerous){|x| x[:strength] > 15}
end

class Dungeon < Neo4j::Rails::Model
  property :level, :type => Fixnum, :index => :exact
  has_n(:monsters).to(Monster)
end

Monster.all.query #=> an Enumeration of all monsters nodes by using Cypher and traversing the 'class node'/rule node
Monster.all.query{|x| x[:age] < 20} => Same as above but adds a where statement

d = Dungeon.find_by_level(2)
d.monsters.query  #=> should use Cypher to return the has_n relationship
d.monsters.dangerous.query  #=> same as above but also use the dangerous rule declared on Monster class.

The d.monster.dangerous method is available on the Traversal/Neo4j::Rails::Relationship::NodeDSL (?), since there is a #to relationship declared to Monster

It's also be possible to use MATCH clauses (or any other cypher construct) in the query method block since the query block is evaluated by the Neo4j::Cypher class.

Notice, by using cypher the traversal will be executed in the Java layer => probably much better performance.

General Purpose Traverals

the outgoing, incoming traversals can be translated to Cypher queries.
Example

  node.outgoing(:foo).query{|x| x[:age] > 42}
  node.outgoing(:foo).query{|x| q = x.outgoing(:bar); x[:thing] == 'something'; q.distinct}

As shown about, it is also allowed to use the outgoing, incoming and both instead of using the <, > <=> operators.
That means that this will work:

  Neo4j.query{ lookup(Person, "name", "kalle").outgoing(Person.friends)[:age] > 42} 

will work.

see also - http://groups.google.com/group/neo4jrb/browse_thread/thread/849d43bf36ea4fe

@andreasronge andreasronge added a commit to neo4jrb/neo4j-core that referenced this issue
@andreasronge andreasronge Started to integrate cypher queries in outgoing, incoming, both trave…
…rsals neo4jrb/neo4j#181

It is now also possible to create several relationship in one go
  node.outgoing(:foo).incoming(:bar).both(:baaz) << other_node
  node.outgoing(:foo).incoming(:bar).both(:baaz).new(other_node, rel_props)
287c423
@andreasronge andreasronge added a commit to neo4jrb/neo4j-core that referenced this issue
@andreasronge andreasronge Support for cypher query expressed as a Hash, e.g. outgoing(:foo).que…
…ry(:name => 'foo') - traversals neo4jrb/neo4j#181
7ab57d2
@andreasronge andreasronge added a commit to andreasronge/neo4j-wrapper that referenced this issue
@andreasronge andreasronge Cypher Traversal and Rules neo4jrb/neo4j#181
Support for things like getting the rooms for a dungeon where there are dangerous monsters using rules:
@dungeon.monsters.dangerous { |m| rooms = m.incoming(Room.monsters); rooms}
662e0ad
@andreasronge andreasronge added a commit to andreasronge/neo4j-wrapper that referenced this issue
@andreasronge andreasronge Added RSpecs for sorting has_n relationship with cypher DSL neo4jrb/n…
…eo4j#181

Some refactoring and exposed a method creating rules method on traversal which can be used by neo4j gem.
5efe932
@andreasronge andreasronge added a commit to andreasronge/neo4j-wrapper that referenced this issue
@andreasronge andreasronge Cypher Traversal and Rules neo4jrb/neo4j#181
Support for things like getting the rooms for a dungeon where there are dangerous monsters using rules:
@dungeon.monsters.dangerous { |m| rooms = m.incoming(Room.monsters); rooms
7ed29ba
@andreasronge andreasronge added a commit that referenced this issue
@andreasronge andreasronge Cypher and Rule integration #181
Support for things like @dungeon.monsters.dangerous { |m| m[:weapon?] == 'sword' }
39b2101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.