From 68ddd98e7ddb263564253d39438104f8ff6d77fc Mon Sep 17 00:00:00 2001 From: q_no Date: Thu, 30 Jan 2014 09:57:42 +0100 Subject: [PATCH 1/8] added .idea (phpstorm) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 516e9eb7..06c29bb3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules temp.js coverage +.idea \ No newline at end of file From 5b93a51f52bc79369dcd7ab20f8b9121797de324 Mon Sep 17 00:00:00 2001 From: q_no Date: Thu, 30 Jan 2014 09:58:07 +0100 Subject: [PATCH 2/8] fixed uri for getDataBaseNames() --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 9b42972c..7720d096 100644 --- a/index.js +++ b/index.js @@ -63,7 +63,7 @@ InfluxDB.prototype.deleteDatabase = function(databaseName, callback) { InfluxDB.prototype.getDatabaseNames = function(callback) { request({ - url: this.url('dbs'), + url: this.url('db'), json: true }, this._parseCallback(function(err, dbs) { if(err) { From 21e57c2c2694871dc613164a8d299b8bfa167fec Mon Sep 17 00:00:00 2001 From: q_no Date: Thu, 30 Jan 2014 10:12:45 +0100 Subject: [PATCH 3/8] added getSeriesNames() function - return all series from a given database - requires database admin privileges --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index 7720d096..979c0887 100644 --- a/index.js +++ b/index.js @@ -73,6 +73,21 @@ InfluxDB.prototype.getDatabaseNames = function(callback) { })); }; + +InfluxDB.prototype.getSeriesNames = function(databaseName,callback) { + request({ + url: this.url('db/' + databaseName + '/series', {q: 'list series'}), + json: true + }, this._parseCallback(function(err, series) { + if(err) { + return callback(err, series); + } + return callback(err, _.map(series, function(series) { return series.name; })); + })); +}; + + + InfluxDB.prototype.createUser = function(databaseName, username, password, callback) { request.post({ url: this.url('db/' + databaseName + '/users'), From b87e9fd3da27d6d0e68aeaabbca4ba8cb487ce36 Mon Sep 17 00:00:00 2001 From: q_no Date: Thu, 30 Jan 2014 10:13:32 +0100 Subject: [PATCH 4/8] updated docs --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 80c994aa..cfc953bb 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,49 @@ var influx = require('influx'); var client = influx(host, port, username, password, database); ``` + +## Functions + +```js +createDatabase(databaseName, callback) { } +``` +Creates a new database - requires cluster admin privileges + +```js +deleteDatabase(databaseName, callback) { } +``` +Deletes a database - requires cluster admin privileges + +```js +getDatabaseNames(callback) { } +``` +Returns array of database names - requires cluster admin privileges + +```js +getSeriesNames(databaseName, callback) { } +``` +Returns array of series names from given dataBase- requires database admin privileges + + +```js +createUser(databaseName, username, password, callback) { } +``` +Creates a new database user - requires cluster admin privileges + +```js +writePoint(seriesName, values, options, callback) { } +``` +Writes point to database - requires database user privileges + +```js +readPoints(query, callback) { } +``` +Reads points from a database - requires database user privileges + + + + + As Jeff Atwood puts it... [Read the source, Luke](http://www.codinghorror.com/blog/2012/04/learn-to-read-the-source-luke.html). If you're still stuck, read the `./examples/*` files and the `./test.js` file. From e7b368ae882739c50cc722bdfa153c795a7c9857 Mon Sep 17 00:00:00 2001 From: q_no Date: Thu, 30 Jan 2014 10:16:14 +0100 Subject: [PATCH 5/8] fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cfc953bb..b21ba3fd 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Returns array of database names - requires cluster admin privileges ```js getSeriesNames(databaseName, callback) { } ``` -Returns array of series names from given dataBase- requires database admin privileges +Returns array of series names from given database - requires database admin privileges ```js From 3b676f5b199cbc0ec6ca6dc56c4a18958b173ff9 Mon Sep 17 00:00:00 2001 From: q_no Date: Thu, 30 Jan 2014 11:01:52 +0100 Subject: [PATCH 6/8] added pool option to writePoints() - setting the pool to false can prevent node from running out of TCP sockets while inserting a large number of datapoins in a batch process --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 979c0887..e2fc7664 100644 --- a/index.js +++ b/index.js @@ -127,6 +127,7 @@ InfluxDB.prototype.writePoint = function(seriesName, values, options, callback) headers: { 'content-type': 'application/json' }, + pool : options.pool ? options.pool : {}, body: JSON.stringify(data) }, this._parseCallback(callback)); }; From 7766340dc478e5af69dfdc072fd72b98a6a39a24 Mon Sep 17 00:00:00 2001 From: q_no Date: Thu, 30 Jan 2014 13:42:49 +0100 Subject: [PATCH 7/8] fixed createUser function. InfluxDB API parameter changed from "username" to "name --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e2fc7664..e6efb897 100644 --- a/index.js +++ b/index.js @@ -89,13 +89,13 @@ InfluxDB.prototype.getSeriesNames = function(databaseName,callback) { InfluxDB.prototype.createUser = function(databaseName, username, password, callback) { - request.post({ + request.post({ url: this.url('db/' + databaseName + '/users'), headers: { 'content-type': 'application/json' }, body: JSON.stringify({ - username: username, + name: username, password: password }, null) }, this._parseCallback(callback)); From 4f52e696a35b8fb88a1f3df2b79fd3884c8a352f Mon Sep 17 00:00:00 2001 From: q_no Date: Thu, 30 Jan 2014 14:29:53 +0100 Subject: [PATCH 8/8] fixed pool option in writePoint --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e6efb897..ffd22b87 100644 --- a/index.js +++ b/index.js @@ -127,7 +127,7 @@ InfluxDB.prototype.writePoint = function(seriesName, values, options, callback) headers: { 'content-type': 'application/json' }, - pool : options.pool ? options.pool : {}, + pool : 'undefined' != typeof options.pool ? options.pool : {}, body: JSON.stringify(data) }, this._parseCallback(callback)); };