How to use the arangojs.aql function in arangojs

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 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 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()
github iyobo / jollofjs / packages / jollof-data-arangodb / jollofDataArangoDB.js View on Github external
constructor(options) {

        this.connectionOptions = options || {};

        this.convertConditionsFromJollof = convertConditionsFromJollof;
        this.convertToJollof = convertToJollof;

        this.arangojs = arangojs;
        this.aql = arangojs.aql;
    }
github iyobo / jollofjs / packages / jollof-data-arangodb / util / conversionUtil.js View on Github external
/**
 * Created by iyobo on 2017-05-02.
 */
const idField = '_key';
const assert = require('assert');
const aql = require('arangojs').aql;
const util = require('util')
const moment = require('moment')

function convertComp(comp) {

    let symbol = '';

    switch (comp) {

        case '=':
            symbol = '==';
            break;
        case '!=':
            symbol = '!=';
            break;
        case '>':
github iyobo / jollofjs / packages / jollof-data-arangodb / jollofDataArangoDB.js View on Github external
/**
 * Created by iyobo on 2016-10-30.
 */
const _ = require('lodash');
const boom = require('boom')
const util = require('util')

const arangojs = require('arangojs');
const Database = arangojs.Database;
const aql = arangojs.aql;

const convertToJollof = require('./util/conversionUtil.js').convertToJollof;
const convertConditionsFromJollof = require('./util/conversionUtil.js').convertConditionsFromJollof;

const connPool = {};

/**
 * A factory of different ArangoDB connections based on URL
 * @param url
 * @returns {Promise<*>}
 */
async function getConnection(url, opts = {}) {
    try {
        const dbName = opts.databaseName;
        if (!dbName || dbName === '')
            throw boom.badImplementation('jollof-data-arangodb: databaseName config is required', { url, opts })
github lovetheory / nkc2 / nkc_modules / query_functions.js View on Github external
var moment = require('moment');
const privateSettings = require('./private_settings');
var settings = require('./server_settings.js');
var helper_mod = require('./helper.js')();
var bodyParser = require('body-parser');
const arango = require('arangojs');
const db = arango(privateSettings.arango);

var users = db.collection('users');

var express = require('express');
var api = express.Router();

var validation = require('./validation');

const aql = arango.aql;

var queryfunc = {};

queryfunc.db_init = function(){
  let p = [];
  var colArr = [
    'posts',
    'threads',
    'forums',
    'logs',
    'users',
    'users_personal',
    'counters',
    'resources',
    'questions',
    'answersheets',
github lovetheory / nkc2 / nkc_modules / layer / index.ts View on Github external
//query functions
//equivalent ORM-Layer
module.paths.push('./nkc_modules'); //enable require-ment for this path

var settings = require('server_settings.js');
var helper_mod = require('helper.js')();
var queryfunc = require('query_functions')
var apifunc = require('api_functions')
var validation = require('validation')
var rs = require('random-seed')
var AQL = queryfunc.AQL
var aql = require('arangojs').aql;
var db = require('arangojs')(settings.arango);

var permission = require('permissions')
var crypto =require('crypto')

var BaseDao = require('./BaseDao')

var layer = (function(){

  var layer = {}

  class ShortMessage extends BaseDao{
    constructor(key){
      super('sms',key)
    }