async function countJobs (schema, where, values) { const db = await getDb() const result = await db.executeSql(`select count(*) as count from ${schema}.job where ${where}`, values) await db.close() return parseFloat(result.rows[0].count) }
app.get('/poi', (req, res, next) => { //console.log('calling poi...') let sqlQuery = '' req.sqlQuery = ` SELECT * FROM public.poi; ` let result = {data: {}} pool.query(req.sqlQuery, function (err, dbdata) { result = dbdata.rows if (err) throw err //console.log(result) res.send(result) }) }, queryHandler)
app.get('/events/hourly', (req, res, next) => { let withRowCount = req.query.withRowCount let pageNumber = req.query.pageNumber let limit = req.query.limit let timeConstraint = req.query.timeConstraint let sqlQuery = '' let rowCountQuery = '' rowCountQuery = `SELECT count(*) FROM public.hourly_events GROUP BY date, hour` req.sqlQuery = ` SELECT date, hour, events, poi_id FROM public.hourly_events ORDER BY date, hour LIMIT ` + limit + ` OFFSET ` + (pageNumber - 1) * limit + `;` //console.log(req.sqlQuery) let result = { rowCount: 0, data: {}, withRowCount: withRowCount, pageNumber: pageNumber, limit: limit } pool.query(req.sqlQuery, function (err, dbdata) { result.data = dbdata.rows if (err) throw err //console.log(result) if (withRowCount == "true") { pool.query(rowCountQuery, function (err, rows, fields) { result.rowCount = rows.rowCount if (err) throw err res.send(result) }) } else { res.send(result) } }) }, queryHandler)
let result = { rowCount: 0, data: {}, withRowCount: withRowCount, pageNumber: pageNumber, limit: limit } pool.query(req.sqlQuery, function (err, dbdata) { result.data = dbdata.rows if (err) throw err
return jobCountResult.rows[0].job_count
app.get('/poi', (req, res, next) => { //console.log('calling poi...') let sqlQuery = '' req.sqlQuery = ` SELECT * FROM public.poi; ` let result = {data: {}} pool.query(req.sqlQuery, function (err, dbdata) { result = dbdata.rows if (err) throw err //console.log(result) res.send(result) }) }, queryHandler)
let result = { rowCount: 0, data: {}, withRowCount: withRowCount, pageNumber: pageNumber, limit: limit } pool.query(req.sqlQuery, function (err, dbdata) { result.data = dbdata.rows if (err) throw err
app.get('/stats/hourly', (req, res, next) => { let withRowCount = req.query.withRowCount let pageNumber = req.query.pageNumber let limit = req.query.limit let timeConstraint = req.query.timeConstraint let sqlQuery = '' let rowCountQuery = '' rowCountQuery = `SELECT count(*) FROM public.hourly_stats GROUP BY date, hour` req.sqlQuery = ` SELECT date, hour, impressions, clicks, revenue, poi_id FROM public.hourly_stats ORDER BY date, hour LIMIT ` + limit + ` OFFSET ` + (pageNumber - 1) * limit + `;` let result = { rowCount: 0, data: {}, withRowCount: withRowCount, pageNumber: pageNumber, limit: limit } pool.query(req.sqlQuery, function (err, dbdata) { result.data = dbdata.rows if (err) throw err //console.log(result) if (withRowCount == "true") { pool.query(rowCountQuery, function (err, rows, fields) { result.rowCount = rows.rowCount if (err) throw err res.send(result) }) } else { res.send(result) } }) }, queryHandler)
app.get('/stats/hourly', (req, res, next) => { let withRowCount = req.query.withRowCount let pageNumber = req.query.pageNumber let limit = req.query.limit let timeConstraint = req.query.timeConstraint let sqlQuery = '' let rowCountQuery = '' rowCountQuery = `SELECT count(*) FROM public.hourly_stats GROUP BY date, hour` req.sqlQuery = ` SELECT date, hour, impressions, clicks, revenue, poi_id FROM public.hourly_stats ORDER BY date, hour LIMIT ` + limit + ` OFFSET ` + (pageNumber - 1) * limit + `;` let result = { rowCount: 0, data: {}, withRowCount: withRowCount, pageNumber: pageNumber, limit: limit } pool.query(req.sqlQuery, function (err, dbdata) { result.data = dbdata.rows if (err) throw err //console.log(result) if (withRowCount == "true") { pool.query(rowCountQuery, function (err, rows, fields) { result.rowCount = rows.rowCount if (err) throw err res.send(result) }) } else { res.send(result) } }) }, queryHandler)
app.get('/events/hourly', (req, res, next) => { let withRowCount = req.query.withRowCount let pageNumber = req.query.pageNumber let limit = req.query.limit let timeConstraint = req.query.timeConstraint let sqlQuery = '' let rowCountQuery = '' rowCountQuery = `SELECT count(*) FROM public.hourly_events GROUP BY date, hour` req.sqlQuery = ` SELECT date, hour, events, poi_id FROM public.hourly_events ORDER BY date, hour LIMIT ` + limit + ` OFFSET ` + (pageNumber - 1) * limit + `;` //console.log(req.sqlQuery) let result = { rowCount: 0, data: {}, withRowCount: withRowCount, pageNumber: pageNumber, limit: limit } pool.query(req.sqlQuery, function (err, dbdata) { result.data = dbdata.rows if (err) throw err //console.log(result) if (withRowCount == "true") { pool.query(rowCountQuery, function (err, rows, fields) { result.rowCount = rows.rowCount if (err) throw err res.send(result) }) } else { res.send(result) } }) }, queryHandler)
let result = { rowCount: 0, data: {}, withRowCount: withRowCount, pageNumber: pageNumber, limit: limit } pool.query(req.sqlQuery, function (err, dbdata) { result.data = dbdata.rows if (err) throw err
let result = { rowCount: 0, data: {}, withRowCount: withRowCount, pageNumber: pageNumber, limit: limit } pool.query(req.sqlQuery, function (err, dbdata) { result.data = dbdata.rows if (err) throw err