Skip to content

Instantly share code, notes, and snippets.

@goodpic
Created September 15, 2018 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goodpic/1b010b63e739b584b8b2805d5628f02c to your computer and use it in GitHub Desktop.
Save goodpic/1b010b63e739b584b8b2805d5628f02c to your computer and use it in GitHub Desktop.
Commander.js command line to create a new BigQuery table
const program = require('commander');
const { createTable } = require('../src/bigquery');
const { SchemaSalesByHour } = require('../schemas/SchemaSalesByHour');
program
.version('0.1.0')
.option('-t, --table [table]', 'Specify the table to create', '')
.parse(process.argv);
if (program.table) {
console.log(`Create a new table ${program.table}`);
switch (program.table) {
case 'shop_sales_by_hour':
createTable({
datasetId: 'stats',
tableId: program.table,
schema: SchemaSalesByHour,
isTest: false,
}).then(() => console.log(`${program.table} created.`));
break;
default:
console.log(`Cannot find the database ${program.table}`);
}
} else {
console.log('Please specifiy the table to create by "-t TABLE_NAME"');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment