DBMS / 02. Usage
Updated: 13. November 2018
Author: Peter Širka

02. Usage

Professional Support Chat with contributors

This module works with existing database NPM modules.

Initialization

  • this module can work with multiple database engines together

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 params

Connection string can contain additional params for some databases.

postgresql://user:pass@localhost:5432/dbname1?param=1&param=2

Param: max

Max pools for pooling. This param supports PostgreSQL only. Default: 4.

?max=4

Param: min

Min pools for pooling. This param supports PostgreSQL only. Default: 2.

?min=2

Param: 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

Param: pooling

Enables pooling. This param supports PostgreSQL only. Default: true.

// Disabling via:
?pooling=false

// or

?pooling=0

Param: ssl

Enables SSL secured connection. By default is ssl disabled.

?ssl=1
// or
?ssl=true

Param: timeout

Idle timeout in milliseconds. This param supports PostgreSQL only. Default: 1000.

?timeout=1000