View on GitHub

db-nuodb

NuoDB database bindings for Node.js

Download this project as a .zip file Download this project as a tar.gz file

Welcome to the db-nuodb Project

This project provides a Node.js database driver for the NuoDB database.

Install

Before proceeding with installation, make sure you have NuoDB installed on your system. Specifically, you should have access to the libNuoRemote binary. If your NuoDB installation is not under the default location (usually /opt/nuodb), then you MUST specify the NUODB_HOME environment variable:

$ export NUODB_HOME=/usr/local/nuodb # ignore this if using default location

And now for the actual install, having set up your environment, above:

$ npm install db-nuodb

Connecting

You should have a running NuoDB Database to try these examples. But don't fret, we can get a running NuoDB Database running by using a quickstart script which is shipped alongside NuoDB.

$ /opt/nuodb/run-quickstart 

If you already have a running NuoDB Database simply correct the credentials used below.

var nuodb = require('db-nuodb');
    new nuodb.Database({
        hostname: 'localhost',
        user: 'dba',
        password: 'goalie',
        database: 'test',
        schema: 'hockey'
    }).on('error', function(error) {
        console.log('ERROR: ' + error);
    }).on('ready', function(server) {
        console.log('Connected to ' + server.hostname + ' (' + server.version + ')');
    }).connect();

Querying

var nuodb = require('db-nuodb');
    new nuodb.Database({
        hostname: 'localhost',
        user: 'dba',
        password: 'goalie',
        database: 'test',
        schema: 'hockey'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query().
            select('*').
            from('hockey').
            where('position = ?', [ 'Defense' ]).
            order({'number': false}).
            execute(function(error, rows, cols) {
                    if (error) {
                            console.log('ERROR: ' + error);
                            return;
                    }
                    console.log(rows.length + ' ROWS found');
            });
    });

Using Manual Queries

In the example below, usage of Database.name() and Database.escape() is not mandatory, but recommended.

var nuodb = require('db-nuodb');
    new nuodb.Database({
        hostname: 'localhost',
        user: 'dba',
        password: 'goalie',
        database: 'test',
        schema: 'hockey'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query('SELECT * FROM ' + this.name('hockey') + ' WHERE ' + this.name('name') + ' LIKE \'A%\'').
            execute(function(error, rows, cols) {
                    if (error) {
                            console.log('ERROR: ' + error);
                            return;
                    }
                    console.log(rows.length + ' ROWS found');
            });
    });

Inserting

var nuodb = require('db-nuodb');
    new nuodb.Database({
        hostname: 'localhost',
        user: 'dba',
        password: 'goalie',
        database: 'test',
        schema: 'hockey'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query().
            insert('hockey',
                ['Number', 'Name', 'Position'],
                [33,'Test User', 'TESTER']
            ).
            execute(function(error, result) {
                    if (error) {
                            console.log('ERROR: ' + error);
                            return;
                    }
                    console.log('GENERATED id: ' + result.id);
            });
    });

Updating

var nuodb = require('db-nuodb');
    new nuodb.Database({
        hostname: 'localhost',
        user: 'dba',
        password: 'goalie',
        database: 'test',
        schema: 'hockey'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query().
            update('hockey').
            set({ 'name': 'New Name Tester' }).
            where('id = ?', [ 24 ]).
            execute(function(error, result) {
                    if (error) {
                            console.log('ERROR: ' + error);
                            return;
                    }
                    console.log('RESULT: ', result);
            });
    });

Deleting

var nuodb = require('db-nuodb');
    new nuodb.Database({
        hostname: 'localhost',
        user: 'dba',
        password: 'goalie',
        database: 'test',
        schema: 'hockey'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query().
            delete().
            from('hockey').
            where('name like ? ', [ 'Test%' ]).
            execute(function(error, result) {
                    if (error) {
                            console.log('ERROR: ' + error);
                            return;
                    }
                    console.log('RESULT: ', result);
            });
    });

Documentation

For more in depth documentation check node-db’s documentation.

Authors and Contributors

Robert Buck (@rbuck).

Support or Contact

You can report bugs on the project issues page.