Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let errorHistorgram = await Errors
- .raw(`SELECT period AS daily, coalesce(count,0) AS count
- FROM generate_series(date '${startTS}', date '${today}', interval '1d') AS period
- LEFT JOIN (
- SELECT time_bucket('1d',timestamp)::date AS date, count(timestamp)
- FROM my_error_table
- WHERE severity = 'HIGH'
- AND timestamp >= '${startTS}' AND timestamp < '${today}'
- AND device_id = ${deviceId}
- GROUP BY date
- ) t ON t.date = period;`)
- .debug();
- let errorHistorgram = await Errors
- .query()
- .select(raw(`time_bucket('1 day', timestamp) AS daily, count(timestamp)`))
- .where('device_id', deviceId)
- .andWhere('timestamp', '>', startTS)
- .andWhere('severity', 'HIGH')
- .leftJoin(`generate_series(date ${startTS}, date ${today}, interval 1d) AS series`, 'series.date', 'my_error_table.timestamp')
- .debug();
- select time_bucket('1 day', timestamp) AS daily, count(timestamp)
- from my_error_table
- left join "generate_series(date 2018-11-08T15:35:33"."050Z, date 2018-11-15T15:35:33"."133Z, interval 1d)" as "series"
- on "series"."date" = my_error_table."timestamp"
- where "device_id" = ? and "timestamp" > ? and "severity" = ?'
- let errorHistorgram = await Errors
- .query()
- .select(raw(`time_bucket('1 day', timestamp) AS daily, count(timestamp)`))
- .where('device_id', deviceId)
- .andWhere('timestamp', '>', startTS)
- .andWhere('severity', 'HIGH')
- .groupBy('timestamp')
- .rightJoin(raw(`generate_series(date '${startTS}', date '${today}', interval '1d') AS series`), 'series.date', 'my_error_table.timestamp')
- .debug();
- select time_bucket('1 day', timestamp) AS daily, count(timestamp)
- from my_errors_table
- right join generate_series(date '2018-11-08', date '2018-11-15', interval '1d') AS series
- on series = my_errors_table.timestamp
- where device_id = ? and timestamp > ? and severity = ?
- group by timestamp
- import { raw } from 'objection';
- const errors = await Errors
- .query()
- .select(
- raw("time_bucket_gapfill(?, timestamp, ?, ?) AS bucket", [bucketWidth, startTS, endTS]),
- raw('COALESCE(count(timestamp), 0) AS count'),
- ).where('device_id', deviceId)
- .andWhere('timestamp', '>=', startTS)
- .andWhere('timestamp', '<=', endTS)
- .groupBy('bucket')
- .orderBy('bucket');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement