Skip to content

mattylight22/arangosdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArangoSDK

ArangoSDK is a very simple and light weight tool for basic ArangoDB operations.

Installation

Use npm to install ArangoSDK.

npm install @mattnick/arangosdk

Usage

const ArangoSDK = require('@mattnick/arangosdk');
const db = new ArangoSDK('url', 'databaseName', 'username', 'password');

Queries

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);
}

Insert

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);
}

Update

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);
}

Remove

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);
}

Close Connection

Closes all active connections

const ArangoSDK = require('@mattnick/arangosdk');
const db = new ArangoSDK('url', 'databaseName', 'username', 'password');


db.close();

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published