Skip to content

Commit 9a752c2

Browse files
use new inheritance style
1 parent 3e07715 commit 9a752c2

14 files changed

Lines changed: 642 additions & 942 deletions

File tree

lib/bigquery/dataset.js

Lines changed: 75 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,85 @@ var Table = require('./table.js');
5555
* @constructor
5656
*/
5757
function Dataset(bigQuery, id) {
58+
var methods = {
59+
/**
60+
* Create a dataset.
61+
*
62+
* @example
63+
* dataset.create(function(err, dataset, apiResponse) {
64+
* // `dataset.metadata` has been populated.
65+
* });
66+
*/
67+
create: true,
68+
69+
/**
70+
* Get a dataset if it exists. Also see
71+
* {module:bigquery/dataset#getOrCreate}.
72+
*
73+
* @example
74+
* dataset.get(function(err, dataset, apiResponse) {
75+
* if (!err) {
76+
* // `dataset.metadata` has been populated.
77+
* }
78+
* });
79+
*/
80+
get: true,
81+
82+
/**
83+
* Get the metadata for the Dataset.
84+
*
85+
* @resource [Datasets: get API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/datasets/get}
86+
*
87+
* @param {function} callback - The callback function.
88+
* @param {?error} callback.err - An error returned while making this
89+
* request.
90+
* @param {object} callback.metadata - The dataset's metadata.
91+
* @param {object} callback.apiResponse - The full API response.
92+
*
93+
* @example
94+
* dataset.getMetadata(function(err, metadata, apiResponse) {});
95+
*/
96+
getMetadata: true,
97+
98+
/**
99+
* Get a dataset if it exists, otherwise create one.
100+
*
101+
* @example
102+
* dataset.getOrCreate(function(err, dataset, apiResponse) {
103+
* if (!err) {
104+
* // `dataset.metadata` has been populated.
105+
* }
106+
* });
107+
*/
108+
getOrCreate: true,
109+
110+
/**
111+
* Sets the metadata of the Dataset object.
112+
*
113+
* @resource [Datasets: patch API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/datasets/patch}
114+
*
115+
* @param {object} metadata - Metadata to save on the Dataset.
116+
* @param {function} callback - The callback function.
117+
* @param {?error} callback.err - An error returned while making this
118+
* request.
119+
* @param {object} callback.apiResponse - The full API response.
120+
*
121+
* @example
122+
* var metadata = {
123+
* description: 'Info for every institution in the 2013 IPEDS universe'
124+
* };
125+
*
126+
* dataset.setMetadata(metadata, function(err, apiResponse) {});
127+
*/
128+
setMetadata: true
129+
};
130+
58131
ServiceObject.call(this, {
59132
parent: bigQuery,
60133
baseUrl: '/datasets',
61134
id: id,
62-
createMethod: bigQuery.createDataset.bind(bigQuery)
135+
createMethod: bigQuery.createDataset.bind(bigQuery),
136+
methods: methods
63137
});
64138

65139
this.bigQuery = bigQuery;
@@ -172,23 +246,6 @@ Dataset.prototype.delete = function(options, callback) {
172246
}, callback);
173247
};
174248

175-
/**
176-
* Get the metadata for the Dataset.
177-
*
178-
* @resource [Datasets: get API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/datasets/get}
179-
*
180-
* @param {function} callback - The callback function.
181-
* @param {?error} callback.err - An error returned while making this request
182-
* @param {object} callback.metadata - The dataset's metadata.
183-
* @param {object} callback.apiResponse - The full API response.
184-
*
185-
* @example
186-
* dataset.getMetadata(function(err, metadata, apiResponse) {});
187-
*/
188-
Dataset.prototype.getMetadata = function() {
189-
ServiceObject.prototype.getMetadata.apply(this, arguments);
190-
};
191-
192249
/**
193250
* Get a list of tables.
194251
*
@@ -289,27 +346,6 @@ Dataset.prototype.query = function(options, callback) {
289346
return this.bigQuery.query(options, callback);
290347
};
291348

292-
/**
293-
* Sets the metadata of the Dataset object.
294-
*
295-
* @resource [Datasets: patch API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/datasets/patch}
296-
*
297-
* @param {object} metadata - Metadata to save on the Dataset.
298-
* @param {function} callback - The callback function.
299-
* @param {?error} callback.err - An error returned while making this request
300-
* @param {object} callback.apiResponse - The full API response.
301-
*
302-
* @example
303-
* var metadata = {
304-
* description: 'Information for every institution in the 2013 IPEDS universe'
305-
* };
306-
*
307-
* dataset.setMetadata(metadata, function(err, apiResponse) {});
308-
*/
309-
Dataset.prototype.setMetadata = function() {
310-
ServiceObject.prototype.setMetadata.apply(this, arguments);
311-
};
312-
313349
/**
314350
* Return a new instance of reference to an existing Table object.
315351
*

lib/bigquery/job.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,50 @@ var ServiceObject = require('../common/service-object.js');
5858
* @constructor
5959
*/
6060
function Job(bigQuery, id) {
61+
var methods = {
62+
/**
63+
* Get a job if it exists.
64+
*
65+
* @example
66+
* job.get(function(err, job, apiResponse) {
67+
* if (!err) {
68+
* // `job.metadata` has been populated.
69+
* }
70+
* });
71+
*/
72+
get: true,
73+
74+
/**
75+
* Get the metadata of the job. This will mostly be useful for checking the
76+
* status of a previously-run job.
77+
*
78+
* @resource [Jobs: get API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/get}
79+
*
80+
* @param {function} callback - The callback function.
81+
* @param {?error} callback.err - An error returned while making this
82+
* request.
83+
* @param {object} callback.metadata - The metadata of the job.
84+
* @param {object} callback.apiResponse - The full API response.
85+
*
86+
* @example
87+
* var job = bigquery.job('id');
88+
* job.getMetadata(function(err, metadata, apiResponse) {});
89+
*/
90+
getMetadata: true
91+
};
92+
6193
ServiceObject.call(this, {
6294
parent: bigQuery,
6395
baseUrl: '/jobs',
6496
id: id,
65-
inherit: []
97+
methods: methods
6698
});
6799

68100
this.bigQuery = bigQuery;
69101
}
70102

71103
nodeutil.inherits(Job, ServiceObject);
72104

