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. Make sure you specify the NUODB_ROOT environment variable:

$ export NUODB_ROOT=/usr/local/nuodb

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

$ npm install db-nuodb

Connecting

var nuodb = require('db-nuodb');
    new nuodb.Database({
        hostname: 'localhost',
        user: 'user',
        password: 'password',
        database: 'test',
        schema: 'test'
    }).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: 'user',
        password: 'password',
        database: 'test',
        schema: 'test'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query().
            select('*').
            from('users').
            where('approved = ?', [ true ]).
            order({'created': 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: 'user',
        password: 'password',
        database: 'test',
        schema: 'test'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query('SELECT * FROM ' + this.name('users') + ' WHERE ' + this.name('name') + ' LIKE \'' + this.escape('%John%') + '\'').
            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: 'user',
        password: 'password',
        database: 'test',
        schema: 'test'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query().
            insert('users',
                ['name', 'created', 'role', 'approved'],
                ['Test User', {value: 'NOW', escape: false}, 'user', true]
            ).
            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: 'user',
        password: 'password',
        database: 'test',
        schema: 'test'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query().
            update('users').
            set({ 'name': 'New Name' }).
            where('id = ?', [ 1 ])
            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: 'user',
        password: 'password',
        database: 'test',
        schema: 'test'
    }).connect(function(error) {
        if (error) {
            return console.log('CONNECTION error: ' + error);
        }
        this.query().
            delete().
            from('users')
            where('id = ?', [ 1 ])
            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.