NuvolaBase

API (Application Program Interface)

NuvolaBase is your graph database on the cloud. You can use different languages with different APIs. Choose the best one for your use case.

NuvolaBase is based on OrientDB Graph Database. For any additional information please consult the OrientDB Documentation.

After reading this small article you will be ready to use your low cost web hosting plan, or your smoking high end infrastructure as well, to make HTTP/REST queries against the orientdb cloud engine of your brand new NuvolaBase account. This is needed, for example, if you want to use NuvolaBase as a centralized orientdb database system with ajax due to the security restrictions imposed by web browsers.
All you need is what you probably already have: a web hosting provider with PHP support.

For the impatients, you are only 3 steps away to the goal!
  1. download the orientdb_proxy PHP file on your computer from this url: http://orient.googlecode.com/svn/trunk/server/src/proxy/php/orientdb_proxy.php
  2. open the downloaded orientdb_proxy.php file with a text editor of your choice (notepad, vim, wordpad, nano, no matter which) and edit the row (about at number 36) of the file as in the example below, setting your nuvolabase user/password/host given at registration time. Save when finished:
              $real_destination_host = "http[s]://[user]:[password]@[host]";
              
    example:
              $real_destination_host = "http://phpguru:mygurupass@dashboard.nuvolabase.com";
              
    If you don't know what to put here fill free to send an email to info@nuvolabase.com.
  3. connect your favourite FTP client to the server of your hosting provider and "cd" into your web document root (the correct path where your PHP files are already deployed). Feel free to use any other web path if you do not want to put the orientdb_proxy.php file into your "/" web uri. You may want to use sftp, scp, or any other file transfer method supported by your provider, it's the same for this to work.
Well done! It's now time for a first check.
Point your favourite web browser (firefox, chrome, explorer, etc) to your website + [previously_chosen_path]/orientdb_proxy.php/studio/
For example, if your website is www.imaphpgu.ru and you putted the orientdb proxy into your document root (/) you can call this url with your browser: http://www.imaphpgu.ru/orientdb_proxy.php/studio/
You should view the orient db studio nuvolabase edition, and... bingo!! The configuration is over.

