Class: Db

Db

Class representing a database.

new Db(name, version, config)

db.js, line 49
Name Type Description
name string The name of the database.
version number optional The version of the database.
config object | Array.<string> The collections configuration.
Examples
let db = new zango.Db('mydb', {
    // Define collection.
    col1: {
        // Create index if it doesn't already exist.
        index1: true,

        // Delete index from pre-existing database.
        index2: false
    },

     // Define collection with indexes.
    col2: ['index1', 'index2'],

    // Define collection without indexes.
    col3: true,

    // Delete collection from pre-existing database.
    col4: false
});
// Define collections without indexes.
let db = new zango.Db('mydb', ['col1', 'col2']);

Members

namestring

The name of the database.

versionnumber

The version of the database.

Methods

close()

db.js, line 217
Close the connection if it is open.

collection(name){Collection}

db.js, line 186
Retrieve a Collection instance.
Name Type Description
name string The name of the collection.
Returns:
Type Description
Collection
Example
let col = db.collection('mycol');

drop(cb){Promise}

db.js, line 235
Delete the database, closing the connection if it is open.
Name Type Description
cb function optional The result callback.
Returns:
Type Description
Promise
Example
db.drop((error) => {
    if (error) { throw error; }
});

open(cb){Promise}

db.js, line 201
Open connection to the database.
Name Type Description
cb function optional The result callback.
Returns:
Type Description
Promise

Events

blocked

db.js, line 8
Db blocked event.
Example
db.on('blocked', () => {
    console.log('database version cannot be upgraded');
});