Skip to content

Commit 521dcc4

Browse files
committed
Merge pull request #2 from tempodb/delete_data
Delete data
2 parents f5cf2f4 + 760b0d3 commit 521dcc4

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

demo/tempodb-delete-demo.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
var TempoDBClient = require('tempodb').TempoDBClient;
3+
var tempodb = new TempoDBClient('your-api-key', 'your-api-secret');
4+
5+
var series_key = 'your-custom-key'
6+
// Delete a day's worth of data
7+
series_start_date = new Date('2012-11-13')
8+
series_end_date = new Date('2012-11-14')
9+
10+
var start_time = new Date();
11+
tempodb.delete_key(series_key, series_start_date, series_end_date, function(result){
12+
console.log(result.response + ': ' + JSON.stringify(result.body));
13+
console.log('Completed in', new Date() - start_time, 'ms\n');
14+
15+
});

tempodb.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var http = require('http');
22
var https = require('https');
33
var ID = 'TempoDB: ';
44

5-
var TempoDBClient = exports.TempoDBClient =
5+
var TempoDBClient = exports.TempoDBClient =
66
function(key, secret, options) {
77
/*
88
options
@@ -12,7 +12,7 @@ var TempoDBClient = exports.TempoDBClient =
1212
version (string)
1313
*/
1414
options = options || {};
15-
15+
1616
const HOST = 'api.tempo-db.com',
1717
PORT = 443,
1818
VERSION = 'v1',
@@ -42,6 +42,9 @@ TempoDBClient.prototype.call = function(method, path, body, callback) {
4242
json_body = JSON.stringify(body);
4343
this.headers['Content-Length'] = json_body.length;
4444
}
45+
else {
46+
this.headers['Content-Length'] = 0
47+
}
4548

4649
var options = {
4750
host: this.hostname,
@@ -57,7 +60,7 @@ TempoDBClient.prototype.call = function(method, path, body, callback) {
5760
//the listener that handles the response chunks
5861
res.addListener('data', function (chunk) {
5962
data += chunk.toString();
60-
});
63+
});
6164

6265
res.addListener('end', function() {
6366
result = '';
@@ -107,7 +110,7 @@ TempoDBClient.prototype.get_series = function(options, callback) {
107110
*/
108111
options = options || {};
109112
query_string = '?' + EncodeQueryData(options);
110-
113+
111114
return this.call('GET', '/series/' + query_string, null, callback);
112115
}
113116

@@ -212,6 +215,28 @@ TempoDBClient.prototype.increment_bulk = function(ts, data, callback) {
212215
return this.call('POST', '/increment/', body, callback);
213216
}
214217

218+
TempoDBClient.prototype.delete_id = function(series_id, start, end, callback) {
219+
var options = {
220+
start: ISODateString(start),
221+
end: ISODateString(end)
222+
}
223+
var query_string = '?' + EncodeQueryData(options);
224+
225+
return this.call('DELETE', '/series/id/'+series_id+'/data/'+query_string, null, callback);
226+
}
227+
228+
TempoDBClient.prototype.delete_key = function(series_key, start, end, callback) {
229+
var options = {
230+
start: ISODateString(start),
231+
end: ISODateString(end)
232+
}
233+
234+
var query_string = '?' + EncodeQueryData(options);
235+
236+
return this.call('DELETE', '/series/key/'+series_key+'/data/'+query_string, null, callback);
237+
}
238+
239+
215240
var EncodeQueryData = function(data) {
216241
var ret = [];
217242
for (var key in data) {

0 commit comments

Comments
 (0)