You can now fire REST queries to your NuvolaBase account with your PHP webserver as a web reverse proxy.
The good news is that you can now safely map your private nuvolabase REST url (for eg: dashboard.nuvolabase.com/your_rest_request) to your public site url (http://www.imaphpgu.ru/orientdb_proxy.php/your_rest_request). This will make browsers feeling very happy.

Now, relax, get a coffe, eat a chocolate and brush your teeth.
OK, it's now time for handling some code. This is a simple JavaScript piece of code to get dynamic content from NuvolaBase traversing the PHP proxy on your domain.
          var database = new ODatabase('http://www.imaphpgu.ru/orientdb_proxy.php/');
          databaseInfo = database.open();
          queryResult = database.query('select from Address where city.country.name = \'Italy\'');
          if (queryResult["result"].length == 0){
                commandResult = database.executeCommand('insert into Address (street,type) values (\'Via test 1\',\'Tipo test\')');
          } else {
                commandResult = database.executeCommand('update Address set street = \'Via test 1\' where city.country.name = \'Italy\'');
          }
          database.close();
          

To get started with OrientDB and NuvolaBase we have prepared a "Ready to use" project that contains all the basic "CRUD" operations.
You can use these examples to start in developing your application.

The project contains executable classes (each one represents an operation) that uses a test database on NuvolaBase:

  1. Document Database
    1. Insert Document
    2. Read Document
    3. Delete Document
  2. Object Database
    1. Insert Object
    2. Read Object
    3. Delete Object
  3. Graph Database (Integrated with TinkerPop BluePrints)
    1. Insert Graph
    2. Read Graph

  1. Download and install Apache Maven Project
  2. Download the OrientDB Java example project source
For Eclipse Users :
  1. Launch in the console of your OS the command: mvn eclipse:eclipse from the directory of the "NuvolaBase Java Example Project".
  2. If you don't have the Maven Plugin installed download it from: M2Eclipse.
  3. Click on the menu File->Import ... and then select Maven->Existing Maven Projects.
    At the end select the directory of the NuvolaBase Java Example Project and press the button "Finish".
  4. Now browse the project, select one of the examples and run it!.

For Intellij IDEA Users :
  1. Open IDEA
  2. Click on the menu File->New Project... and then select Import Project from external Model.
  3. Select the type Maven
  4. Select the Root directory of the NuvolaBase Java Example Project and then the project java-examples. Now press the button "Next" and then "Finish"
  5. Now browse the project, select one example and run it!

If you want to use OrientDB with a php application you can choice two different library:

  1. OrientDB-PHP - A plain PHP driver to OrientDB graph database using its binary protocol.
  2. Orient CONGOW - An Object Graph Mapper in PHP using the OrientDB HTTP protocol binding

Just a quick full immersion to get your feet wet with PHP and OrientDB.

Here we are creating a record:

$db = new OrientDB(string $host, int $port[, int $connectTimeout]);
$connected = $db->connect('root', 'passwd');
$config = $db->DBOpen('demo', 'writer', 'writer');

$record = new OrientDBRecord();
$record->data->name = 'John';
$recordPos = $db->recordCreate(1, $record);

$db->DBClose();

You can obviously get back the previous record:

$db = new OrientDB(string $host, int $port[, int $connectTimeout]);
$connected = $db->connect('root', 'passwd');
$config = $db->DBOpen('demo', 'writer', 'writer');

$cluster_id="1";
$cluster_position="1";

$record = $db->recordLoad($cluster_id .":". $cluster_position, '*:-1');
var_dump($db->cachedRecords);
$db->DBClose();

Coming Soon.
Coming Soon.

Well, well, well... so you come here and pretend to use a document/object database on the cloud from your applications written in C, isn't it?
We are absolutely sure (if you code in C you can surely confirm this) that viewing the source code is more direct and productive that reading stuff like that, so, let's go to the code!

oh = o_new();
rc = o_prepare_connection(oh, ORIENT_PROTO_BINARY, "yourhost.nuvolabase.com", "2424");
rc = o_prepare_user(oh, ORIENT_USER, "youruser", "verysecure_userpwd_123");
rc = o_prepare_user(oh, ORIENT_ADMIN, "youradmin", "verysecure_adminpwd_123");
oc = o_connect(oh, &tv, 0);
rc = o_bin_dbopen(oh, oc, &tv, 0, "yourverypersonaldatabaseonthecloud");
odoc = o_bin_recordload(oh, oc, &tv, 0, cluster_id, cluster_position, "*:-1");
rc = o_bin_dbclose(oh, oc, &tv, 0);
o_close(oh, oc);
o_free(oh);

Ok. The first is self explained, we are setting up library internal buffers.
The o_prepare_connection() library call means that you want to prepare the library to open a connection to a given host/port with the orientdb binary protocol. No real connection will be made here.
The o_prepare_user() function will setup the library to use the given user/password for operations on orientdb. Administrative tasks on the DB that make use of the CONNECT binary method can be performed by administrators. You can specify which administrative account will be used by the library passing the "ORIENT_ADMIN" attribute. For normal operations you can use the "ORIENT_USER" attribute instead. This way you can specify which DB user to use for normal and administrative tasks, letting the library to do all the work for you, for free.
With o_connect() you will create the real connection to the specified host, on the specified port, with the specified protocol (only the binary protocol is supported by now, but we are working on REST api as well).
Once successfully connected you can interact with the DB in the cloud, for example opening the DB first. You can do it using the o_bin_dbopen() call. You could also use multiple opened DBs in parallel using diffenent o_connect() returned objects.
After the DB is opened, if your access credentials are OK, you can for example retrieve an object from the DB with o_bin_recordload(), then close the database with o_bin_dbclose(), close the connection with o_close() and free things with o_free().

As you know well, the C language does not have the concept of "objects", and all the OOP stuff cannot be done natively in C.

So, this also means that it shouldn't be possible to access the simple or complex structured objects saved into (nuvolabase.com) OrientDB... we are talking about integers, shorts, longs, floats, strings, binary, collections (arrays), maps (hash tables), structured embedded documents (objects inside other objects) and more... Well, this is simply not true! With NuvolaBase you can access all that stuff from your C code without too much effort.

You can, for example, iterate on the returned object fields:

...
odoc = o_bin_recordload(oh, oc, &tv, 0, cluster_id, cluster_position, "*:-1");
printf("Fields cycle...\n");
ODOC_ITERATE(odoc, field) {
        printf("Field name: %s\n", odoc_get_field_name(field));
        printf("Field type: %i\n", odoc_get_field_type(field));
}
printf("END of fields cycle.\n\n");
ODOC_FREE_DOCUMENT(odoc);
...

Get a object field by its name, (obtaining real native C data!!):

short shorty;
int inty;
...
odoc = o_bin_recordload(oh, oc, &tv, 0, cluster_id, cluster_position, "*:-1");
// get shorty
field = odoc_get_field_byname(odoc, "shorty");
shorty = odoc_get_short(field);
printf("Field value: %i\n", shorty);
// get inty
field = odoc_get_field_byname(odoc, "inty");
inty = odoc_get_short(field);
printf("Field value: %i\n", inty);
ODOC_FREE_DOCUMENT(odoc);
...

Or simply get some info about a field by its name, for example the field type (short, int, string, etc):

...
odoc = o_bin_recordload(oh, oc, &tv, 0, cluster_id, cluster_position, "*:-1");
// get shorty
field = odoc_get_field_byname(odoc, "shorty");
printf("Field type: %i\n", odoc_get_field_type(field));
ODOC_FREE_DOCUMENT(odoc);
...

We are working hard to create the complete library API and odocument handling API documentation set.

Ahh!!! The library to use is called "liborient" (LGPLv3):
https://github.com/dam2k/liborient

Come back soon.