Skip to content

Commit 6c0136d

Browse files
author
Daniel Arrizza
committed
add WHERE with REGEXP
1 parent e2e534c commit 6c0136d

File tree

5 files changed

+49
-21
lines changed

5 files changed

+49
-21
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ Create AppD dashboards at lightning speed with a query language
1616
- [x] headers
1717
- [x] default metric format strings
1818
- [x] AS
19+
- [x] WHERE on a name/label with = or REGEX
20+
- [] add tier to bts
1921
- [] add a title
2022
- [] more than just bts
21-
- [] WHERE on a name/label
22-
- [] WHERE operators (>, <, REGEX, etc.)
2323
- [] WHERE on metric values (current art > x)
24+
- [] WHERE OR operator and nesting
2425
- [] SORT BY
2526
- [] LIMIT
2627
- [] query autocomplete
@@ -29,11 +30,13 @@ Create AppD dashboards at lightning speed with a query language
2930
- [] specify dashboard name
3031
- [] create multiple dashboards at once
3132
- [] save queries
32-
- [] more metric types: browser, mobile, DB, SIM
33+
- [] more metric types: browser, mobile, DB, SIM, IoT
3334
- [] styling/theming
3435
- [] add logo
3536
- [] table grid lines
3637
- [] electron app
38+
- [] help docs
39+
- [] prebuilt dashboards
3740
- [] preview dashboard before deploying
3841
- [] share dashboard formulas
3942

src/getAppModel.js

+33-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { options, baseURL } from './requestOptions'
1+
import _ from 'lodash'
22
import rp from 'request-promise'
3+
import { options, baseURL } from './requestOptions'
34

45
export const getApps = async () => {
5-
return await rp({
6+
return rp({
67
...options,
78
url: `${baseURL}/rest/applications?output=json`,
89
})
@@ -18,7 +19,7 @@ export const getApps = async () => {
1819
}
1920

2021
export const getTiers = async ({ applicationName }) => {
21-
return await rp({
22+
return rp({
2223
...options,
2324
url: `${baseURL}/rest/applications/${applicationName}/tiers?output=json`,
2425
})
@@ -33,16 +34,40 @@ export const getTiers = async ({ applicationName }) => {
3334
})
3435
}
3536

36-
export const getBTs = async ({ applicationName }) => {
37-
return await rp({
37+
export const getBTs = async ({ applicationName, wheres }) => {
38+
return rp({
3839
...options,
3940
url: `${baseURL}/rest/applications/${applicationName}/business-transactions?output=json`,
4041
})
4142
.promise()
4243
.then(data => {
43-
const parsedData = JSON.parse(data)
44-
console.log(parsedData)
45-
return parsedData
44+
const parsedData = JSON.parse(data).map(bt => ({
45+
...bt,
46+
tier: bt.tierName,
47+
}))
48+
49+
let filteredData = parsedData
50+
const filters = _.intersection(wheres.map(({ field }) => field), [
51+
'bt',
52+
'tier',
53+
])
54+
55+
filters.forEach(filter => {
56+
const { field, operator, value } = wheres.find(
57+
where => where.field === filter,
58+
)
59+
const contextField = field === 'bt' ? 'name' : field
60+
filteredData = filteredData.filter(bt => {
61+
if (operator === '=') {
62+
return bt[contextField] === value
63+
} else if (operator === 'REGEXP') {
64+
return new RegExp(value, 'i').test(bt[contextField])
65+
} else {
66+
return true
67+
}
68+
})
69+
})
70+
return filteredData
4671
})
4772
.catch(err => {
4873
console.log(err)

src/getColumnFromSelect.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export default ({
3636
const applicationName = getApplicationFromWheres({ wheres })
3737
const { metric } = getMetricFromShortcut(select)
3838
if (selects[0].value === 'bt') {
39-
const metricWidgetData = data.bt.map(({ internalName, tierName }) => ({
39+
const metricWidgetData = data.bt.map(({ internalName, tier }) => ({
4040
applicationName,
41-
metricPath: `Business Transaction Performance|Business Transactions|${tierName}|${internalName}|${metric}`,
42-
entityName: tierName,
41+
metricPath: `Business Transaction Performance|Business Transactions|${tier}|${internalName}|${metric}`,
42+
entityName: tier,
4343
}))
4444

4545
return [

src/main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import createDashboard from './createDashboard'
77

88
const main = async () => {
99
const DASHBOARD_NAME = 'z_dan_2'
10-
const query = 'SELECT bt, art AS "Response Time", cpm, epm FROM applications WHERE application = "2075ICE.PREPROD"'
10+
const query = 'SELECT bt, art AS "Response Time", cpm, epm FROM applications WHERE application = "2075ICE.PREPROD" AND bt REGEXP "AdaptiveAuthentication"'
1111

12-
const { selects, from, wheres } = queryParser({ query })
12+
const { selects, wheres } = queryParser({ query })
1313

1414
// TODO: maybe this should be a gather data method
1515
// TODO: only get bt info if in select
1616
const applicationName = getApplicationFromWheres({ wheres })
17-
const bt = await getBTs({ applicationName })
18-
const data = { bt }
17+
const bt = await getBTs({ applicationName, wheres })
1918

19+
const data = { bt }
2020
const widgets = selects.map((s, index) => getColumnFromSelect({
2121
selects,
2222
selectIndex: index,

src/queryParser.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const getFrom = ({ query }) => {
2929
const getWhere = ({ query }) => {
3030
const whereRegex = /where(.*)/i
3131
const allWhere = whereRegex.exec(query)
32-
const wheres = allWhere[1].split(',').map(s => s.trim())
32+
const wheres = allWhere[1].split('AND').map(s => s.trim())
3333
const tokenizedWheres = wheres.map(where => {
34-
const delimeterRegex = /(.*?) ?(=) ?\"(.*)\"/
34+
const delimeterRegex = /(.*?) ?(=|REGEXP) ?"(.*)"$/
3535
const [, field, operator, value] = delimeterRegex.exec(where)
3636
return { field, operator, value }
3737
})
@@ -52,6 +52,6 @@ export default ({ query }) => {
5252
const selects = getSelects({ query })
5353
const { from } = getFrom({ query })
5454
const wheres = getWhere({ query })
55-
console.log(selects, from, wheres)
55+
console.log({ selects, from, wheres })
5656
return { selects, from, wheres }
5757
}

0 commit comments

Comments
 (0)