sails-arangojs
Version:
A sails-arangojs adapter for Sails / Waterline
56 lines (52 loc) • 3.01 kB
JavaScript
// ███████╗██████╗ █████╗ ██╗ ██╗███╗ ██╗
// ██╔════╝██╔══██╗██╔══██╗██║ ██║████╗ ██║
// ███████╗██████╔╝███████║██║ █╗ ██║██╔██╗ ██║
// ╚════██║██╔═══╝ ██╔══██║██║███╗██║██║╚██╗██║
// ███████║██║ ██║ ██║╚███╔███╔╝██║ ╚████║
// ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═══╝
//
// ██████╗ ██████╗ ███╗ ██╗███╗ ██╗███████╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗
// ██╔════╝██╔═══██╗████╗ ██║████╗ ██║██╔════╝██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║
// ██║ ██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║
// ██║ ██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██║ ██║ ██║██║ ██║██║╚██╗██║
// ╚██████╗╚██████╔╝██║ ╚████║██║ ╚████║███████╗╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║
// ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
//
// Instantiate a new connection from the connection manager.
const Flaverr = require('flaverr');
const assert = require('assert');
module.exports = function getConnection({ manager }) {
// This is a no-op that just sends back the manager and `meta` that were passed in.
assert(
manager && manager.dbConnection,
'The datastore does not have a DB connection manager'
);
if (manager) {
// manager returns connection and aql
const {
dbConnection,
aql,
graph,
graphName,
graphEnabled,
Transaction,
dsName,
} = manager;
return {
dbConnection,
graphEnabled,
graphName,
graph,
aql,
Transaction,
dsName,
};
}
throw Flaverr(
{
code: 'E_GETTING_COMMECTION',
message: 'There are no active connections to the database',
},
new Error('Error getting an active connection')
);
};