163
1 David Funaro Alessandro Nadalin GraphDB in PHP

Graph databases in PHP @ PHPCon Poland 10-22-2011

Embed Size (px)

DESCRIPTION

Presentation given at the national PHP conference in Poland, in Kielce, October 2011, dealing with the introduction of graph databases in PHP, taking a practical look at OrientDB.

Citation preview

Page 1: Graph databases in PHP @ PHPCon Poland 10-22-2011

1

David FunaroAlessandro Nadalin

GraphDB in PHP

Page 2: Graph databases in PHP @ PHPCon Poland 10-22-2011

Agenda

2

•Theory•When to use a graph?•Why graphDB?•The graphDB community•OrientDB•OrientDB in PHP•Demo

Page 3: Graph databases in PHP @ PHPCon Poland 10-22-2011

Essential (Theory)

3

Page 4: Graph databases in PHP @ PHPCon Poland 10-22-2011

Essential (Theory)

3

Gra

phG =

Page 5: Graph databases in PHP @ PHPCon Poland 10-22-2011

Essential (Theory)

3

Ver

tex

(V,G

raph

G =

Page 6: Graph databases in PHP @ PHPCon Poland 10-22-2011

Essential (Theory)

A

3

Ver

tex

(V,G

raph

G =

Page 7: Graph databases in PHP @ PHPCon Poland 10-22-2011

Essential (Theory)

A

3

Ver

tex

(V,G

raph

G =

Edg

e

E)

Page 8: Graph databases in PHP @ PHPCon Poland 10-22-2011

Essential (Theory)

A

3

Ver

tex

(V,G

raph

G =

Edg

e

E)

Page 9: Graph databases in PHP @ PHPCon Poland 10-22-2011

Binary Relation

4

BA

Hates

Itchy Scratchy

Page 10: Graph databases in PHP @ PHPCon Poland 10-22-2011

Binary Relation

4

B

Vertex Vertex

Edge

A

Page 11: Graph databases in PHP @ PHPCon Poland 10-22-2011

Graph

5

B

D

E

G

FA

Page 12: Graph databases in PHP @ PHPCon Poland 10-22-2011

Undirected Graph

B

D

E

F

A

Example: Friendship 6

Page 13: Graph databases in PHP @ PHPCon Poland 10-22-2011

Directed Edge

7

B

Vertex Vertex

A

Page 14: Graph databases in PHP @ PHPCon Poland 10-22-2011

Directed Edge

7

B

Vertex Vertex

Edge

A

Page 15: Graph databases in PHP @ PHPCon Poland 10-22-2011

Directed Graph

8Example: Followee

D

FA

BA

Page 16: Graph databases in PHP @ PHPCon Poland 10-22-2011

Path

9

B

D

E

G

FA

Page 17: Graph databases in PHP @ PHPCon Poland 10-22-2011

Path

10

B D EG FA

Page 18: Graph databases in PHP @ PHPCon Poland 10-22-2011

Graph -> GraphDB

11

GraphDB is a database that use the Graph as its primary data structure

Page 19: Graph databases in PHP @ PHPCon Poland 10-22-2011

... when to use a graph ?

Page 20: Graph databases in PHP @ PHPCon Poland 10-22-2011

Web in ’99

13

Page 21: Graph databases in PHP @ PHPCon Poland 10-22-2011

Web in 2005

14

Page 22: Graph databases in PHP @ PHPCon Poland 10-22-2011

The social web

15

Page 23: Graph databases in PHP @ PHPCon Poland 10-22-2011

Your data is a graph

16

Page 24: Graph databases in PHP @ PHPCon Poland 10-22-2011

a tree is a graph

17

Page 25: Graph databases in PHP @ PHPCon Poland 10-22-2011

parent_id is a graph

18

Page 26: Graph databases in PHP @ PHPCon Poland 10-22-2011

Recommendations

19

John

Rome

Milan

Cinema A

Cinema B

Cinema C

Se7en

Mr Bean

Thriller

Fun

lives in

location

location

location

type

type

likes

shows

shows

shows

Page 27: Graph databases in PHP @ PHPCon Poland 10-22-2011

Recommendations

20

John

Rome

Milan

Cinema A

Cinema B

Cinema C

Se7en

Mr Bean

Thriller

Fun

lives in

location

location

location

type

type

likes

shows

shows

shows x

x

Page 28: Graph databases in PHP @ PHPCon Poland 10-22-2011

Recommendations

21

John

Rome

Milan

Cinema A

Cinema B

Cinema C

Se7en

Mr Bean

Thriller

Fun

lives in

location

location

location

type

type

likes

shows

shows

shows x

x

Page 29: Graph databases in PHP @ PHPCon Poland 10-22-2011

Recommendations

22

John

Rome

Milan

Cinema A

Cinema B

Cinema C

Se7en

Mr Bean

Thriller

Fun

lives in

location

location

location

type

type

likes

shows

shows

shows x

x

✓ ✓

Page 30: Graph databases in PHP @ PHPCon Poland 10-22-2011

Recommendations

23

John

Rome

Milan

Cinema A

Cinema B

Cinema C

Se7en

Mr Bean

Thriller

Fun

lives in

location

location

location

type

type

likes

shows

shows

shows x

x

✓ ✓ x

Page 31: Graph databases in PHP @ PHPCon Poland 10-22-2011

Recommendations

24

John

Rome

Milan

Cinema A

Cinema B

Cinema C

Se7en

Mr Bean

Thriller

Fun

lives in

location

location

location

type

type

likes

shows

shows

shows x

x

x x x ✓

Page 32: Graph databases in PHP @ PHPCon Poland 10-22-2011

Recommendations

25

John

Rome

Milan

Cinema A

Cinema B

Cinema C

Se7en

Mr Bean

Thriller

Fun

lives in

location

location

location

type

type

likes

shows

shows

shows x

x

x x x ✓ ✓

Page 33: Graph databases in PHP @ PHPCon Poland 10-22-2011

Recommendations

26

John

Rome

Milan

Cinema A

Cinema B

Cinema C

Se7en

Mr Bean

Thriller

Fun

lives in

location

location

location

type

type

likes

shows

shows

shows x

x

x x x ✓ ✓ ✓

Page 34: Graph databases in PHP @ PHPCon Poland 10-22-2011

Recommendations

27

John

Rome

Milan

Cinema A

Cinema B

Cinema C

Se7en

Mr Bean

Thriller

Fun

lives in

location

location

location

type

type

likes

shows

shows

shows x

x

x x x ✓ ✓ ✓ ✓

Page 35: Graph databases in PHP @ PHPCon Poland 10-22-2011

Solve decision problems

Page 36: Graph databases in PHP @ PHPCon Poland 10-22-2011

Maximum flow

Page 37: Graph databases in PHP @ PHPCon Poland 10-22-2011
Page 38: Graph databases in PHP @ PHPCon Poland 10-22-2011

maximum flowGiven a dataset, calculate how to best organize it

Page 39: Graph databases in PHP @ PHPCon Poland 10-22-2011

travelling salesman problem

Page 40: Graph databases in PHP @ PHPCon Poland 10-22-2011

The pizza guy needs to deliver on A, B,C.

Page 41: Graph databases in PHP @ PHPCon Poland 10-22-2011

Decision base on distance, traffic, time and so on.

Page 42: Graph databases in PHP @ PHPCon Poland 10-22-2011

Shortest path

Page 43: Graph databases in PHP @ PHPCon Poland 10-22-2011

Identify "special" nodes of the graph

Page 44: Graph databases in PHP @ PHPCon Poland 10-22-2011

Given your dataset, organize some clusters

Are there some nodes which cannot belong to a cluster?

They probably have some properties different from the average

Page 45: Graph databases in PHP @ PHPCon Poland 10-22-2011

Given your dataset, organize some clusters

Are there some nodes which cannot belong to a cluster?

They probably have some properties different from the average

ACHTUNG!TERRORISTEN!

Page 46: Graph databases in PHP @ PHPCon Poland 10-22-2011

but ... why graphDB?

38

Page 49: Graph databases in PHP @ PHPCon Poland 10-22-2011

where is the difference ?

40

Page 50: Graph databases in PHP @ PHPCon Poland 10-22-2011

A graph database is any storage system that provides index-free adjacency.

GraphDB

http://www.slideshare.net/slidarko/problemsolving-using-graph-traversals-searching-scoring-ranking-and-recommendation

Page 51: Graph databases in PHP @ PHPCon Poland 10-22-2011

Step by step example

42

Given a list of people, find their homepages

Page 52: Graph databases in PHP @ PHPCon Poland 10-22-2011

Tree-based DB WAY

43

1

Page 53: Graph databases in PHP @ PHPCon Poland 10-22-2011

Tree-based DB WAY

43

1

David Funaro

put in the Search Engine2

Page 54: Graph databases in PHP @ PHPCon Poland 10-22-2011

Tree-based DB WAY

43

1

find

http://davidfunaro.com

3

David Funaro

put in the Search Engine2

Page 55: Graph databases in PHP @ PHPCon Poland 10-22-2011

Tree-based DB WAY

43

1

find

http://davidfunaro.com

3

David Funaro

put in the Search Engine2

The cost to find a single friend HP grows as the friends HP tables grows

Page 56: Graph databases in PHP @ PHPCon Poland 10-22-2011

GraphDB WAY

44

it’s like that the GraphDB has an additional information(the ancor <a>)

Page 57: Graph databases in PHP @ PHPCon Poland 10-22-2011

GraphDB WAY

44

get the embedded information(index)

www.odino.org

1

it’s like that the GraphDB has an additional information(the ancor <a>)

Page 58: Graph databases in PHP @ PHPCon Poland 10-22-2011

GraphDB WAY

45

<a href=”http://odino.org”>Alessandro Nadalin

</a>

The Anchor work as a local index to reach the document = index-free

adjacency

Page 59: Graph databases in PHP @ PHPCon Poland 10-22-2011

Local cost

46

The local cost is O(k) = Constant

Page 60: Graph databases in PHP @ PHPCon Poland 10-22-2011

Local cost

47

The local cost is O(k) = Constant

Page 61: Graph databases in PHP @ PHPCon Poland 10-22-2011

Local cost

48

Page 62: Graph databases in PHP @ PHPCon Poland 10-22-2011

Local cost

48

Thus, as the graph grows in size, the cost of a local step remain the same

Page 63: Graph databases in PHP @ PHPCon Poland 10-22-2011

any database can implicity represent a graph

BUTonly a graph database make the graph

structure explicit

49

Page 64: Graph databases in PHP @ PHPCon Poland 10-22-2011

Benchmark

50

• 1 Million Vertex

• 4 Million Edge

• Scale Free Tolopogy

• Postgres VS Neo4J

• Both Hash and BTree

Deph RDBMS Graph

1

2

3

4

5

100ms 30ms

1000ms 500ms

10000ms 3000ms

100000ms

50000ms

N/A 100000ms

http://markorodriguez.com/2011/02/18/mysql-vs-neo4j-on-a-large-scale-graph-traversal/

Page 65: Graph databases in PHP @ PHPCon Poland 10-22-2011

Databases

community that is building and feeding the GraphDB ecosystem

ThinkerPopStack

GraphDB community

Page 66: Graph databases in PHP @ PHPCon Poland 10-22-2011

Blueprints is a collection of interfaces, implementations, ouplementations, and test suites for the property graph data

model. Blueprints is analogous to the JDBC, but for graph databases.

https://github.com/tinkerpop/blueprints/wiki/

data model and their implementation

Page 67: Graph databases in PHP @ PHPCon Poland 10-22-2011

provide a collection of "pipes" that are connected togheter to from processing

pipelines

a data flow Framework using Process Graph

Page 68: Graph databases in PHP @ PHPCon Poland 10-22-2011

a graph-based programming language.

a Turing-Complete graph-base programming language that compiles Gremlin syntax down to Pipes

Page 69: Graph databases in PHP @ PHPCon Poland 10-22-2011

a REST-full graph shell.

Allow blueprints graph to be exposed through a RESTful API (HTTP)

Page 70: Graph databases in PHP @ PHPCon Poland 10-22-2011

What's hot

Page 71: Graph databases in PHP @ PHPCon Poland 10-22-2011

OrientDB

Page 72: Graph databases in PHP @ PHPCon Poland 10-22-2011

Glossary

58

<10:05>RID

Cluster Position

Page 73: Graph databases in PHP @ PHPCon Poland 10-22-2011

Glossary

58

<10:05>RID

Cluster Position

CLASS

Page 74: Graph databases in PHP @ PHPCon Poland 10-22-2011

Main features

Page 75: Graph databases in PHP @ PHPCon Poland 10-22-2011

Inheritance

Page 76: Graph databases in PHP @ PHPCon Poland 10-22-2011

class Bike

class Vehicle

class Car

Page 77: Graph databases in PHP @ PHPCon Poland 10-22-2011

class Bike

class Vehicle

class Car

SELECT FROM Vehicle WHERE owner = 1:1

Page 78: Graph databases in PHP @ PHPCon Poland 10-22-2011

class Bike

class Vehicle

class Car

can return records of class Bike or Car

Page 79: Graph databases in PHP @ PHPCon Poland 10-22-2011

Traversal

Page 80: Graph databases in PHP @ PHPCon Poland 10-22-2011
Page 81: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM fellas WHERE any() traverse(0,-1) ( @rid = [Michelle @rid] )66

Page 82: Graph databases in PHP @ PHPCon Poland 10-22-2011

67SELECT FROM fellas WHERE any() traverse(0,-1) ( @rid = [Michelle @rid] )

Page 83: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM fellas WHERE any() traverse(0,2) ( @rid = [Michelle @rid] )SELECT FROM fellas WHERE any() traverse(0,2) ( @rid = [Michelle @rid] )

Page 84: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM fellas WHERE any() traverse(0,2) ( @rid = [Michelle @rid] )

Page 85: Graph databases in PHP @ PHPCon Poland 10-22-2011

SQL synthax

Page 86: Graph databases in PHP @ PHPCon Poland 10-22-2011

beyond SQL

Page 87: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM authors WHERE book.title = ...

Page 88: Graph databases in PHP @ PHPCon Poland 10-22-2011

ACID

Page 89: Graph databases in PHP @ PHPCon Poland 10-22-2011

speaks JSON

Page 90: Graph databases in PHP @ PHPCon Poland 10-22-2011

{ "schema": { "name": "Address" }, "result": [{ "@type": "d", "@rid": "#13:0", "@version": 6, "@class": "Address", "type": "Residence", "street": "Piazza Navona, 1", "city": "#14:0", "nick": "Luca2" }, { ... ...

Page 91: Graph databases in PHP @ PHPCon Poland 10-22-2011

Double Protocol

Page 92: Graph databases in PHP @ PHPCon Poland 10-22-2011

HTTP

Page 93: Graph databases in PHP @ PHPCon Poland 10-22-2011

HTTP

Universal

Page 94: Graph databases in PHP @ PHPCon Poland 10-22-2011

HTTP

Easy to interact with

Page 95: Graph databases in PHP @ PHPCon Poland 10-22-2011

binary

Page 96: Graph databases in PHP @ PHPCon Poland 10-22-2011

Blazing fast

binary

Page 97: Graph databases in PHP @ PHPCon Poland 10-22-2011

on-record SELECTs

Page 98: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM cats

Page 99: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM cats

Page 100: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM 11:0

Page 101: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM 11:0

Page 102: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM [11:0,11:1]

Page 103: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM [11:0,11:1]

Page 104: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM [11:0,12:0]

Page 105: Graph databases in PHP @ PHPCon Poland 10-22-2011

SELECT FROM [11:0,12:0]

Page 106: Graph databases in PHP @ PHPCon Poland 10-22-2011

stress-free setup

Page 107: Graph databases in PHP @ PHPCon Poland 10-22-2011

2 Mb

Page 108: Graph databases in PHP @ PHPCon Poland 10-22-2011

./orient/bin/server.sh

93

Page 109: Graph databases in PHP @ PHPCon Poland 10-22-2011

in-memory DB

Page 110: Graph databases in PHP @ PHPCon Poland 10-22-2011

or disk-persisted

Page 111: Graph databases in PHP @ PHPCon Poland 10-22-2011

Supports standards Supports standards

96

Page 112: Graph databases in PHP @ PHPCon Poland 10-22-2011

OrientDB

•Inheritance

•Traversal

•Sql syntax like

•ACID

•Speak JSON

•Double protocol

•on-record Select

•ThinkerPop Compliant

Page 113: Graph databases in PHP @ PHPCon Poland 10-22-2011

Oh, it's Java.

98

Page 114: Graph databases in PHP @ PHPCon Poland 10-22-2011

PHP ?

Page 115: Graph databases in PHP @ PHPCon Poland 10-22-2011

somebody started writing thebinary-protocol binding

https://github.com/AntonTerekhov/OrientDB-PHP( beta0.4.1, 28 April 2010 )

Page 116: Graph databases in PHP @ PHPCon Poland 10-22-2011

$db = new OrientDB($host, $port);

$record = $db->recordLoad('1:1', '*:-1');

// $record instance of OrientDBRecord

Page 117: Graph databases in PHP @ PHPCon Poland 10-22-2011

and others

Page 118: Graph databases in PHP @ PHPCon Poland 10-22-2011
Page 119: Graph databases in PHP @ PHPCon Poland 10-22-2011

Orient Library

104

... are writing a complete library

https://github.com/congow/Orient

Page 120: Graph databases in PHP @ PHPCon Poland 10-22-2011

Orient = PHP Library to work with OrientDB

105

Page 121: Graph databases in PHP @ PHPCon Poland 10-22-2011

Data Mapper

Query BuilderHTTP Binding

Page 122: Graph databases in PHP @ PHPCon Poland 10-22-2011

HTTP Binding

Page 123: Graph databases in PHP @ PHPCon Poland 10-22-2011

use Congow\Orient;use Congow\Orient\Foundation\Binding;

$driver   = new Orient\Http\Client\Curl();$orient   = new Binding($driver, '127.0.0.1', '2480', 'admin', 'admin', 'demo');

$response = $orient->query("SELECT FROM Address");

$output   = json_decode($response->getBody());

foreach ($output->result as $address){  var_dump($address->street);}

Page 124: Graph databases in PHP @ PHPCon Poland 10-22-2011

use Congow\Orient;use Congow\Orient\Foundation\Binding;

$driver   = new Orient\Http\Client\Curl();$orient   = new Binding($driver, '127.0.0.1', '2480', 'admin', 'admin', 'demo');

$response = $orient->query("SELECT FROM Address");

$output   = json_decode($response->getBody());

foreach ($output->result as $address){  var_dump($address->street);}

Page 125: Graph databases in PHP @ PHPCon Poland 10-22-2011

use Congow\Orient;use Congow\Orient\Foundation\Binding;

$driver   = new Orient\Http\Client\Curl();$orient   = new Binding($driver, '127.0.0.1', '2480', 'admin', 'admin', 'demo');

$response = $orient->query("SELECT FROM Address");

$output   = json_decode($response->getBody());

foreach ($output->result as $address){  var_dump($address->street);}

Page 126: Graph databases in PHP @ PHPCon Poland 10-22-2011

use Congow\Orient;use Congow\Orient\Foundation\Binding;

$driver   = new Orient\Http\Client\Curl();$orient   = new Binding($driver, '127.0.0.1', '2480', 'admin', 'admin', 'demo');

$response = $orient->query("SELECT FROM Address");

$output   = json_decode($response->getBody());

foreach ($output->result as $address){  var_dump($address->street);}

Page 127: Graph databases in PHP @ PHPCon Poland 10-22-2011

use Congow\Orient;use Congow\Orient\Foundation\Binding;

$driver   = new Orient\Http\Client\Curl();$orient   = new Binding($driver, '127.0.0.1', '2480', 'admin', 'admin', 'demo');

$response = $orient->query("SELECT FROM Address");

$output   = json_decode($response->getBody());

foreach ($output->result as $address){  var_dump($address->street);}

{ "schema": { "name": "Address" }, "result": [{ "@type": "d", "@rid": "#13:0", "@version": 6, "@class": "Address", "type": "Residence", "street": "Piazza Navona, 1", "city": "#14:0", "nick": "Luca2" }, { ... ...

Page 128: Graph databases in PHP @ PHPCon Poland 10-22-2011

apart from ->query($SQL)

Page 129: Graph databases in PHP @ PHPCon Poland 10-22-2011

->get|delete|postClass($class)

Page 130: Graph databases in PHP @ PHPCon Poland 10-22-2011

->post|delete|put|getDocument($rid)

Page 131: Graph databases in PHP @ PHPCon Poland 10-22-2011

...and much more!

(connect, disconnect, ...)

Page 132: Graph databases in PHP @ PHPCon Poland 10-22-2011

Query Builder

Page 133: Graph databases in PHP @ PHPCon Poland 10-22-2011

use Congow\Orient\Query;

$query = new Query();$query->from(array('users'))->where('username = ?', "admin");

echo $query->getRaw(); // SELECT FROM users WHERE username = "admin"

Page 134: Graph databases in PHP @ PHPCon Poland 10-22-2011

use Congow\Orient\Query;

$query = new Query();$query->from(array('users'))->where('username = ?', "admin");

echo $query->getRaw(); // SELECT FROM users WHERE username = "admin"

Page 135: Graph databases in PHP @ PHPCon Poland 10-22-2011

use Congow\Orient\Query;

$query = new Query();$query->from(array('users'))->where('username = ?', "admin");

echo $query->getRaw(); // SELECT FROM users WHERE username = "admin"

Page 136: Graph databases in PHP @ PHPCon Poland 10-22-2011

use Congow\Orient\Query;

$query = new Query();$query->from(array('users'))->where('username = ?', "admin");

echo $query->getRaw(); // SELECT FROM users WHERE username = "admin"

Page 137: Graph databases in PHP @ PHPCon Poland 10-22-2011

               $query->select(array('name', 'username', 'email'), false)                ->from(array('12:0', '12:1'), false)                ->where('any() traverse ( any() like "%danger%" )')                ->orWhere("1 = ?", 1)                ->andWhere("links = ?", 1)                ->limit(20)                ->orderBy('username')                ->orderBy('name', true, true)                ->range("12:0", "12:1");

              SELECT name, username, email               FROM [12:0, 12:1]               WHERE any() traverse ( any() like "%danger%" )              OR 1 = "1" AND links = "1"               ORDER BY name, username               LIMIT 20               RANGE 12:0 12:1

Page 138: Graph databases in PHP @ PHPCon Poland 10-22-2011

Data Mapper

Page 139: Graph databases in PHP @ PHPCon Poland 10-22-2011

A Doctrine2 strange ODM

Page 140: Graph databases in PHP @ PHPCon Poland 10-22-2011

namespace Poland\PHPCon\Entity;

use Congow\Orient\ODM\Mapper\Annotations as ODM;

/*** @ODM\Document(class="Person")*/class Speaker{    /**     * @ODM\Property( type="string")     */    protected $name;

    public function setName($name)    {        $this->name = $name;    }

Page 141: Graph databases in PHP @ PHPCon Poland 10-22-2011

namespace Poland\PHPCon\Entity;

use Congow\Orient\ODM\Mapper\Annotations as ODM;

/*** @ODM\Document(class="Person")*/class Speaker{    /**     * @ODM\Property(type="string")     */    protected $name;

    public function setName($name)    {        $this->name = $name;    }

Page 142: Graph databases in PHP @ PHPCon Poland 10-22-2011

namespace Poland\PHPCon\Entity;

use Congow\Orient\ODM\Mapper\Annotations as ODM;

/*** @ODM\Document(class="Person")*/class Speaker{    /**     * @ODM\Property(type="string")     */    protected $name;

    public function setName($name)    {        $this->name = $name;    }

Page 143: Graph databases in PHP @ PHPCon Poland 10-22-2011

namespace Poland\PHPCon\Entity;

use Congow\Orient\ODM\Mapper\Annotations as ODM;

/*** @ODM\Document(class="Person")*/class Speaker{    /**     * @ODM\Property(type="string")     */    protected $name;

    public function setName($name)    {        $this->name = $name;    }

Page 144: Graph databases in PHP @ PHPCon Poland 10-22-2011

Domain Driven Design

Page 145: Graph databases in PHP @ PHPCon Poland 10-22-2011

{ "schema": { "name": "Speaker" }, "result": [{ "@type": "d", "@rid": "#1:0", "@version": 6, "@class": "Speaker", "name": "David Coallier" }, { ... ...

Page 146: Graph databases in PHP @ PHPCon Poland 10-22-2011

{ "schema": { "name": "Speaker" }, "result": [{ "@type": "d", "@rid": "#1:0", "@version": 6, "@class": "Speaker", "name": "David Coallier" }, { ... ...

$david = $mapper->hydrate(json_decode($speaker));

Page 147: Graph databases in PHP @ PHPCon Poland 10-22-2011

{ "schema": { "name": "Speaker" }, "result": [{ "@type": "d", "@rid": "#1:0", "@version": 6, "@class": "Speaker", "name": "David Coallier" }, { ... ...

$david instanceOf Poland\PHPCon\Entity\Speaker

Page 148: Graph databases in PHP @ PHPCon Poland 10-22-2011

Repository Pattern

$repo = $manager->getRepository('Speaker')

Page 149: Graph databases in PHP @ PHPCon Poland 10-22-2011

$speakers = $repo->findAll();

Page 150: Graph databases in PHP @ PHPCon Poland 10-22-2011

$speaker = $repo->find($rid);

Page 151: Graph databases in PHP @ PHPCon Poland 10-22-2011

$criteria = array('Name' => 'Lorna');

$lornas = $repo->findBy($criteria);

Page 152: Graph databases in PHP @ PHPCon Poland 10-22-2011

$criteria = array( 'Name' => 'Lorna', 'last_name' => 'Jane');

$lornaJ = $repo->findOneBy($criteria);

Page 153: Graph databases in PHP @ PHPCon Poland 10-22-2011

Know your boundaries

138

Page 155: Graph databases in PHP @ PHPCon Poland 10-22-2011

Theory sucks.

140

Page 156: Graph databases in PHP @ PHPCon Poland 10-22-2011

Demo

Page 157: Graph databases in PHP @ PHPCon Poland 10-22-2011

Demo

142

id type page url

1 external NULL http://www.google.com

2 page 1 NULL

Menu items in RDBMS

Page 158: Graph databases in PHP @ PHPCon Poland 10-22-2011

Demo

143

rid title url

8:2 google google.com

Menu items in OrientDB

rid title page

9:1 home 1{ Link

PageLink ExternalLink

Page 159: Graph databases in PHP @ PHPCon Poland 10-22-2011

144

That’s all, folks!

Page 160: Graph databases in PHP @ PHPCon Poland 10-22-2011

144

David Funaro@ingdavidinohttp://davidfunaro.com

That’s all, folks!

Page 161: Graph databases in PHP @ PHPCon Poland 10-22-2011

144

David Funaro@ingdavidinohttp://davidfunaro.com

Alessandro Nadalin@_odino_

http://odino.org

That’s all, folks!

Page 162: Graph databases in PHP @ PHPCon Poland 10-22-2011

144

David Funaro@ingdavidinohttp://davidfunaro.com

Alessandro Nadalin@_odino_

http://odino.org

That’s all, folks!

Page 163: Graph databases in PHP @ PHPCon Poland 10-22-2011

Credits

http://www.flickr.com/photos/sayamindu/5677281218/sizes/l/in/photostream/http://farm1.static.flickr.com/182/471383865_79d04aec36_o.pnghttp://farm1.static.flickr.com/134/318947873_12028f1b66_b.jpg

http://www.flickr.com/photos/atomdocs/3275758118/sizes/o/in/photostream/http://www.flickr.com/photos/pattipics/5229478393/sizes/o/in/photostream/

http://www.flickr.com/photos/kongharald/366597251/sizes/o/in/photostream/http://www.everaldo.com/

http://www.flickr.com/photos/tusnelda/6140792529/sizes/l/in/photostream/http://www.flickr.com/photos/mondi/5368644355/sizes/l/in/photostream/

http://www.flickr.com/photos/jayneandd/4191106566/sizes/l/in/photostream/http://www.flickr.com/photos/jooon/2093253534/sizes/l/in/photostream/

http://www.flickr.com/photos/bluedharma/89186151/sizes/o/in/photostream/http://www.flickr.com/photos/exfordy/2747089295/sizes/l/in/photostream/

http://www.flickr.com/photos/nostri-imago/3137422976/sizes/o/in/photostream/http://www.flickr.com/photos/fionasjournal/379587818/sizes/z/in/photostream/

http://www.flickr.com/photos/nperlapro/1297392267/http://www.flickr.com/photos/fastphive/28428808/sizes/m/in/photostream/

http://www.flickr.com/photos/rnugraha/2003147365/sizes/o/in/photostream/http://www.flickr.com/photos/zigazou76/4412946911/sizes/l/in/photostream/http://www.flickr.com/photos/greatnet/4667555436/sizes/l/in/photostream/

http://www.flickr.com/photos/mnsc/2768391365/sizes/l/in/photostream/http://www.flickr.com/photos/christmaswithak/4675962453/sizes/l/in/photostream/

http://www.amazon.com/Trainspotting-Irvine-Welsh/dp/0393314804http://www.flickr.com/photos/franconadalin59/5778176872/sizes/l/in/photostream/

http://farm6.static.flickr.com/5176/5474445627_875d621689_b.jpghttp://farm3.static.flickr.com/2243/2189435082_a16d3c89ae_b.jpghttp://farm3.static.flickr.com/2647/3816311930_ac52cff491_o.jpg

http://i130.photobucket.com/albums/p266/feike1977/PES6-4-3-3defencesettings.jpghttp://images.usatoday.com/life/_photos/2006/11/30/numb3rs-topper.jpg

http://www.flickr.com/photos/jakecaptive/3205277810/sizes/l/in/photostream/