Browse Source

Remove Query class

main
Haris Razis 4 years ago
parent
commit
470795ac8a
No known key found for this signature in database GPG Key ID: 86A4D290ED03FAB4
  1. 32
      web/src/Class/Query.ts

32
web/src/Class/Query.ts

@ -1,32 +0,0 @@
import { InfluxDB, QueryApi } from '@influxdata/influxdb-client';
export class Query {
private client!: InfluxDB;
private queryApi!: QueryApi;
constructor() {
this.initDatabase();
}
private initDatabase(): void {
this.client = new InfluxDB({
url: process.env.VUE_APP_DB_URL!,
token: process.env.VUE_APP_DB_TOKEN!,
});
this.queryApi = this.client.getQueryApi(process.env.VUE_APP_DB_ORG!);
}
async query(filter: string) {
const query = `from(bucket: "${process.env.VUE_APP_DB_BUCKET}") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "${filter}") |> aggregateWindow(every: 10m, fn: mean)`;
try {
const data = await this.queryApi.collectRows(query);
console.log('\nCollect ROWS SUCCESS');
return data;
} catch (error) {
console.error(error);
console.log('\nCollect ROWS ERROR');
return [{ Error: 'Error occured' }];
}
}
}
Loading…
Cancel
Save