Advertisement
GiacomoGalanti

codice 1 big query

Jun 12th, 2020
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. const {BigQuery} = require('@google-cloud/bigquery');
  2.  
  3. let datasetId='' //enter the Big Query Dataset ID
  4. let tableName='' //enter the Big Query table Name
  5.  
  6.  
  7. exports.webhook2bq = (req, res) => {
  8. try{
  9. const bigquery = new BigQuery();
  10. const dataset = bigquery.dataset(datasetId);
  11. const table = dataset.table(tableName);
  12. let time = new Date();
  13.  
  14. let data = req.method === 'POST' ? req.body : req.query;
  15. console.log(data)
  16. table.insert({
  17. TIMESTAMP: time,
  18. DATA: JSON.stringify(data)
  19. })
  20.  
  21. res.status(200).send(JSON.stringify(data));
  22.  
  23. } catch(e) {
  24. console.log(e);
  25. res.status(400).send(JSON.stringify(e));
  26. return e;
  27. };
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement