Frequently Asked Questions

What are the supported databases?

These are the currently supported database engines and their correspondent node-db driver:

We are actively working on supporting Oracle, MS SQL Server, PostgreSQL, and others. So keep coming back!

What license is node-db, and its drivers, released with?

node-db, its drivers, and any code that is part of the node-db project, is released under the MIT license, a license that lets you do pretty much anything with the code.

What are the chain methods? Why should I use them?

The chain methods are the Query methods that provide a wrapper around SQL statements / clauses (such as select(), insert(), delete(), and others). They are not mandatory, and you can simply use the Query.execute() method to run arbitrary SQL commands (see the question Why can’t I simply execute an SQL statement instead of suffering the overhead of the chain methods?).

Using the chain methods allows you to avoid the small but annoying differences that database vendors may have. For example, the following query:

this.query().
    select('*').
    from('users').
    where('id = ?', [ 99 ]).
    limit(10);

Will produce the same results on all of the supported databases, even when some of them may have a completely different implementation of the same SQL concepts (for example, the LIMIT statement varies between MySQL, MS SQL Server, and Oracle.)

Why can’t I simply execute an SQL statement instead of suffering the overhead of the chain methods?

You can use the Query.execute() method to manually execute arbitrary SQL statements (or alternatively, use Database.query() to create an instance of the Query class with the given SQL). For example:

var mysql = require('db-mysql');
new mysql.Database({
    hostname: 'localhost',
    user: 'user',
    password: 'password',
    database: 'test'
}).connect(function(error) {
    this.query().execute('SELECT * FROM users', function(error, rows, cols) {
        console.log(rows.length + ' ROWS found');
    });
});

Or alternatively:

var mysql = require('db-mysql');
new mysql.Database({
    hostname: 'localhost',
    user: 'user',
    password: 'password',
    database: 'test'
}).connect(function(error) {
    this.query('SELECT * FROM users').execute(function(error, rows, cols) {
        console.log(rows.length + ' ROWS found');
    });
});

However the chain methods prove themselves useful in many scenarios. See What are the chain methods? Why should I use them?

Does node-db offer connection pooling?

node-db is meant to provide a common framework for database bindings. On top of it, one can implement countless solutions, such as ORM (Object Relational Mapping) frameworks, connection pooling, etc.

As such, connection pooling is not part of the drivers themselves, but can be easily achieved with existing Node.js pooling solutions. As an example, here’s how you can pool your node-db connections with generic-pool.