Skip to content

Commit

Permalink
feat: add function dropShard (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
Infern1 authored and bencevans committed Jul 1, 2019
1 parent fa24617 commit 4772578
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/index.ts
Expand Up @@ -1122,6 +1122,27 @@ export class InfluxDB {
);
}

/**
* Drops a shard with the provided number.
* @param shard_id
* @return
* @example
* influx.dropShard(3)
*/
public dropShard(shard_id: number): Promise<void> {
return this._pool
.json(
this._getQueryOpts(
{
q: `drop shard ${shard_id}`
},
'POST',
),
)
.then(assertNoErrors)
.then(() => undefined);
}

/**
* WritePoints sends a list of points together in a batch to InfluxDB. In
* each point you must specify the measurement name to write into as well
Expand Down
11 changes: 11 additions & 0 deletions test/integrate/data.test.ts
Expand Up @@ -58,6 +58,17 @@ describe('data operations', () => {
.then(() => db.getSeries())
.then(res => expect(res).to.not.contain('h2o_quality,location=coyote_creek,randtag=1'));
});
it('drops shard', () => {
let first_shard_number = 0;
return db
.showShards('influx_test_db')
.then(res => {
first_shard_number = res[0].id;
})
.then(() => db.dropShard(first_shard_number))
.then(() => db.showShards('influx_test_db'))
.then(res => expect(res[0].id).to.not.equal(first_shard_number));
});

it('gets measurements', () => {
return db.getMeasurements().then(res => expect(res).to.deep.equal(['h2o_feet', 'h2o_quality']));
Expand Down
5 changes: 5 additions & 0 deletions test/unit/influx.test.ts
Expand Up @@ -228,6 +228,11 @@ describe('influxdb', () => {
influx.dropDatabase('f"oo');
});

it('.dropShard()', () => {
expectQuery('json', 'drop shard 1');
influx.dropShard(1);
});

it('.getDatabaseNames()', () => {
expectQuery('json', 'show databases', 'GET', dbFixture('showDatabases'));
return influx.getDatabaseNames().then(names => {
Expand Down

0 comments on commit 4772578

Please sign in to comment.