https://github.com/mrquincle/cassandrajsconnector
https://github.com/mrquincle/cassandrajsconnector
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mrquincle/cassandrajsconnector
- Owner: mrquincle
- Created: 2019-06-26T08:36:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-08T19:09:17.000Z (over 6 years ago)
- Last Synced: 2025-01-22T09:42:53.121Z (9 months ago)
- Language: JavaScript
- Size: 52.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cassandra JS-connector
TLS client to talk with the Cassandra server
## Installation
Install Node.JS (Compatible Version 10.15.0)https://nodejs.org/en/
Run following command in this directory
```
npm install
```## Usage
Run the examples in the ./examples folder using:
```
node connect.js
```## API
Import the library
``` javascript
// import library
let CassandraAPI = require("../middleware/cassandraAPI")// create a CassandraAPI instance
const client = new CassandraAPI();// connect
client.connect(options);
```CassandraAPI has a number of methods available:
***`connect(options)`***
> @param **options** : [TLS Server options documentation](https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options "TLSServer Documentation")
> ``` js
> options = {
> ca: [buffer],
> key: buffer,
> cert: buffer,
> host: string,
> port: number,
> rejectUnauthorized: boolean,
> requestCert: boolean
> }
> ```
> @returns void### Select
***`getEnergyUsage(stoneIds = [string], beginTime = timestamp, endTime = timestamp)`***
> @param **stoneIds** *: array of strings; ‘12-byte ‘MongoDB ObjectID'*
> @param **beginTime** *: number; forms a range with endtime; format emitted by javascripts new Date().toValue()*
> @param **endTime** *: number; forms a range with beginTime; format emitted by javascripts new Date().toValue()*
> @returns **Promise** *: data json object*
> ```js
> {
> "startTime": timestamp, //optional
> "endTime": timestamp, //optional
> "interval": number , //optional
> "stones":[
> {
> "stoneID": string,
> "Data":[
> {
> "time": timestamp,
> "value":
> {
> "kWh" : number
> }
> },
> {
> "time": timestamp,
> "value":
> {
> "kWh" : number
> }
> }
> ]
> }
> ]
>}
>```***`getPowerUsage(stoneIds = [string], beginTime = timestamp, endTime = timestamp)`***
> @param **stoneIds** *: array of strings; ‘12-byte ‘MongoDB ObjectID'*
> @param **beginTime** *: number; forms a range with endtime; format emitted by javascripts new Date().toValue()*
> @param **endTime** *: number; forms a range with beginTime; format emitted by javascripts new Date().toValue()*
> @returns **Promise** *: data json object*
>```js
> {
> "startTime": timestamp, //optional
> "endTime": timestamp, //optional
> "interval": number, //optional
> "stones":[
> {
> "stoneID": string,
> "Data":[
> {
> "time": timestamp,
> "value":
> {
> "w": number,
> "pf": number
> }
> },
> {
> "time": timestamp,
> "value":
> {
> "w": number,
> "pf": number
> }
> }
> ]
> }
> ]
>}
>```## Delete
***`deleteEnergyUsage(stoneId = string , beginTime = timestamp, endTime = timestamp)`***
> @param **stoneId** *: string; ‘12-byte ‘MongoDB ObjectID'*
> @param **beginTime** *: number; forms a range with endtime; format emitted by javascripts new Date().toValue()*
> @param **endTime** *: number; forms a range with beginTime; format emitted by javascripts new Date().toValue()*
> @returns **Promise** *: json: number of successful deletions*
>```js
> {
> "deleted": number
>}
>```***`deleteEnergyUsage(stoneId = string , beginTime = timestamp, endTime = timestamp)`***
> @param **stoneId** *: string; ‘12-byte ‘MongoDB ObjectID'*
> @param **beginTime** *: uint32; forms a range with endtime; format emitted by javascripts new Date().toValue()*
> @param **endTime** *: uint32; forms a range with beginTime; format emitted by javascripts new Date().toValue()*
> @returns **Promise** *: json: number of successful deletions*
>```js
> {
> "deleted": number
>}
>```***`deleteAllUsageData(stoneId = string , beginTime = timestamp, endTime = timestamp)`***
> @param **stoneId** *: string; ‘12-byte ‘MongoDB ObjectID'*
> @param **beginTime** *: number; forms a range with endtime; format emitted by javascripts new Date().toValue()*
> @param **endTime** *: number; forms a range with beginTime; format emitted by javascripts new Date().toValue()*
> @returns **Promise** *: json: number of successful deletions*
>```js
> {
> "deleted": number
>}
>```***`insertEnergyUsage(stoneId = string, data = array of timeAndEnergy)`***
> @param **stoneId** *: string; ‘12-byte ‘MongoDB ObjectID'*
> @param **data** *: array of timeAndEnergy; {time = timestamp, w = number, pf = number }; time = number, format emitted by javascripts new Date().toValue(); w(watt) = number between 0 and 3600; pf(powerfactor) = number between -1 and 1*
> @returns **Promise** *: json: number of successful inserts*
>```js
> {
> "inserted": number
>}
>```***`insertEnergyUsage(stoneId = string, data = array of timeAndPower)
`***
> @param **stoneId** *: string; ‘12-byte ‘MongoDB ObjectID'*
> @param **data** *: array of timeAndPower; {time = timestamp, kWh = number };time = number, format emitted by javascripts new Date().toValue(); kWh(kilowatt hour) = number between 0 and infinity;
> @returns **Promise** *: json: number of successful inserts*
>```js
> {
> "inserted": number
>}
>```## Testing