NYC Neo4j Meetup 003 Slides: Realistic Neo4j with Ruby (Part 1)

12
Meetup Jan 29 th , 2014 Realistic Neo4j: Neo4j + Ruby (part 1) 1

description

Using Neo4j with Ruby and Neography. Code examples here: https://github.com/seenickcode/nycneo4j-sinatra-example-1

Transcript of NYC Neo4j Meetup 003 Slides: Realistic Neo4j with Ruby (Part 1)

Page 1: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

1

Meetup Jan 29th, 2014

Realistic Neo4j: Neo4j + Ruby (part 1)

Page 2: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

source: http://neo4j.rubyforge.org/guides/why_graph_db.html

Neo4j Quick Review• Benefits of a Graph Database

– Super fast when querying complex, highly connected data

– Schema-less and Efficient storage of Semi Structured

Information

– Fast deep traversal instead of slow SQL queries that span

many table joins

– Very natural to express graph related problems with

traversals (recommendation engine, shortest parth etc..)

Page 3: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

3

Neo4j Quick Review• Graph Database

– A graph database is a database that uses graph structures with nodes,

edges, and properties to represent and store data (Wikipedia)

• Node

– An entity in the database typically representing a “thing”

• Relationship

– A one way link between two nodes

• Node/Relationship Property

– A key-value pair that can be attached to a node or relationship

– example: { “name” : “Nicholas” }

• Label

– A “tag” that can be attached to a node in order to make querying faster

and more convenient

Page 4: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

4

Examplenode node

property: valueproperty: valueproperty: value

label

relationship type

label

name: ‘Joe’age: 27

:User

:UPLOADS

:Photo

filename: ‘cat.png’

on: 2013-11-18

Page 5: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

5

Example

name: ‘Joe’age: 27

:User

:FOLLOWS

weight: 10

name: ‘Jane’bday: 19800115

name: ‘Joe’age: 27

filename: ‘cat.png’

:FOLLOWS

weight: 2

:LIKES

on: 20131118

:PHOTO

Page 6: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

6

Queries are Traversals

end

start

Page 7: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

7

What Are Our Options?• Java

– Kind of heavyweight. Bit more complex to host. But good

for control and optimizing queries.

• Ruby

– Neo4j.rb

• Uses JRuby which is still Java under the hood.

– Neography

• Uses Neo4j’s RESTful HTTP web services

• Not as fast as other options, but simple and easier to deploy and

host

• Other Options

– Node.js, Python, PHP, .NET, Go, etc

– http://www.neo4j.org/develop/drivers

Page 8: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

8

Our Example Today• Why Ruby?

– Simple, popular, easy to learn.

• Why Not X Instead of Ruby?

• Why Neography?

– Communicates with Neo4j via HTTP, simply point your code

to a Neo4j server and get started

– Downside: not the best documentation or examples for

newcomers (hence this meetup)

– https://github.com/maxdemarzi/neography

• Why aren’t we looking at a Rails example?

• Thoughts on ActiveRecord

Page 9: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

9

Today (part 1) We’ll Cover• Writing Code That:

– creates nodes for Users

– creates relationships for Users

– using indexes

• Writing a Few Tests To

Demonstrate

• (No webpages, Sorry , Keeping it

Simple)

Page 10: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

10

Technologies We’ll Cover• Neo4j

– Download, start and make sure Neo4j is running

– Checkout the Data Browser at http://localhost:7474

• Ruby

– Ruby is a programming language we will use to talk to the Neo4j server

– Install Ruby: https://www.ruby-lang.org/en/installation

– Run `ruby –v` to make sure it is installed properly

• Sinatra

– A simple framework for writing Ruby web applications or web service APIs

– Remember, use whatever language and framwork you like. Sinatra is just

an example.

– (more information: http://www.sinatrarb.com)

– (great intro:

http://www.slideshare.net/knaveofdiamonds/web-simplicity-ruby-sinatra-r

ack

)

Page 12: NYC Neo4j Meetup 003 Slides:  Realistic Neo4j with Ruby (Part 1)

12

Thanks for Coming

• @seenickcode

[email protected] for

questions

• Next time we’ll expand on this!

• Want to present? Let me know.