Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
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);
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)
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()
constructor(options) {
this.connectionOptions = options || {};
this.convertConditionsFromJollof = convertConditionsFromJollof;
this.convertToJollof = convertToJollof;
this.arangojs = arangojs;
this.aql = arangojs.aql;
}
/**
* 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 '>':
/**
* 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 })
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',
//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)
}