Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clickhouse

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clickhouse - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

85

index.js

@@ -46,2 +46,5 @@ 'use strict';

getHost() {
return this.opts.url + ':' + this.opts.port;
}

@@ -60,3 +63,3 @@ /**

return this.opts.url + ':' + this.opts.port + '?' + querystring.stringify(params);
return this.getHost() + '?' + querystring.stringify(params);
}

@@ -196,52 +199,36 @@

}
/**
* Insert rows by one query
* @param {String} tableName
* @param {Array} values List or values. Each value is array of columns
* @param {Function} cb
* @returns
*/
insertMany(tableName, values, cb) {
var url = `INSERT INTO ${tableName} FORMAT TabSeparated`;
request.post(
{
url : this.getHost() + '?query=' + url,
body : values
.map(i => i.join('\t'))
.join('\n'),
headers : {
'Content-Type': 'text/plain'
}
},
function (error, response, body) {
if ( ! error && response.statusCode == 200) {
cb(null, body);
} else {
return cb(error || body);
}
}
);
}
}
module.exports = ClickHouse;
//Example
/*
var async = require('async');
var query = 'SELECT FlightDate, DestCityName, AirlineID, DestStateFips FROM ontime LIMIT 10';
var ch = new ClickHouse();
async.series(
[
function (cb) {
// single query
ch.query(query, function (err, rows) {
console.log(err, rows);
cb();
});
},
function (cb) {
var count = 0;
// query with data streaming
ch.query(query)
.on('data', function (data) {
console.log('ch data', data);
if (++count % 1000 == 0) console.log('count', count);
})
.on('error', function (err) {
console.log('ch error', err);
process.exit();
})
.on('end', function () {
console.log('ch end', count);
cb();
});
}
],
function () {
process.exit();
}
);
*/
module.exports = ClickHouse;

@@ -86,7 +86,7 @@ {

"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"readme": "README.md",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.0.2",
"version": "1.0.3",
"repository" : {

@@ -93,0 +93,0 @@ "type" : "git",

# clickhouse
NodeJS client for ClickHouse
NodeJS client for [ClickHouse](https://clickhouse.yandex/).
Send query over HTTP interface.
Example:
```javascript
var async = require('async');
var query = 'SELECT FlightDate, DestCityName, AirlineID, DestStateFips FROM ontime LIMIT 10';
var ch = new ClickHouse({
url : 'http://localhost',
port : 8123,
debug : false
});
async.parallel(
[
function (cb) {
// single query
ch.query(query, function (err, rows) {
console.log('single query result', err, rows);
cb(err);
});
},
function (cb) {
var error = null;
// query with data streaming
ch.query(query)
.on('data', function (data) {
console.log('data', data);
})
.on('error', function (err) {
error = err;
})
.on('end', function () {
cb(error);
});
},
function(cb) {
// insert rows
ch.insertMany(
'sometable',
[
// row 1
[
'2016-07-02',
'1',
12
],
// row 2
[
'2016-07-03',
'2',
30
]
],
function(err, result) {
if (err) return cb(err);
console.log('insert result', result);
}
);
}
],
function () {
process.exit();
}
);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc