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); } 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