Last active
April 11, 2018 09:24
-
-
Save StarpTech/6f6285af7aad7dbbe223fff6d03cf47a to your computer and use it in GitHub Desktop.
Manage Multi-Tenancy in Arangojs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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