Code Monkey home page Code Monkey logo

feathers-arangodb's Introduction

feathers-arangodb

Build Status
Dependency Status
Download Status

A Feathers database adapter for ArangoDB using official NodeJS driver for ArangoDB.

$ npm install --save arangojs feathers-arangodb  

Important: feathers-arangodb implements the Feathers Common database adapter API and querying syntax.

This adapter also requires a running ArangoDB database server.


Simple Server Example

import express from '@feathersjs/express';  
import feathers, {HookContext} from '@feathersjs/feathers';  
import cors from 'cors';  
import helmet from 'helmet';  
import compress from 'compression';  
import ArangoDbService, { IArangoDbService, IOptions, AUTH_TYPES } from 'feathers-arangodb'  
import { aql } from "arangojs";  
  
// Set up your feathers app.  
const app = express(feathers());  
app.use(helmet());  
app.use(cors());  
app.use(compress());  
app.use(express.json());  
app.use(express.urlencoded({ extended: true }));  
app.configure(express.rest());  
  
// Create your database settings  
const todoDatabase:IOptions = {  
  collection: 'TODOS',  
  database: 'YOUR_DATABASE_NAME',  
  authType: AUTH_TYPES.BASIC_AUTH,  
  username: 'root',  
  password: 'root',  
};  
// Fast and simple CRUD  
app.use('todos', ArangoDbService(todoDatabase));  
  
// Add in some hooks!  
const todoService = <IArangoDbService<any>>app.service('todos');  
todoService.hooks({  
  after: {  
    create: [  
      async (context:HookContext) => {  
        // Maybe we want run another AQL query directly on the database.  
        const { database, collection } = await todoService.connect();  
        // Do a query  
        const cursor = await database.query(aql`RETURN LENGTH(${collection})`)  
        // Parse the cursor  
        const count = await cursor.next();  
        // Assign some data to the stuff  
        context.result = {  
          count,  
          data: context.result  
        };  
        return context;  
      }  
    ]  
  }  
});  
  
// Start the app listening  
app.listen(8080);  
console.log('Listening on port 8080');  

Database Options

id (optional) : String : Translated ID key value in payloads. Actual storage in database is saved in the _key key/value within ArangoDB. Defaults to _key

expandData (optional) : Boolean : Adapter filters out _rev and _id from ArangoDB. Setting expandData to true will include these in the payload results. Defaults to false

collection (required) : DocumentCollection | String : Either a string name of a collection, which will be created if it doesn't exist in database, or a reference to an existing arangoDB collection object.

database (required) : Database | String : Either a string name of a database, which will be created if it doesn't exist on the ArangoDB server, or a reference to an existing ArangoDB database object.

graph (optional) : Graph | { properties, opts } : Graph options to create a new graph. name is required in the properties. See Documentation

authType (optional) : String : String value of either BASIC_AUTH or BEARER_AUTH. Used to define the type of auth to ArangoDB (see documentation). Defaults to BASIC_AUTH

username (optional) : String : Used for auth, plaintext username

password (optional) : String : Used for auth, plaintext password

token (optional) : String : If token is supplied, auth uses token instead of username/password.

dbConfig (optional) : ArangoDbConfig : ArangoDB Config file for a new database. See Documentation

events (optional) : Array : FeathersJS Events - See Documentation

paginate (optional) : FeathersJS Paginate : FeathersJS Paginate - See Documentation

Copyright (c) 2018

Licensed under the MIT license.

feathers-arangodb's People

Contributors

brian-mcbride avatar greenkeeper[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.