From b791118c4d3febb2968807bec455408ea412577a Mon Sep 17 00:00:00 2001 From: Bryan Short Date: Tue, 15 Oct 2013 17:25:27 -0700 Subject: [PATCH 1/2] adding update / put commands to google-bigquery project --- lib/Tables.js | 7 ++++++- lib/post.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Tables.js b/lib/Tables.js index aace253..af721e4 100644 --- a/lib/Tables.js +++ b/lib/Tables.js @@ -2,7 +2,8 @@ var Tables = function ( options ) { var post = require('./post')(options), del = require('./del')(options), - get = require('./get')(options); + get = require('./get')(options), + put = require('./put')(options); return { create: function ( table, cb ) { @@ -22,6 +23,10 @@ var Tables = function ( options ) { getAll: function ( datasetId, projId, cb ) { var url = '/projects/' + projId + '/datasets/' + datasetId + '/tables'; get(url, cb); + }, + patch: function ( id, datasetId, projId, patchObj, cb) { + var url = '/projects/' + projId + '/datasets/' + datasetId + '/tables/' + id; + put(url, patchObj, cb); } }; }; diff --git a/lib/post.js b/lib/post.js index bb5dcc1..6e9349e 100644 --- a/lib/post.js +++ b/lib/post.js @@ -19,7 +19,7 @@ var post = function ( options ) { }, function ( err, res, body ) { if ( err || res.statusCode !== 200 ) { //console.log(err || res); - cb('there was a problem executing your query'); + cb(err); } else { cb(undefined,body); } From 77ac2360033bc82ed51d3ed56fc4a93cc8c9b563 Mon Sep 17 00:00:00 2001 From: Bryan Short Date: Tue, 15 Oct 2013 17:33:30 -0700 Subject: [PATCH 2/2] actually adding put --- lib/put.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/put.js diff --git a/lib/put.js b/lib/put.js new file mode 100644 index 0000000..adc807d --- /dev/null +++ b/lib/put.js @@ -0,0 +1,31 @@ +var request = require('request'); + +var put = function ( options ) { + + var getToken = require('./getToken')(options.iss, options.key); + + return function ( url, data, cb ) { + + getToken(function ( err, token ) { + + if (err) { return cb(err); } + + request.put({ + url: 'https://www.googleapis.com/bigquery/v2' + url, + qs: { + access_token: token + }, + json: data + }, function ( err, res, body ) { + if ( err || res.statusCode !== 200 ) { + //console.log(err || res); + cb(err); + } else { + cb(undefined,body); + } + }); + }); + }; +}; + +module.exports = put; \ No newline at end of file