73-
/**
74-
* Get the metadata of the job. This will mostly be useful for checking the
75-
* status of a previously-run job.
76-
*
77-
* @resource [Jobs: get API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/get}
78-
*
79-
* @param {function} callback - The callback function.
80-
* @param {?error} callback.err - An error returned while making this request
81-
* @param {object} callback.metadata - The metadata of the job.
82-
* @param {object} callback.apiResponse - The full API response.
83-
*
84-
* @example
85-
* var job = bigquery.job('id');
86-
* job.getMetadata(function(err, metadata, apiResponse) {});
87-
*/
88-
Job.prototype.getMetadata = function() {
89-
ServiceObject.prototype.getMetadata.apply(this, arguments);
90-
};
91-
92105
/**
93106
* Get the results of a job.
94107
*

lib/bigquery/table.js

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,83 @@ var util = require('../common/util');
7979
* var table = dataset.table('my-table');
8080
*/
8181
function Table(dataset, id) {
82+
var methods = {
83+
/**
84+
* Create a table.
85+
*
86+
* @param {object} config - See {module:bigquery/dataset#createTable}.
87+
*
88+
* @example
89+
* var config = {
90+
* // ...
91+
* };
92+
*
93+
* table.create(config, function(err, table, apiResponse) {
94+
* // `table.metadata` has been populated.
95+
* });
96+
*/
97+
create: true,
98+
99+
/**
100+
* Delete a table and all its data.
101+
*
102+
* @resource [Tables: delete API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/tables/delete}
103+
*
104+
* @param {function} callback - The callback function.
105+
* @param {?error} callback.err - An error returned while making this
106+
* request.
107+
* @param {object} callback.apiResponse - The full API response.
108+
*
109+
* @example
110+
* table.delete(function(err, apiResponse) {});
111+
*/
112+
delete: true,
113+
114+
/**
115+
* Get a table if it exists. Also see {module:bigquery/table#getOrCreate}.
116+
*
117+
* @example
118+
* table.get(function(err, table, apiResponse) {
119+
* // `table.metadata` has been populated.
120+
* });
121+
*/
122+
get: true,
123+
124+
/**
125+
* Return the metadata associated with the Table.
126+
*
127+
* @resource [Tables: get API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/tables/get}
128+
*
129+
* @param {function} callback - The callback function.
130+
* @param {?error} callback.err - An error returned while making this
131+
* request.
132+
* @param {object} callback.metadata - The metadata of the Table.
133+
* @param {object} callback.apiResponse - The full API response.
134+
*
135+
* @example
136+
* table.getMetadata(function(err, metadata, apiResponse) {});
137+
*/
138+
getMetadata: true,
139+
140+
/**
141+
* Get a table if it exists, otherwise create one.
142+
*
143+
* @param {object=} config - See {module:bigquery/dataset#createTable}.
144+
*
145+
* @example
146+
* table.getOrCreate(config, function(err, table, apiResonse) {
147+
* // `table.metadata` has been populated.
148+
* });
149+
*/
150+
getOrCreate: true
151+
};
152+
82153
ServiceObject.call(this, {
83154
parent: dataset,
84155
baseUrl: '/tables',
85156
id: id,
86-
createMethod: dataset.createTable.bind(dataset)
157+
createMethod: dataset.createTable.bind(dataset),
158+
methods: methods
87159
});
88160

89161
this.bigQuery = dataset.bigQuery;
@@ -352,22 +424,6 @@ Table.prototype.createWriteStream = function(metadata) {
352424
return dup;
353425
};
354426

355-
/**
356-
* Delete a table and all its data.
357-
*
358-
* @resource [Tables: delete API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/tables/delete}
359-
*
360-
* @param {function} callback - The callback function.
361-
* @param {?error} callback.err - An error returned while making this request
362-
* @param {object} callback.apiResponse - The full API response.
363-
*
364-
* @example
365-
* table.delete(function(err, apiResponse) {});
366-
*/
367-
Table.prototype.delete = function() {
368-
return ServiceObject.prototype.delete.apply(this, arguments);
369-
};
370-
371427
/**
372428
* Export table to Google Cloud Storage.
373429
*
@@ -497,23 +553,6 @@ Table.prototype.export = function(destination, options, callback) {
497553
});
498554
};
499555

500-
/**
501-
* Return the metadata associated with the Table.
502-
*
503-
* @resource [Tables: get API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/tables/get}
504-
*
505-
* @param {function} callback - The callback function.
506-
* @param {?error} callback.err - An error returned while making this request
507-
* @param {object} callback.metadata - The metadata of the Table.
508-
* @param {object} callback.apiResponse - The full API response.
509-
*
510-
* @example
511-
* table.getMetadata(function(err, metadata, apiResponse) {});
512-
*/
513-
Table.prototype.getMetadata = function() {
514-
ServiceObject.prototype.getMetadata.apply(this, arguments);
515-
};
516-
517556
/**
518557
* Retrieves table data from a specified set of rows. The rows are returned to
519558
* your callback as an array of objects matching your table's schema.
@@ -897,6 +936,7 @@ Table.prototype.query = function(query, callback) {
897936
* description: 'A table for storing my recipes.',
898937
* schema: 'name:string, servings:integer, cookingTime:float, quick:boolean'
899938
* };
939+
*
900940
* table.setMetadata(metadata, function(err, metadata, apiResponse) {});
901941
*/
902942
Table.prototype.setMetadata = function(metadata, callback) {

0 commit comments

Comments
 (0)