overleaf/services/web/scripts/analytics/helpers/GoogleBigQueryHelper.js
Alexandre Bourdin 971dabb1f8 Merge pull request #9116 from overleaf/ab-script-group-membership-sync
[web] Script & cron job to synchronize group subscriptions memberships in BQ

GitOrigin-RevId: 0180f7586eb520f37d4d600bcb8d3eeea36a538a
2022-12-21 09:05:42 +00:00

30 lines
628 B
JavaScript

const GoogleBigQuery = require('@google-cloud/bigquery').BigQuery
let dataset = null
function getDataset() {
if (!dataset) {
console.log(
'Connecting to BigQuery dataset: ',
process.env.BQ_PROJECT_ID,
process.env.BQ_DATASET
)
dataset = new GoogleBigQuery({
projectId: process.env.BQ_PROJECT_ID,
keyFilename: process.env.GCS_KEY_FILE,
}).dataset(process.env.BQ_DATASET)
}
return dataset
}
async function query(query) {
const [job] = await getDataset().createQueryJob({ query })
const [rows] = await job.getQueryResults()
return rows
}
module.exports = {
query,
}