How can I alter node properties with pacer?

29 views
Skip to first unread message

Bob

unread,
Nov 29, 2014, 6:11:48 AM11/29/14
to pacer...@googlegroups.com
Are there any examples for using pacer as a data persistence layer in Rails?

Another question: I'm not familiar with the Blueprints stack, it seems that pacer allows me writing arbitrary traversal logic in ruby, does that mean running a complex pacer traversal against a remote database will trigger a lot of RPCs and is impractical?

The interfaces are quite elegant, and using them must be very happy.

Thanks for your help.

Darrick Wiebe

unread,
Nov 29, 2014, 11:12:59 AM11/29/14
to Pacer Group
Hi Bob,

I know that Pacer has been used in a variety of projects, but am not aware of whether anyone is using it in a Rails app, and no problems have been reported to me. Given the popularity of Rails, I'd expect that there are people using them together, though.

To alter node or edge properties, you can simply get a reference to the element you want to change and then set it like this: node[:property] = "value". Depending on the graph you use you may need to use a transaction block: graph.transaction { <do work here> }.

Pacer's designed for use with embedded graphs. Neo4j can only be used in embedded mode, while Orient can be used in either mode, but yes it is much slower when using it remote.

I'm glad to hear you are liking Pacer!

Darrick


--
You received this message because you are subscribed to the Google Groups "pacer-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pacer-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bob

unread,
Nov 29, 2014, 9:16:28 PM11/29/14
to pacer...@googlegroups.com
Hi Darrick,

I tried these

jruby-1.7.6 :001 > g = Pacer.orient 'remote:localhost/test'
jruby
-1.7.6 :002 > g.v(type: 'user') # a ({type: user}) node created earlier
#<V[9:3]>
jruby
-1.7.6 :003 > g.v(type: 'user')[:name] = 'bob'
NoMethodError: #<V[9:3]>
Total: 1
undefined method `[]=' for #<GraphV -> V-Property(type=="user")>`

....

jruby
-1.7.6 :013 > g.v(type: 'user')[:name]
"bob"

I can change the property through a VertexWrapper though (but not knowing other ways to get one).

g.transaction do g.vertex('9:3')[:name] = 'bob' end # the same node

Am I supposed to wrap a g.v in a wrapper and treat the wrapper as a vertex?

Do you have any recommended documents/projects for Pacer's new users to read? 

Thanks so much for your help. 

Darrick Wiebe

unread,
Nov 29, 2014, 9:34:44 PM11/29/14
to Pacer Group
Hi Bob,

You're almost there! :)

The problem is that you were working against a Route, not a Vertex.

Try this instead to update each record in your query in chunked transactions:

g.v(type: 'user').bulk_job { |vertex| vertex[:name] = 'bob' }

or if you were expecting a single vertex, just grab it and updated it directly:

g.v(type: 'user').first[:name] = 'bob'

We are currently working on documentation. You can see the work in progress at https://github.com/joeyfreund/pacer/wiki

Hope that helps, and feedback on the docs is very welcome!

Darrick

Bob

unread,
Nov 30, 2014, 12:55:56 AM11/30/14
to pacer...@googlegroups.com
Ah, I see. That explains many things, and makes the wiki easier to understand. 
Pacer is really doing things in the ruby way. Paths are lazily computed Enumerable.
Thanks, that's super helpful.

I think the documents would be more friendly for new users if it contains some sections about what to expect in Pacer, e.g. Pacer supports richer traversal patterns like recursive ones compared to neo4j-core's limited Cypher queries, but would not be so suitable for a remote database(am I understanding it right?).

Thanks again for your work.
Reply all
Reply to author
Forward
0 new messages