Skip to content

Instantly share code, notes, and snippets.

@StarpTech StarpTech/arangodb.js
Last active Apr 11, 2018

Embed
What would you like to do?
Manage Multi-Tenancy in Arangojs
// initialize
// The maximum number of requests is equal to
// maxSockets * 2 with keepAlive: true or equal to maxSockets with keepAlive: false.
const arangodb = new Arangojs.Database({
url: "http://localhost:8529", // Base URL of the ArangoDB server or list of server URLs.
agentOptions: {
maxSockets: 100,
keepAlive: true
},
loadBalancingStrategy: 'ROUND_ROBIN'
})
// In your request handler you can set the correct database
// Any request is queued in form of command pattern https://github.com/arangodb/arangojs/blob/master/src/connection.ts#L269
// Due to the fact that node.js is single threaded and the item is pushed synchronously to the queue we don't have to worry about race conditions.
// We will use one connection: https://github.com/arangodb/arangojs/blob/master/src/database.ts#L50
async function handler(req, resp) {
let db = arangodb.useDatabase('testDb')
await db.listDatabases()
await db
.query({
query: "RETURN @value",
bindVars: { value: now }
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.