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.
 
 

62 lines
1.7 KiB

import { Datasource, DatasourceConnector, QueryType } from '../connectors';
import { connectorFactory } from '../connectors/connector_factory';
import { QueryService } from '../services/query_service/base';
import { queryServiceFactory } from '../services/query_service/query_service_factory';
export class QueryConfig {
queryType: QueryType;
datasource: Datasource;
// TODO: Target type (depends on datasource type)
targets: any[];
private _datasourceConnector?: DatasourceConnector;
private _queryService?: QueryService;
constructor(queryType: QueryType, datasource: Datasource, targets: any[]) {
if(queryType === undefined) {
throw new Error('queryType is undefined');
}
if(datasource === undefined) {
throw new Error('datasource is undefined');
}
if(targets === undefined) {
throw new Error('targets is undefined');
}
this.queryType = queryType;
this.datasource = datasource;
this.targets = targets;
}
get datasourceConnector(): DatasourceConnector {
if(this._datasourceConnector === undefined) {
this._datasourceConnector = connectorFactory(this);
}
return this._datasourceConnector;
}
get queryService(): QueryService {
if(this._queryService === undefined) {
this._queryService = queryServiceFactory(this);
}
return this._queryService;
}
public toObject() {
return {
queryType: this.queryType,
datasource: this.datasource,
targets: this.targets,
};
}
static fromObject(obj: any): QueryConfig {
if(obj === undefined) {
throw new Error('obj is undefined');
}
return new QueryConfig(
obj.queryType,
obj.datasource,
obj.targets,
);
}
}