Getting Started with ArangoDB & Symfony: Part 1 | ArangoDB 2013

This is part 1 (of 4) of an introduction to the use of ArangoDB together with Symfony 2. You'll find the links to the other parts of this tutorial at the end of this text.

In this tutorial we will implement a very simple movie database as an example of how to use ArangoDB together with Symfony 2. We assume for the tutorial that you know the basic concepts of Symfony2. No prior ArangoDB knowledge is required.

The demo shows how to create, edit, update and delete movies, how to select a list of movies from the database in two different ways. We’ll use the simple query API for most examples. The “search for a topic” feature uses ArangoDB’s query language (AQL), a convenient sql-like way to query ArangoDB.

You can download the completed demo at Github.


A short word on ArangoDB

Warning - a paragraph of marketing ahead! ;-) ArangoDB is an open-source mostly-memory database with a flexible data model for documents and graphs for modern web applications.  With ArangoDB you build high performance applications in short time - it is schema-less and has a full-blown query language nevertheless (there is no need to write map/reduce functions if your queries get more complicate) . You can even extend ArangoDB by adding your own Javascript/Ruby methods to the database.

Libraries & infrastructure

The following components are used

What’s this? Since Symfony is a PHP framework we need the PHP driver for ArangoDB. The MopArangoDbBundle integrates the PHP driver into Symfony: having this bundle installed, you can config the connection to ArangoDB in the config.yml (note: the bundle also offers a FOSUserBundle integration which is not used in this demo, but might be interested for you if you are looking for a  user management system out of the box).

Installing ArangoDB

Now grab your copy of ArangoDB from the download page and install it. There are binaries available for many common platforms (Linux, OSX, Windows). Make sure that ArangoDB is up and running by opening the graphical user interface in your browser:

http://localhost:8529/_admin/html/index.html

Configuring Symfony for use with ArangoDB

First thing we have to do is to tell Symfony that we want to work with ArangoDB. So we add the two required bundles to composer.json and run “php composer.phar update” as usual.

// path/to/myapp/composer.json
"require": {
        …
        "triagens/ArangoDb": "dev-devel",
        "mop/arangodbbundle" : "dev-master"
         …
    },

Note: for this tutorial a feature was added to the ArangoDB PHP driver which is only available in the  “dev-devel” branch at the time of writing this text.

Having MopArangodbBundle installed we can add our connection settings to config.yml

//myapp/app/config/config.yml
mop_arango_db:
    default_connection: main #will be set to the first connection if not present
    connections:
        main:
            host: 127.0.0.1
            port: 8529

We are done.

In Symfony we can now access the default connection to ArangoDB with

$connection = $this->get('mop_arangodb.default_connection');

The end

Congrats, you have reached the end of part 1 the tutorial. There is more:

More info...

ArangoDB & Symfony Integration: Part 2 | ArangoDB ’13

This is part 2 (of 4) of an introduction to the use of ArangoDB together with Symfony 2. You’ll find the links to the other parts of this tutorial at the end of this text.

You can download the completed demo at Github.

The data structure

Our app deals with movies: each movie has a title, a year of release and it is assigned to a genre. Each movie deals with none, one or many topics.

In a relational database we would probably create a table movie and another table topic and join them with a shared movie id.

ArangoDB follows like other document stores the “aggregate model” approach: In short terms this means that you should put data that is often needed together into one document. Remember: documents are a bit like rows in the relation world; in nosql world they can have a nested structure.

(more…)

More info...

ArangoDB & Symfony Integration: Part 3 Guide | ArangoDB ’13

This is part 3 (of 4) of an introduction to the use of ArangoDB together with Symfony 2. You’ll find the links to the other parts of this tutorial at the end of this text.
You can download the completed demo at Github.

Working with forms

The next example shows the use of ArangoDB with Symfony’s form component.

This is how our form will look like. The topics are represented as a text field and the user is required to separate them by commas. This delivers questionable user experience, but leads to an interesting question: how can we transform our topics array from our movie document to a text field? And: we’ll need it at least two times, both for creating and editing movies.

(more…)

More info...

ArangoDB & Symfony Integration: Part 4 Guide | ArangoDB ’13

This is part 4 (of 4) of an introduction to the use of ArangoDB together with Symfony 2. You’ll find the links to the other parts of this tutorial at the end of this text.
You can download the completed demo at Github.

Extending Arangodb\Document

The next thing we want to improve are all those noisy set calls in the controller:

// src/Triagens/ArangodbBundle/Controller/DefaultController.php
if ($form->isValid()) {
    $movie = new ArangoDocument();
    $movie->set("title",$form->get("title")->getData());
    $movie->set("released",$form->get("released")->getData());
    $movie->set("genre",$form->get("genre")->getData());
    // and so on ... my eyes hurt!
}

(more…)

More info...

Tutorial for AvocadoDB PHP API Published | ArangoDB Blog 2012

Note: We changed the name of the database in May 2012. AvocadoDB is now called ArangoDB.

Hey there, short notice: Jan has written a tutorial on how to use the PHP API for AvocadoDB (note: this is “just” the API for the REST interface, it does not cover yet the upcoming query language). You can find both the

PHP API and the tutorial on Github. We are making progress with other languages as well… but that’s something for another blog post (cliffhanger 😉 ).

More info...

Get the latest tutorials,
blog posts and news: