Let Your Database Update You with EctoWatch
Elixir allows application developers to create very parallel and very complex systems. Tools like Phoenix PubSub and LiveView thrive on this property of the ...
For a while now I’ve been building various Neo4j.rb educational resources using the example of an asset portal. There has been:
As part of this process I’ve wanted to use what I’ve been building and allow anybody to easily create a UI for their own assets in Rails. I’m pleased to say that I’ve got a good start with the graph_starter gem.
The graph_starter
gem is a Rails engine, which means that it can be placed within a Rails application. The goal is to be able to quickly set up a basic UI for your entities, but to also be able to override it when you want to provide custom logic.
Setting up a graph_starter
application is as simple as the following steps:
Using graph_starter
is easy!
First create a Rails application if you don’t already have one:
rails new application_name
Include the graph_starter
gem (it will include the Neo4j.rb gems for you):
# Gemfile
gem 'graph_starter'
Mount the engine:
# config/routes.rb
mount GraphStarter::Engine => '/'
Create some asset models:
# app/models/product.rb
class Product < GraphStarter::Asset
# `title` property is added automatically
property :name
property :description
property :price, type: Integer
has_images
has_one :in, :vendor, type: :SELLS_PRODUCT
end
# app/models/vendor.rb
class Vendor < GraphStarter::Asset
property :brand_name
property :code
name_property :brand_name
has_many :out, :products, origin: :vendor
end
These models are simply Neo4j.rb ActiveNode
models so you can refer to the Neo4j.rb documentation to define them. They do have some special methods, however, which let you control how GraphStarter works. In the above Product
model, for example, has_images
has been called to indicate that products have images which defines a separate Image
model along with the neccessary association. See the graph_starter README for documentation on how to configure aspects of your models.
Once that framework is in place you can define a way to import data, if desired. For this I would suggest making a rake task:
# lib/tasks/store.rake
namespace :store do
task :import do
CSV.open(File.read('vendors.csv')).each do |row|
Vendor.create(name: row['brand_name'],
code: row['code'])
end
CSV.open(File.read('products.csv')).each do |row|
product = Product.create(name: row['name'],
description: row['description'],
price: row['price'].to_i)
product.vendor = Vendor.find_by(code: row['vendor_code'])
end
end
end
And that’s all!
When everything is in place you can simply start up your Rails server (by running rails server
) and you get a UI which looks like this example site I made using data from the Natural History Museum in London:
You can browse the app on Heroku and checkout the repository on Github
I’ll be working on a new project to create a GraphGist portal based on the graph_starter
gem so I plan to continue improving it!
Elixir allows application developers to create very parallel and very complex systems. Tools like Phoenix PubSub and LiveView thrive on this property of the ...
(This post was originally created for the Erlang Solutions blog. The original can be found here)
with
It, Can’t Live with
out It
(This post was originally created for the Erlang Solutions blog. The original can be found here)
I’ve been using Elixir for a while and I’ve implemented a number of GenServers. But while I think I mostly understand the purpose of them, I’ve not gotten t...
I love Lodash, but I’m not here to tell you to use Lodash. It’s up to you to decide if a tool is useful for you or your project. It will come down to the n...
I’ve mix phx.new ed many applications and when doing so I often start with wondering how to organize my code. I love how Phoenix pushes you to think about th...
What can a 50 year old cryptic error message teach us about the software we write today?
For just over a year I’ve been obsessed on-and-off with a project ever since I stayed in the town of Skibbereen, Ireland. Taking data from the 1901 and 1911...
Recently the continuous builds for the neo4j Ruby gem failed for JRuby because the memory limit had been reached. I wanted to see if I could use my favorite...
A while ago my colleague Michael suggested to me that I draw out some examples of how my record linkage algorithm did it’s thing. In order to do that, I’ve ...
Last night I ran a very successful workshop at the Friends of Neo4j Stockholm meetup group. The format was based on a workshop that I attended in San Franci...
In my last two posts I covered the process of importing data from StackOverflow and GitHub for the purpose of creating a combined MDM database. Now we get t...
In my last post I said I would “bring in another data source, show how I linked the data together, and demonstrate the sort of bigger picture that one can ge...
Joining multiple disparate data-sources, commonly dubbed Master Data Management (MDM), is usually not a fun exercise. I would like to show you how to use a g...
I have a bit of a problem.
When using neo4j for the first time, most people want to import data from another database to start playing around. There are a lot of options including LOA...
Having recently become interested in making it easy to pull data from Twitter with neo4apis-twitter I also decided that I wanted to be able to visualize an...
I’ve been reading a few interesting analyses of Twitter data recently such as this #gamergate analysis by Andy Baio. I thought it would be nice to have a ...
I am he as you are he as you are me and we are all together – The Beatles
When I told the people of Northern Ireland that I was an atheist, a woman in the audience stood up and said, ‘Yes, but is it the God of the Catholics or t...
“Wilkins! Yes! I’ve considered decorating these walls with some graffiti of my own, and writing it in the Universal Character.. but it is too depressing...