neo4jrb / activegraph

An active model wrapper for the Neo4j Graph Database for Ruby.
http://neo4jrb.io
MIT License
1.4k stars 276 forks source link

Allow passing array of hashes to `create` in `ActiveNode` #1448

Open cheerfulstoic opened 6 years ago

cheerfulstoic commented 6 years ago

In ActiveRecord you can pass in an array of hashes where the hashes has the properties of the nodes that you want to create and it creates many at the same time. ActiveNode should support the same functionality.

Open question: Does ActiveRecord actually create the objects in memory and validate them before saving? Does it make multiple DB requests?

jorroll commented 6 years ago

It's been a while since I've had to do this in ActiveRecord, so I don't remember if AR makes multiple DB requests. I DO remember that AR passes multiple insert queries to the DB, which is very inefficient. The ActiveRecord import gem specifically fixes this problem.

I think an analogous scenario in Neo4j would be sending 10 batched queries to the DB (in order to create 10 nodes) as part of one http request VS sending one query in which you unwind a param in order to create 10 nodes.

I don't remember if AR validates the objects.

cheerfulstoic commented 6 years ago

Yeah, I've definitely created some functions to help emulated part of what activerecord_import does. It would definitely make sense to send multiple queries in one HTTP request, though probably it would be good to start pushing toward Bolt which (I don't think) has the same tradeoff in sending multiple queries in one network request