An ruby gem to import SQL data to neo4j using activerecord
Clone or download
Latest commit 6dd3bb2 Aug 28, 2015


The easiest and quickest way to copy data from PostgreSQL / mySQL / sqlite to Neo4j

How to run:

Without existing ActiveRecord application:

neo4apis activerecord all_tables --identify-model --import-all-associations


neo4apis activerecord tables posts comments --identify-model --import-all-associations

With existing ActiveRecord application:

neo4apis activerecord all_models --import-all-associations


neo4apis activerecord models Post Comment --import-all-associations


Using rubygems:

gem install neo4apis-activerecord

How it works

ActiveRecord is a ORM for ruby. neo4apis-activerecord uses ActiveRecord models which are either found in an existing ruby app or generated from table structures. The models are then introspected to create nodes (from tables) and relationships (from associations) in neo4j. The neo4apis library is used to load data efficiently in batches.


For a list of all options run:

neo4apis activerecord --help

Some options of particular interest:


The --identify-model option looks for tables' names/primay keys/foreign keys automatically. Potential options are generated and the database is examined to find out which fits.

As an example: for a table of posts the following possibilities would checked:

  • Names: Looks for names like posts, post, Posts, or Post
  • Primary keys: Table schema is examined first. If no primary key is specified it will look for columns like id, post_id, PostId, or uuid
  • Foreign keys: author_id or AuthorId will be assumed to go to a table of authors (with a name identified as above)





Either specify that a certain class of associations be imported from ActiveRecord models or specify all with --import-all-associations

Using neo4apis-activerecord from ruby

If you'd like to do custom importing, you can use neo4apis-activerecord in the following way:


neo4apis_activerecord =, import_all_associations: true)

neo4apis_activerecord.batch do
  SomeModel.where(condition: 'value').find_each do |object|
    neo4apis_activerecord.import object