sql_part.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { SqlPartDef, SqlPart } from 'app/angular/components/sql_part/sql_part';
  2. const index: any[] = [];
  3. function createPart(part: any): any {
  4. const def = index[part.type];
  5. if (!def) {
  6. return null;
  7. }
  8. return new SqlPart(part, def);
  9. }
  10. function register(options: any) {
  11. index[options.type] = new SqlPartDef(options);
  12. }
  13. register({
  14. type: 'column',
  15. style: 'label',
  16. params: [{ type: 'column', dynamicLookup: true }],
  17. defaultParams: ['value'],
  18. });
  19. register({
  20. type: 'expression',
  21. style: 'expression',
  22. label: 'Expr:',
  23. params: [
  24. { name: 'left', type: 'string', dynamicLookup: true },
  25. { name: 'op', type: 'string', dynamicLookup: true },
  26. { name: 'right', type: 'string', dynamicLookup: true },
  27. ],
  28. defaultParams: ['value', '=', 'value'],
  29. });
  30. register({
  31. type: 'macro',
  32. style: 'label',
  33. label: 'Macro:',
  34. params: [],
  35. defaultParams: [],
  36. });
  37. register({
  38. type: 'aggregate',
  39. style: 'label',
  40. params: [
  41. {
  42. name: 'name',
  43. type: 'string',
  44. options: ['avg', 'count', 'min', 'max', 'sum', 'stddev', 'variance'],
  45. },
  46. ],
  47. defaultParams: ['avg'],
  48. });
  49. register({
  50. type: 'alias',
  51. style: 'label',
  52. params: [{ name: 'name', type: 'string', quote: 'double' }],
  53. defaultParams: ['alias'],
  54. });
  55. register({
  56. type: 'time',
  57. style: 'function',
  58. label: 'time',
  59. params: [
  60. {
  61. name: 'interval',
  62. type: 'interval',
  63. options: ['$__interval', '1s', '10s', '1m', '5m', '10m', '15m', '1h'],
  64. },
  65. {
  66. name: 'fill',
  67. type: 'string',
  68. options: ['none', 'NULL', 'previous', '0'],
  69. },
  70. ],
  71. defaultParams: ['$__interval', 'none'],
  72. });
  73. export default {
  74. create: createPart,
  75. };