add event data

This commit is contained in:
Brian Cao 2022-10-21 16:42:44 -07:00
parent 67394194af
commit 75778fdfc7
22 changed files with 446 additions and 84 deletions

View file

@ -85,13 +85,13 @@ function getTimestampInterval(field) {
}
}
function getJsonField(column, property, value) {
function getJsonField(column, property, isNumber) {
const db = getDatabaseType(process.env.DATABASE_URL);
if (db === POSTGRESQL) {
let accessor = `${column} ->> '${property}'`;
if (value && typeof value === 'number') {
if (isNumber) {
accessor = `CAST(${accessor} AS DECIMAL)`;
}
@ -111,7 +111,9 @@ function getEventDataColumnsQuery(column, columns) {
return arr;
}
arr.push(`${filter}(${getJsonField(column, key)})`);
const isNumber = ['sum', 'avg', 'min', 'max'].some(a => a === filter);
arr.push(`${filter}(${getJsonField(column, key, isNumber)}) as "${filter}(${key})"`);
return arr;
}, []);
@ -127,8 +129,10 @@ function getEventDataFilterQuery(column, filters) {
return arr;
}
const isNumber = filter && typeof filter === 'number';
arr.push(
`${getJsonField(column, key, filter)} = ${
`${getJsonField(column, key, isNumber)} = ${
typeof filter === 'string' ? `'${filter}'` : filter
}`,
);