Ruby on Rails – Storing Graphs with JSON and Database

dataruby-on-rails

I have a Rails 4 app having to do with graphs. These graphs need to be stored and I'm not sure of the best way to do it. Firstly, the app has a SQLite db in development and PostgreSQL in production. I would love to have graphs in JSON, but that can be achieved in several ways. Also, these graphs are going to be manipulated using some interface. I was thinking a graphical solution and a raw one in JSON.

I have some alternatives to implementation:

  1. Store the graph JSON files directly in the db. (how?)
  2. Store the graphs in db with tables (graph, edges, vertex) (probably not…)
  3. Store the graphs in db with tables and build a parser to manipulate the in JSON format.

What is your recommendations?

Best Answer

It looks like you're talking about mathematical graphs, not charts per se. I read a pretty nice presentation on using Postgres for storing graph-type data. It covers several different data modeling options that can work with an RDBMS. You might also want to consider using a specialized graph database (neo4j) for graph-related needs.

Related Topic