You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
794 B
24 lines
794 B
2 years ago
|
import { QueryService } from './base';
|
||
|
import { DirectQueryService } from './direct';
|
||
|
import { GrafanaQueryService } from './grafana';
|
||
|
import { QueryType } from '../../connectors';
|
||
|
import { QueryConfig } from '../../models/query_config';
|
||
|
|
||
|
|
||
|
export function queryServiceFactory(
|
||
|
queryConfig: QueryConfig,
|
||
|
): QueryService {
|
||
|
const classMap = {
|
||
|
[QueryType.DIRECT]: DirectQueryService,
|
||
|
[QueryType.GRAFANA]: GrafanaQueryService,
|
||
|
};
|
||
|
const queryType = queryConfig.queryType;
|
||
|
const datasource = queryConfig.datasource;
|
||
|
if(classMap[queryType] === undefined) {
|
||
|
console.error(`Queries of type ${queryType} are not supported currently`);
|
||
|
throw new Error(`Queries of type ${queryType} are not supported currently`);
|
||
|
} else {
|
||
|
return new classMap[queryType](datasource);
|
||
|
}
|
||
|
}
|