dl-nosqldb

DL nosqldb library

Usage no npm install needed!

<script type="module">
  import dlNosqldb from 'https://cdn.skypack.dev/dl-nosqldb';
</script>

README

dl-nosqldb

The library dl-nosqldb allows to connect with Cassandra database and manage data.

Install

npm install dl-nosqldb

const NoSqlDb = require(dl-nosqldb);

API

http://doc.grupa.onet/display/NOS/API+Reference

This library is compatible with callback and promise invoke. Below there are examples of usage:

➦ **Example of usage with promise **

'use strict';

const Nosqldb = require('dl-nosqldb').Nosqldb;

const nosqldb = new Nosqldb(datasource);
let key = [namespaId];
let colValues = {
    name: 'nosql',
    deleted: false
};

nosqldb.insert(table, key, colValues)
    .then((data) => {
        return callback(null, data);
    })
    .catch((err) =>{
        return callback(err);
    });

➦ **Example of useage with callback **

'use strict';

const Nosqldb = require('dl-nosqldb').Nosqldb;

const nosqldb = new Nosqldb(datasource);
let key = [namespaId];
let colValues = {
    name: 'nosql',
    deleted: false
};

nosqldb.insert(table, key, colValues, {}, callback);

Available methods

get (table, key[, options = {}, cb = null]) {

return data by key

options:
  • columns
  • consistency
example:
   nosqldb.get('table_name', ['col_1_value', 'col_1_value'])

getRange (table, keyPrefix, options = {}, cb = null)

return data by part of key

options:
  • rangeLt
  • rangeLte
  • rangeGt
  • rangeGte
  • columns
  • orderBy
  • limit
  • consistency
example:
   nosqldb.getRange('table_name', ['col_1_value']')

multiGet (items, options = {}, cb = null)

return data from many get query, optionaly limitation to the values of defined columns

options:
  • consistency
example:
   nosqldb.multiGet([
        {
            "table": "table_name",
            "key":  ['col_1_value', 'col_2_value']
        },
        {
            "table": "table_name2",
            "key":  ['col_1_value2', 'col_2_value2']
        }
    ]);
   nosqldb.multiGet([
        {
            "table": "table_name",
            "key":  ['col_1_value', 'col_2_value'],
            "columns": ["col_2", "col_3", "col_4"]
        },
        {
            "table": "table_name2",
            "key":  ['col_1_value2', 'col_2_value2'],
            "columns": ["col_2", "col_3", "col_4"]
        }
    ]);

insert (table, key, columns, options = {}, cb = null)

added new element

options:
  • ttl
  • consistency
example:
   nosqldb.insert("table_name", ['col_1_value', 'col_2_value'], { "col_3": "test", "col_4": "test" });
   nosqldb.insert("table_name", ['col_1_value', 'col_2_value'], { "col_3": "test", "col_4": "test" }, {"ttl": 200});

multiInsert (items, options = {}, cb = null)

added new elements in one query

options:
  • consistency
example:
    nosqldb.multiInsert( [ 
        {
            "table": "table_name",
            "key": ['col_1_value', 'col_2_value'],
            "columns": { "col_3": "test", "col_4": "test" }
        },
        {
            "table": "table_name",
            "key": ['col_1_value2', 'col_2_value2'],
            "columns": { "col_3": "test", "col_4": "test" },
            "ttl": 200
        }
    ]);

update (table, key, assignments, options = {}, cb = null)

update data by key

options:
  • ttl
  • consistency
example:
   nosqldb.update("table_name", ['col_1_value', 'col_2_value'], { "col_3": [ "=", "testnew"]});

remove (table, key, options = {}, cb = null)

remove data by key

options:
  • columns
  • consistency
example:
   nosqldb.remove("table_name", ['col_1_value', 'col_2_value']);

batch (operations, options = {}, cb = null)

execute list of operations (insert or remove only)

options:
  • consistency
example:
   nosqldb.batch([
       {
           "name": "insert",
           "params": {
                "table": "table_name",
                "key": ["col_1_value", "col_2_value"],
                "columns": { "col_3": "test", "col_4": "test" },
                "ttl": 200
           }
       },
       {
           "name": "insert",
           "params": {
                "table": "table_name",
                "key": ["col_1_value2", "col_2_value2"],
                "columns": { "col_3": "test", "col_4": "test" }
           }
       },
       {
           "name": "remove
           "params": {
                "table": "table_name",
                "key": ["col_1_value", "col_2_value"]
           }
       }
   ]);