BigQuery: Create and delete a table from the Node client
Next, We would like to save the hourly sales summary created in the previous post in BigQuery.
BigQuery Node.js client library
When playing with the sales data and the dashboard, I often need to update or modify the database schema to add the various analytic views. It would be much easier to operate the BigQuery from the Node.js client rather than working manually on the admin page. The client script could be used as the automated script as well to update the data periodically.
There is a good installation guide to set up the Node BigQuery client. The Commander.js library is also useful to develop your own BigQuery command line tools.
Create and delete a table from the Node client
Here is the example of creating and dropping a table from the BigQuery Node.js client. Save it as “/src/bigquery.js”
Define the schema for the hourly sales summary
Save the following schema as “/schemas/SchemaSalesByHour.js”
Command to create a new table
Then create the following commander script to require the library and schema files, saved it as “./command/create.js”
To create the table, type the following command on the terminal.
% node ./commands/create.js -t shop_sales_by_hour
Command to drop the table
Saved the command as “./command/drop.js”
To delete the table, type the following command on the terminal.
% node ./commands/drop.js -t shop_sales_by_hour