How to use arangojs - 10 common examples

To help you get started, we’ve selected a few arangojs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github harpagon210 / steemsmartcontracts / test / tokens.js View on Github external
plugin.cp.stdout.on('data', data => console.log(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));
  plugin.cp.stderr.on('data', data => console.error(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));

  plugins[newPlugin.PLUGIN_NAME] = plugin;

  return send(newPlugin.PLUGIN_NAME, 'MASTER', { action: 'init', payload: conf });
};

const unloadPlugin = (plugin) => {
  plugins[plugin.PLUGIN_NAME].cp.kill('SIGINT');
  plugins[plugin.PLUGIN_NAME] = null;
  jobs = new Map();
  currentJobId = 0;
}

const db = new Database(conf.databaseURL);

const FORK_BLOCK_NUMBER = 30896500;
const SSC_STORE_QTY = '0.001';

// tokens
describe('Tokens smart contract', function () {
  this.timeout(10000);

  beforeEach((done) => {
    new Promise(async (resolve) => {
      try {
        await db.dropDatabase(conf.databaseName);
      } catch (error) {

      }
github harpagon210 / steemsmartcontracts / test / smarttokens.js View on Github external
plugin.cp.stdout.on('data', data => console.log(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));
  plugin.cp.stderr.on('data', data => console.error(`[${newPlugin.PLUGIN_NAME}]`, data.toString()));

  plugins[newPlugin.PLUGIN_NAME] = plugin;

  return send(newPlugin.PLUGIN_NAME, 'MASTER', { action: 'init', payload: conf });
};

const unloadPlugin = (plugin) => {
  plugins[plugin.PLUGIN_NAME].cp.kill('SIGINT');
  plugins[plugin.PLUGIN_NAME] = null;
  jobs = new Map();
  currentJobId = 0;
}

const db = new Database(conf.databaseURL);

const FORK_BLOCK_NUMBER = 30896500;

// smart tokens
describe('smart tokens', function () {
  this.timeout(30000);

  beforeEach((done) => {
    new Promise(async (resolve) => {
      try {
        await db.dropDatabase(conf.databaseName);
      } catch (error) {

      }

      resolve();
github OriginTrail / ot-node / test / bdd / steps / hooks.js View on Github external
AfterAll(async function () {
    // Delete almost all Arango dbs.
    const systemDb = new Database();
    systemDb.useBasicAuth(config.database.username, config.database.password);

    const listOfDatabases = await systemDb.listDatabases();

    const that = this;
    listOfDatabases.forEach(async function (databaseItem) {
        if (databaseItem !== '_system' && databaseItem !== 'origintrail' && databaseItem !== 'origintrail-develop' && databaseItem !== 'origintrail-staging' && databaseItem !== 'origintrail-stable') {
            try {
                await systemDb.dropDatabase(databaseItem);
            } catch (error) {
                that.logger.log(`Oops, failed to delete database: ${databaseItem}`);
                that.logger.log(error);
            }
        }
    });
github OriginTrail / ot-node / scripts / setup.js View on Github external
async function resetArangoDb(database) {
    console.info(`Setting up graph database '${database.database}'...`);
    const systemDb = new Database();
    systemDb.useBasicAuth(database.username, database.password);

    // Drop test database if exist.
    const listOfDatabases = await systemDb.listDatabases();
    if (listOfDatabases.includes(database.database)) {
        await
        systemDb.dropDatabase(database.database);
    }

    await
    systemDb.createDatabase(
        database.database,
        [{ username: database.username, passwd: database.password, active: true }],
    );
}
github NodeMC / CORE / lib / db.js View on Github external
async exists(collection = required(), key = required(), value = required()) {
    const aql = arangojs.aql;
    const collectionObject = await this._collection(collection)

    let exists = false;
    try {
      const cursor = await this.db.query(aql`
        FOR o IN ${collectionObject}
        FILTER o.${key} == ${value}
        RETURN o
      `, { count: true })

      // if we have more or equal to 1, it exists already.
      if(cursor.count >= 1) exists = true
    } catch(e) {
      debug("exists", "error", e.message)
      exists = true
    }
github AEB-labs / cruddl / spec / performance / support / helpers.ts View on Github external
import { Database } from 'arangojs';
import { graphql, GraphQLSchema } from 'graphql';
import * as path from 'path';
import { SchemaContext } from '../../../src/config/global';
import { ArangoDBAdapter } from '../../../src/database/arangodb';
import { Project } from '../../../src/project/project';
import { loadProjectFromDir } from '../../../src/project/project-from-fs';
import { range } from '../../../src/utils/utils';
import { Log4jsLoggerProvider } from '../../helpers/log4js-logger-provider';
import { createTempDatabase } from '../../regression/initialization';

// arangojs typings for this are completely broken
export const aql: (template: TemplateStringsArray, ...args: any[]) => any = require('arangojs').aql;

const MODEL_PATH = path.resolve(__dirname, '../../regression/papers/model');

export interface TestEnvironment {
    getDB(): Database;

    exec(graphql: string, variables?: { [name: string]: any }): any
}

const schemaContext: SchemaContext = { loggerProvider: new Log4jsLoggerProvider('warn'), getExecutionOptions: ({ context }) => ({ authRoles: context.authRoles }) };

export async function createTestProject(modelPath: string = MODEL_PATH): Promise<{ project: Project, schema: GraphQLSchema }> {
    const project = await loadProjectFromDir(modelPath, schemaContext);
    const dbConfig = await createTempDatabase();
    const dbAdapter = new ArangoDBAdapter(dbConfig, schemaContext);
    const schema = project.createSchema(dbAdapter);
github hemerajs / hemera / packages / hemera-arango-store / index.js View on Github external
function hemeraArangoStore(hemera, opts, done) {
  const connections = {}
  const topic = 'arango-store'
  const Joi = hemera.joi

  hemera.decorate('arango', Arangojs)
  hemera.decorate('aqlTemplate', Arangojs.aql)

  function useDb(databaseName) {
    if (connections[databaseName]) {
      return connections[databaseName]
    }

    // try to create new db connection based on arango settings
    if (opts.arango.databaseName) {
      let options = Object.assign({}, opts.arango)

      if (databaseName) {
        options.databaseName = databaseName
      }

      connections[databaseName] = new Arangojs.Database(options)
github OKNoah / final-orm / models / model.js View on Github external
static async _getDatabase () {
    if (Model._database) {
      return Model._database
    }

    const dbName = this.options.database
    const host = this.options.host || 'localhost'
    const port = this.options.port || 8529
    const username = this.options.username || 'root'
    const password = this.options.password || ''
    const url = this.options.url || `http://${username}:${password}@${host}:${port}`

    const db = arangojs({
      url
    })

    try {
      await db.createDatabase(dbName)
    } catch (e) {
      // throw new Error(get(e, 'response.body.errorMessage', e))
    }

    db.useDatabase(dbName)

    Model._database = db
    return db
  }
github AEB-labs / cruddl / src / database / arangodb / arangojs-instrumentation / custom-request.ts View on Github external
{ method, url, headers, body, requestInstrumentation }: RequestOptions,
            callback: Errback
        ) {
            // this is the last change we cancel a request
            // we don't cancel running requests because arangodb does not kill queries when the request ist terminated
            // thus, we keep the request open
            // - to get notified if the request completes pretty quickly anyway so we don't need to kill the query
            // - to take up a socket so that no new query is sent on it while the query is not yet killed
            if (requestInstrumentation && requestInstrumentation.isCancelled) {
                return callback(new Error(`Request has been cancelled by caller before it was sent`));
            }

            notifyAboutPhaseEnd(requestInstrumentation, 'queuing');
            let path = baseUrlParts.pathname
                ? url.pathname
                    ? joinPath(baseUrlParts.pathname, url.pathname)
                    : baseUrlParts.pathname
                : url.pathname;
            const search = url.search
                ? baseUrlParts.search
                    ? `${baseUrlParts.search}&${url.search.slice(1)}`
                    : url.search
                : baseUrlParts.search;
            if (search) {
                path += search;
            }
            if (body && !headers['content-length']) {
                headers['content-length'] = String(Buffer.byteLength(body));
            }
            if (!headers['authorization']) {
                headers['authorization'] = `Basic ${btoa(
                    baseUrlParts.auth || 'root:'
github lovetheory / nkc2 / dataGenerator.js View on Github external
const arango = require('arangojs');
const aql = arango.aql;
const db = arango({
  url: 'http://root:@127.0.0.1:8529',
  databaseName: 'rescue',    //数据库名称
  arangoVersion: 20800
});

//05-18
/*
console.log('generating...');
console.log('creating collections...');

Promise.all([
  db.collection('invites').create(),
  db.collection('personalForums').create(),
  db.collection('usersSubscribe').create(),
  db.collection('usersBehavior').create()