Introduction
This is a driver that control Cassandra database.
Installation
$ npm install node-cassandra-control
Usage
Setting server
You can setup your server in front of your require statement
var config_obj = "host": "your_database_server" "port": "database_port" "keyspace": "cassandra_keyspace"
For example:
var config_obj = "host": "127.0.0.1" "port": 9160 "keyspace": "clubond_test"
see some example in example
file
Require module
Require node-cassandra-control
and put your config_obj
in the parameter.
var node_control = config_obj;
Methods
Here are some methods that you can insert, get, delete your data by a very easy way.
getAllKeys
Simply get all from a column family
for example:
params = CF: "user" node_control;
In this example it will get all the Keys from user
column family.
getKeysByIdx
Get keys by second index
parameter and callback type
* @param {Object} params= { CF, idx_name, idx_id}
* @param {Function} callback
*
* @callback {object} rows
for example:
var params = CF: "user" idx_name: "account" idx_id: "info@fougood.com" node_control;
In this example it will get data from column family user
, second index name account
and second index id info@fougood.com
chkKeyExist
Check if the key exist
parameter and callback type
/**
*
* @method chkKeyExist
*
* @param {Object} params= { CF, key_id}
* @param {Function} callback
*
* @callback {object} rows
* @callback {Boolean} false if target KEY_ID not exist
*/
chkKeyExistByIdx
Check if the key exist in second index.
parameter and callback type
/**
*
* @method chkKeyExistByIdx
*
* @param {Object} params= { CF, idx_name, idx_id}
* @param {Function} callback
*
* @callback {object} rows
* @callback {Boolean} false if target not exist
*/
getHashByKey
Get colHash object in rows[0].
parameter and callback type
/**
* get colHash object in rows[0]
*
* @method getHashByKey
*
* @param {Object} params= { key_id, CF}
* @param {Function} callback
*
* @callback {object} rows[0].colHash
*
*/
getHashByKeyIn
Get rows use for the WHERE KEY IN query.
parameter and callback type
/**
* get rows
* use for the WHERE KEY IN query
*
* @method getHashByKeyIn
*
* @param {Object} params= { keyArr, CF}
* @param {Function} callback
*
* @callback {object} rows
*
*/
insertColtoKey
Insert a column KEY VALUE to a CF.
parameter and callback type
/**
* insert a column KEY VALUE to a CF
*
* @method insertColtoKey
*
* @param {Object} params= { key_id, CF, col_val, col_name}
* @param {Function} callback
*
* @callback {boolean}
*
*/
updateColtoKey
Update a column KEY VALUE to a CF, similar to INSERT.
parameter and callback type
/**
* UPDATE a column KEY VALUE to a CF, similar to INSERT
*
* @method updateColtoKey
*
* @param {Object} params= { key_id, CF, col_val, col_name}
* @param {Function} callback
*
* @callback {boolean}
*
*/
updateColstoKey
Update many cols to a CF KEY.
parameter and callback type
/**
* UPDATE **MANY cols to a CF KEY
*
* @method updateColstoKey
*
* @param {Object} params= { key_id, CF}
* @param {Object} object maps column names to column values, colObj= {name: "william", gender: "male"...}
* @param {Function} callback
*
* @callback {boolean}
*
*/
incrCounter
INCR a counter column value from CF, CFkey.
parameter and callback type
/**
* INCR A COUNTER column value from CF, CFkey
*
* @method incrCounter
*
* @param {Object} params= { CF, key_id, col_name}
* @param {Number} num how much u want to incr
* @param {Function} callback
*
* @callback {boolean}
*
*/
incrManyCols
INCR many counter column value from CF, CFkey.
parameter and callback type
/**
* INCR MANY COUNTER column value from CF, CFkey
*
* @method incrManyCols
*
* @param {Object} params= { CF, key_id}
* @param {Object} colObj = {down: 1, member: 3}
* @param {Function} callback
*
* @callback {boolean}
*
*/
incrAllByOne
INCR many counter column by one from CF, CFkey.
parameter and callback type
/**
* INCR MANY COUNTER column BY ONE from CF, CFkey
*
* @method incrAllByOne
*
* @param {Object} params= { CF, key_id}
* @param {Array} colArr = [down, upper]
* @param {Function} callback
*
* @callback {boolean}
*
*/
updateColsNull
Update many cols in a CF-key, which value is null use to insert in list CF.
parameter and callback type
/**
* UPDATE MANY COLS in a CF-key, which value is null
* use to insert in list CF
*
* @method updateColsNull
*
* @param {Object} params= { CF, key_id}
* @param {Array} id_arr = [id1, id2, id3...]
* @param {Function} callback
*
* @callback {boolean}
*
*/
deleteColFromKey
delete a column from CF, key.
parameter and callback type
/**
* DELETE A column from CF, key
*
* @method deleteColFromKey
*
* @param {Object} params= { CF, col_name, key_id}
* @param {Function} callback
*
* @callback {Boolean} success
*
*/
License
(The MIT License)
Copyright (c) 2013-2015 Clubond Inc. <info@fougood.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.