1313
1414'use strict' ;
1515
16- // [START all]
1716// [START setup]
1817// By default, the client will authenticate using the service account file
1918// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
2019// the project specified by the GCLOUD_PROJECT environment variable. See
21- // https://googlecloudplatform.github.io/gcloud -node/#/docs/google-cloud/latest/guides/authentication
20+ // https://googlecloudplatform.github.io/google-cloud -node/#/docs/google-cloud/latest/guides/authentication
2221var BigQuery = require ( '@google-cloud/bigquery' ) ;
23-
24- // Instantiate the bigquery client
25- var bigquery = BigQuery ( ) ;
2622// [END setup]
2723
28- // Control-flow helper library
29- var async = require ( 'async' ) ;
24+ function createDataset ( datasetId , callback ) {
25+ var bigquery = BigQuery ( ) ;
26+ var dataset = bigquery . dataset ( datasetId ) ;
3027
31- // [START create_dataset]
32- /**
33- * List datasets in the authenticated project.
34- *
35- * @param {string } name The name for the new dataset.
36- * @param {function } callback The callback function.
37- */
38- function createDataset ( name , callback ) {
39- var dataset = bigquery . dataset ( name ) ;
40-
41- // See https://googlecloudplatform.github.io/gcloud-node/#/docs/bigquery/latest/bigquery
42- dataset . create ( function ( err , dataset ) {
28+ // See https://googlecloudplatform.github.io/google-cloud-node/#/docs/bigquery/latest/bigquery/dataset?method=create
29+ dataset . create ( function ( err , dataset , apiResponse ) {
4330 if ( err ) {
4431 return callback ( err ) ;
4532 }
4633
47- console . log ( 'Created dataset: %s' , name ) ;
48- return callback ( null , dataset ) ;
34+ console . log ( 'Created dataset: %s' , datasetId ) ;
35+ return callback ( null , dataset , apiResponse ) ;
4936 } ) ;
5037}
51- // [END create_dataset]
52-
53- // [START delete_dataset]
54- /**
55- * List datasets in the authenticated project.
56- *
57- * @param {string } name The name for the new dataset.
58- * @param {function } callback The callback function.
59- */
60- function deleteDataset ( name , callback ) {
61- var dataset = bigquery . dataset ( name ) ;
62-
63- // See https://googlecloudplatform.github.io/gcloud-node/#/docs/bigquery/latest/bigquery
38+
39+ function deleteDataset ( datasetId , callback ) {
40+ var bigquery = BigQuery ( ) ;
41+ var dataset = bigquery . dataset ( datasetId ) ;
42+
43+ // See https://googlecloudplatform.github.io/google-cloud-node/#/docs/bigquery/latest/bigquery/dataset?method=delete
6444 dataset . delete ( function ( err ) {
6545 if ( err ) {
6646 return callback ( err ) ;
6747 }
6848
69- console . log ( 'Deleted dataset: %s' , name ) ;
49+ console . log ( 'Deleted dataset: %s' , datasetId ) ;
7050 return callback ( null ) ;
7151 } ) ;
7252}
73- // [END delete_dataset]
74-
75- // [START list_datasets]
76- /**
77- * List datasets in the authenticated project.
78- *
79- * @param {string } projectId The project ID to use.
80- * @param {function } callback The callback function.
81- */
53+
8254function listDatasets ( projectId , callback ) {
83- // Instantiate a bigquery client
8455 var bigquery = BigQuery ( {
8556 projectId : projectId
8657 } ) ;
8758
88- // See https://googlecloudplatform.github.io/gcloud- node/#/docs/bigquery/latest/bigquery
59+ // See https://googlecloudplatform.github.io/google-cloud- node/#/docs/bigquery/latest/bigquery?method=getDatasets
8960 bigquery . getDatasets ( function ( err , datasets ) {
9061 if ( err ) {
9162 return callback ( err ) ;
@@ -95,31 +66,27 @@ function listDatasets (projectId, callback) {
9566 return callback ( null , datasets ) ;
9667 } ) ;
9768}
98- // [END list_datasets]
9969
10070// [START get_dataset_size]
101- /**
102- * Calculate the size of the specified dataset.
103- *
104- * @param {string } datasetId The ID of the dataset.
105- * @param {string } projectId The project ID.
106- * @param {function } callback The callback function.
107- */
71+ // Control-flow helper library
72+ var async = require ( 'async' ) ;
73+
10874function getDatasetSize ( datasetId , projectId , callback ) {
10975 // Instantiate a bigquery client
11076 var bigquery = BigQuery ( {
11177 projectId : projectId
11278 } ) ;
11379 var dataset = bigquery . dataset ( datasetId ) ;
11480
115- // See https://googlecloudplatform.github.io/gcloud- node/#/docs/bigquery/latest/bigquery/dataset
81+ // See https://googlecloudplatform.github.io/google-cloud- node/#/docs/bigquery/latest/bigquery/dataset?method=getTables
11682 dataset . getTables ( function ( err , tables ) {
11783 if ( err ) {
11884 return callback ( err ) ;
11985 }
12086
12187 return async . map ( tables , function ( table , cb ) {
12288 // Fetch more detailed info for each table
89+ // See https://googlecloudplatform.github.io/google-cloud-node/#/docs/bigquery/latest/bigquery/table?method=get
12390 table . get ( function ( err , tableInfo ) {
12491 if ( err ) {
12592 return cb ( err ) ;
@@ -142,7 +109,6 @@ function getDatasetSize (datasetId, projectId, callback) {
142109 } ) ;
143110}
144111// [END get_dataset_size]
145- // [END all]
146112
147113// The command-line program
148114var cli = require ( 'yargs' ) ;
@@ -161,13 +127,13 @@ var program = module.exports = {
161127
162128cli
163129 . demand ( 1 )
164- . command ( 'create <name >' , 'Create a new dataset.' , { } , function ( options ) {
165- program . createDataset ( options . name , makeHandler ( ) ) ;
130+ . command ( 'create <datasetId >' , 'Create a new dataset with the specified ID .' , { } , function ( options ) {
131+ program . createDataset ( options . datasetId , makeHandler ( ) ) ;
166132 } )
167- . command ( 'delete <datasetId>' , 'Delete the specified dataset .' , { } , function ( options ) {
133+ . command ( 'delete <datasetId>' , 'Delete the dataset with the specified ID .' , { } , function ( options ) {
168134 program . deleteDataset ( options . datasetId , makeHandler ( ) ) ;
169135 } )
170- . command ( 'list' , 'List datasets in the authenticated project.' , { } , function ( options ) {
136+ . command ( 'list' , 'List datasets in the specified project.' , { } , function ( options ) {
171137 program . listDatasets ( options . projectId , makeHandler ( true , 'id' ) ) ;
172138 } )
173139 . command ( 'size <datasetId>' , 'Calculate the size of the specified dataset.' , { } , function ( options ) {
@@ -181,13 +147,13 @@ cli
181147 description : 'Optionally specify the project ID to use.' ,
182148 global : true
183149 } )
184- . example ( 'node $0 create my_dataset' , 'Create a new dataset named "my_dataset".' )
185- . example ( 'node $0 delete my_dataset' , 'Delete "my_dataset".' )
150+ . example ( 'node $0 create my_dataset' , 'Create a new dataset with the ID "my_dataset".' )
151+ . example ( 'node $0 delete my_dataset' , 'Delete a dataset identified as "my_dataset".' )
186152 . example ( 'node $0 list' , 'List datasets.' )
187- . example ( 'node $0 list -p bigquery-public-data' , 'List datasets in a project other than the authenticated project.' )
153+ . example ( 'node $0 list -p bigquery-public-data' , 'List datasets in the "bigquery-public-data" project.' )
188154 . example ( 'node $0 size my_dataset' , 'Calculate the size of "my_dataset".' )
189155 . example ( 'node $0 size hacker_news -p bigquery-public-data' , 'Calculate the size of "bigquery-public-data:hacker_news".' )
190- . wrap ( 100 )
156+ . wrap ( 120 )
191157 . recommendCommands ( )
192158 . epilogue ( 'For more information, see https://cloud.google.com/bigquery/docs' ) ;
193159
0 commit comments