mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
38 lines
979 B
TypeScript
38 lines
979 B
TypeScript
import { ScopedVars } from '@grafana/data';
|
|
import { TemplateSrv } from '@grafana/runtime';
|
|
|
|
import { MySQLQuery } from './types';
|
|
|
|
export default class MySQLQueryModel {
|
|
target: Partial<MySQLQuery>;
|
|
templateSrv?: TemplateSrv;
|
|
scopedVars?: ScopedVars;
|
|
|
|
constructor(target: Partial<MySQLQuery>, templateSrv?: TemplateSrv, scopedVars?: ScopedVars) {
|
|
this.target = target;
|
|
this.templateSrv = templateSrv;
|
|
this.scopedVars = scopedVars;
|
|
}
|
|
|
|
// remove identifier quoting from identifier to use in metadata queries
|
|
unquoteIdentifier(value: string) {
|
|
if (value[0] === '"' && value[value.length - 1] === '"') {
|
|
return value.substring(1, value.length - 1).replace(/""/g, '"');
|
|
} else {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
quoteIdentifier(value: string) {
|
|
return '"' + value.replace(/"/g, '""') + '"';
|
|
}
|
|
|
|
quoteLiteral(value: string) {
|
|
return "'" + value.replace(/'/g, "''") + "'";
|
|
}
|
|
|
|
getDatabase() {
|
|
return this.target.dataset;
|
|
}
|
|
}
|