Created
January 26, 2022 22:17
-
-
Save harrisonrw/feb6acbcf668b1a68553948eda2b1379 to your computer and use it in GitHub Desktop.
Read from BigQuery via Firebase Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require("firebase-functions"); | |
const {BigQuery} = require('@google-cloud/bigquery'); | |
exports.getMostPolluted = functions.https.onCall((data, context) => { | |
const bigQuery = new BigQuery(); | |
const query = 'SELECT location, city, country, value, timestamp FROM `bigquery-public-data.openaq.global_air_quality` WHERE pollutant = "pm25" AND timestamp > "2020-01-01" ORDER BY value DESC LIMIT 10'; | |
return bigQuery.query(query) | |
.then(function(data) { | |
const rows = data[0]; | |
return rows; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment