Skip to content

Instantly share code, notes, and snippets.

@StarpTech
Last active April 11, 2018 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StarpTech/6f6285af7aad7dbbe223fff6d03cf47a to your computer and use it in GitHub Desktop.
Save StarpTech/6f6285af7aad7dbbe223fff6d03cf47a to your computer and use it in GitHub Desktop.
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