This module works with existing database NPM modules.
Create a definition file db.js
:
const dbms = require('dbms');
// dbms.init([alias], connection_string);
// @alias {String} Optional, alias for connection string (default: 'default')
// @connection_string {String} A connection string to DB
dbms.init('postgresql://user:pass@localhost:5432/dbname1');
dbms.init('mypg', 'postgresql://user:pass@localhost:5432/dbname2'); // with a name
dbms.init('mynosql', 'nosql'); // It uses Total.js NOSQL
dbms.init('mytable', 'table'); // It uses Total.js TABLE
Simple usage:
// DBMS is a global variable for the entire project
var db = DBMS();
db.find('table_name').take(100).callback(console.log);
db.find('mypg/table_name').take(100).callback(console.log);
db.find('mynosql/users').take(100).callback(console.log);
db.find('mytable/users').take(100).callback(console.log);
Connection string can contain additional params for some databases.
postgresql://user:pass@localhost:5432/dbname1?param=1¶m=2
max
Max pools for pooling. This param supports PostgreSQL only. Default: 4
.
?max=4
min
Min pools for pooling. This param supports PostgreSQL only. Default: 2
.
?min=2
native
Enables a native driver for DB engine. Currently only PostgreSQL
supports native driver. Just follow steps on Node PostgreSQL C/C++ Binding. By default is native
binding disabled.
Possible values for connection string:
?native=1
// or
?native=true
pooling
Enables pooling. This param supports PostgreSQL only. Default: true
.
// Disabling via:
?pooling=false
// or
?pooling=0
ssl
Enables SSL secured connection. By default is ssl
disabled.
?ssl=1
// or
?ssl=true
timeout
Idle timeout in milliseconds. This param supports PostgreSQL only. Default: 1000
.
?timeout=1000