grafana/public/app/plugins/datasource/postgres/sql_part.ts

138 lines
2.5 KiB
TypeScript
Raw Normal View History

import { SqlPartDef, SqlPart } from 'app/angular/components/sql_part/sql_part';
2018-01-30 15:57:38 -06:00
const index: any[] = [];
2018-01-30 15:57:38 -06:00
function createPart(part: any): any {
const def = index[part.type];
2018-01-30 15:57:38 -06:00
if (!def) {
2018-07-10 07:45:36 -05:00
return null;
2018-01-30 15:57:38 -06:00
}
2018-05-21 04:10:00 -05:00
return new SqlPart(part, def);
2018-01-30 15:57:38 -06:00
}
function register(options: any) {
2018-05-21 04:10:00 -05:00
index[options.type] = new SqlPartDef(options);
2018-01-30 15:57:38 -06:00
}
register({
2018-03-03 13:57:00 -06:00
type: 'column',
style: 'label',
2018-03-03 13:57:00 -06:00
params: [{ type: 'column', dynamicLookup: true }],
2018-01-30 15:57:38 -06:00
defaultParams: ['value'],
});
2018-06-30 04:11:34 -05:00
register({
type: 'expression',
style: 'expression',
label: 'Expr:',
params: [
{ name: 'left', type: 'string', dynamicLookup: true },
{ name: 'op', type: 'string', dynamicLookup: true },
{ name: 'right', type: 'string', dynamicLookup: true },
],
defaultParams: ['value', '=', 'value'],
});
register({
type: 'macro',
style: 'label',
label: 'Macro:',
params: [],
defaultParams: [],
});
2018-01-30 15:57:38 -06:00
register({
type: 'aggregate',
style: 'label',
params: [
{
name: 'name',
type: 'string',
options: ['avg', 'count', 'min', 'max', 'sum', 'stddev', 'variance'],
},
],
defaultParams: ['avg'],
2018-01-30 15:57:38 -06:00
});
register({
type: 'percentile',
label: 'Aggregate:',
style: 'label',
params: [
{
name: 'name',
type: 'string',
options: ['percentile_cont', 'percentile_disc'],
},
{
name: 'fraction',
type: 'number',
options: ['0.5', '0.75', '0.9', '0.95', '0.99'],
},
],
defaultParams: ['percentile_cont', '0.95'],
});
2018-01-30 15:57:38 -06:00
register({
type: 'alias',
style: 'label',
2018-01-30 15:57:38 -06:00
params: [{ name: 'name', type: 'string', quote: 'double' }],
defaultParams: ['alias'],
});
2018-03-04 03:18:11 -06:00
register({
type: 'time',
style: 'function',
2018-05-21 04:44:37 -05:00
label: 'time',
2018-03-04 03:18:11 -06:00
params: [
{
name: 'interval',
type: 'interval',
options: ['$__interval', '1s', '10s', '1m', '5m', '10m', '15m', '1h'],
},
{
name: 'fill',
type: 'string',
options: ['none', 'NULL', 'previous', '0'],
2018-03-04 03:18:11 -06:00
},
],
2018-06-30 04:11:34 -05:00
defaultParams: ['$__interval', 'none'],
2018-03-04 03:18:11 -06:00
});
2018-07-10 14:43:10 -05:00
register({
2018-07-28 14:30:08 -05:00
type: 'window',
2018-07-10 14:43:10 -05:00
style: 'label',
params: [
{
name: 'function',
type: 'string',
options: ['delta', 'increase', 'rate', 'sum'],
2018-07-10 14:43:10 -05:00
},
],
defaultParams: ['increase'],
});
2018-08-03 00:44:36 -05:00
register({
type: 'moving_window',
style: 'label',
label: 'Moving Window:',
params: [
{
name: 'function',
type: 'string',
options: ['avg'],
},
{
name: 'window_size',
type: 'number',
options: ['3', '5', '7', '10', '20'],
},
],
defaultParams: ['avg', '5'],
});
2018-01-30 15:57:38 -06:00
export default {
create: createPart,
};