ArangoDB client
A client for the ArangoDB nosql database.
Install
As nodejs module: npm install arango.client
From source: git clone git://github.com/kaerus/arango-client
Test
Open/run index.html from the test directory.
Building
To be able to build a minified version you need to have the require.js optimizer r.js installed.
make dist
This creates a single minified javascript file in the dist
directory.
Usage
You can use arango-client either as node.js server module or from a web client. Since arango-client is written in AMD compatible fashion you should be able to require it in your project using any standard AMD loader. However, require.js is included by default when installing through npm.
Introduction
All callbacks receives error code, return value and message headers. If the error is set, return contains an error message, otherwise return contains whatever yields from the database, usually in the form of a json object.
dbdocument;
Using events
You may also use events as a means to receive data or errors. This can be very useful in some cases, however the current implementation is somewhat limited at the moment but new exciting developements are in the pipeline.
The on 'error' event passes an error object with error.code and error.message.
dbdocument;
On 'result' event passes the returned data and headers.
dbdocument;
For details regarding the ArangoDB interface check out lib/api/ and use the nodejs/browser console to experiment.
nodearango = Connection: Function db =
Examples
Require
var arango =
Initialization
To initialize a connection you have to use the Connection([string],[object])
constructor.
/* use default settings, connects to http://127.0.0.1:8529 in nodejs *//* or window.location when using from your browser */db = /* connection string */db = "http://127.0.0.1/test"; /* connection with http auth */db = "http://user:pass@your.host.com/database"; /* connection object */db = name:"database" user:"master"; /* mixed mode */db = "http://test.host.com:80/default"user:unamepass:pwd;
Creating collections & documents
/* Create a 'test' collection */dbcollection; /* create a new document in 'test' collection */dbdocument; /* get a list of all documents in collection */dbdocument; /* create a new document and create a new collection on demand */dbdocument; /* create another document in the new collection */dbdocument;
Utilizing events
Sometimes it's better to use events instead of callbacks.
/* alternate style utilizing events */dbdocument;/* errors are logged to console per default */
Queries
/* simple query string */dbquery; /* A bindvar for the collection name */dbquerystring = "FOR u IN @@collection RETURN u";.../* execute the query and pass the collection variable */dbquery;
Note: ArangoDB expects @@ in front of collection names when using a bindvar. The bindvar attribute in this case needs to be prefixed with a single @. In all other cases the bindvar atttribute can be provided without any prefix and the variable in the query string is denoted with a single @ .
Query builder
The query builder is still experimental and prone for changes.
Batch size can be set using the query.count(<number>)
method.
However iterations over result sets are not fully supported yet.
/* using the experimental query builder */query = dbquery ; /* show the composed query string */console; /* test run the query */query; /* execute the query and set the variable 'state' */query; /* detailed query explanation */query; /* nested queries embedded as functions(){} */query = dbquery ; query;
License
MIT License
Copyright (C) Kaerus 2012, Anders Elo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.