ArangoSDK is a very simple and light weight tool for basic ArangoDB operations.
Use npm to install ArangoSDK.
npm install @mattnick/arangosdk
const ArangoSDK = require('@mattnick/arangosdk');
const db = new ArangoSDK('url', 'databaseName', 'username', 'password');
const ArangoSDK = require('@mattnick/arangosdk');
const db = new ArangoSDK('url', 'databaseName', 'username', 'password');
const results = await db.query("FOR doc IN `users` FILTER doc.userID == @uid RETURN doc",{uid: 34543});
//results example
/*
Success:
{error: null, docs: [...], length: 3}
Error:
{error: {some arango error}}
*/
if(!results.error){
//do something
results.docs.forEach((row)=>console.log(row))
}else{
console.log(results.error);
}
const ArangoSDK = require('@mattnick/arangosdk');
const db = new ArangoSDK('url', 'databaseName', 'username', 'password');
const user_data = {name: "bob", email: "[email protected]"};
const result = await db.insert("users", user_data);
//result example
/*
Success:
{error: null, meta: {_id: "users/343534543", _rev: 33453534}}
Error:
{error: {some arango error}}
*/
if(!result.error){
//do something
console.log(result.meta._id);
}else{
console.log(result.error);
}
const ArangoSDK = require('@mattnick/arangosdk');
const db = new ArangoSDK('url', 'databaseName', 'username', 'password');
const user_data = {name: "bob", email: "[email protected]"};
const result = await db.update("users", "users/343534543", user_data);
//result example
/*
Success:
{error: null, meta: {_id: "users/343534543", _rev: 33453535}}
Error:
{error: {some arango error}}
*/
if(!result.error){
//do something
console.log(result.meta._id);
}else{
console.log(result.error);
}
const ArangoSDK = require('@mattnick/arangosdk');
const db = new ArangoSDK('url', 'databaseName', 'username', 'password');
const result = await db.remove("users", "users/343534543");
//result example
/*
Success:
{error: null}
Error:
{error: {some arango error}}
*/
if(!result.error){
//do something
console.log("Document was removed!");
}else{
console.log(result.error);
}
Closes all active connections
const ArangoSDK = require('@mattnick/arangosdk');
const db = new ArangoSDK('url', 'databaseName', 'username', 'password');
db.close();