UNPKG

dl-nosqldb

Version:

DL nosqldb library

223 lines (179 loc) 4.93 kB
# **dl-nosqldb** The library dl-nosqldb allows to connect with Cassandra database and manage data.<br><br> ### Install ```javascript 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 ** ```javascript '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 ** ```javascript '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: ```javascript 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: ```javascript 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: ```javascript nosqldb.multiGet([ { "table": "table_name", "key": ['col_1_value', 'col_2_value'] }, { "table": "table_name2", "key": ['col_1_value2', 'col_2_value2'] } ]); ``` ```javascript 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: ```javascript nosqldb.insert("table_name", ['col_1_value', 'col_2_value'], { "col_3": "test", "col_4": "test" }); ``` ```javascript 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: ```javascript 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: ```javascript 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: ```javascript 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: ```javascript 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"] } } ]); ```