How can I use multiple databases in Total.js with help of SQL Agent?
SQL Agent is a simple Node.js module for working with RDBMS and NoSQL databases. It supports PostgreSQL, MySQL, SQL Server and MongoDB.
- supports mixing of RDMBS with NoSQL
Create a definition file e.g. database.js
:
const databases = {};
databases.helpdesk = require('sqlagent/pg').connect('connetion-string-to-postgresql');
databases.eshop = require('sqlagent/mysql').connect('connetion-string-to-mysql');
databases.monitor = require('sqlagent/mongodb').connect('connetion-string-to-mongodb');
F.database = function(name) {
// returns SQL Agent instance
return databases[name]();
};
Usage in code:
var helpdesk = DB('helpdesk');
helpdesk.select('tbl_user').take(5);
helpdesk.exec(console.log);
var eshop = DB('eshop');
eshop.select('tbl_user').take(5);
eshop.exec(console.log);
var monitor = DB('monitor');
monitor.select('users').take(5);
monitor.exec(console.log);