Skip to content

Instantly share code, notes, and snippets.

@harrisonrw
Created January 26, 2022 22:17
Show Gist options
  • Save harrisonrw/feb6acbcf668b1a68553948eda2b1379 to your computer and use it in GitHub Desktop.
Save harrisonrw/feb6acbcf668b1a68553948eda2b1379 to your computer and use it in GitHub Desktop.
Read from BigQuery via Firebase Function
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