简体   繁体   中英

Using NodeJs Style function callbacks with ArangoJS 3.x

Is it possible to use NodeJs like function Callbacks with ArangoJs 3.x; I have seen that ArangoJs 3.x using .then method (promises).. But I am using NodeJs 4.4 .. so i can't use .then method there.. Can I use nodejs like function callbacks for arangojs 3.x ?

Quoting the ArangoJS github page :

// ES2015-style
import arangojs, {Database, aql} from 'arangojs';
let db1 = arangojs(); // convenience short-hand
let db2 = new Database();
let {query, bindVars} = aql`RETURN ${Date.now()}`;

// or plain old Node-style
var arangojs = require('arangojs');
var db1 = arangojs();
var db2 = new arangojs.Database();
var aql = arangojs.aql(['RETURN ', ''], Date.now());
var query = aql.query;
var bindVars = aql.bindVars;

// Using a complex connection string with authentication
let host = process.env.ARANGODB_HOST;
let port = process.env.ARANGODB_PORT;
let database = process.env.ARANGODB_DB;
let username = process.env.ARANGODB_USERNAME;
let password = process.env.ARANGODB_PASSWORD;
let db = arangojs({
  url: `http://${username}:${password}@${host}:${port}`,
  databaseName: database
});

// Using ArangoDB 2.8 compatibility mode
let db = arangojs({
  arangoVersion: 20800
});

Isn't that exactly what you were looking for?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM