Interact with your BigQuery dataset. Create a Dataset instance with or .
Package
@google-cloud/bigqueryExample
const{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('institutions');
Constructors
(constructor)(bigQuery, id, options)
constructor(bigQuery:BigQuery,id:string,options?:DatasetOptions);
Constructs a new instance of theDataset class
Properties
bigQuery
location
projectId
Methods
createQueryJob(options)
createQueryJob(options:string|Query):Promise<JobResponse>;
Run a query as a job. No results are immediately returned. Instead, your callback will be executed with aJob object that you must ping for the results. See the Job documentation for explanations of how to check on the status of the job.
See for full documentation of this method.
| Parameter |
|---|
| Name | Description |
options | string |Query
See for full documentation of this method. |
| Returns |
|---|
| Type | Description |
Promise<JobResponse_2> | {Promise |
createQueryJob(options, callback)
createQueryJob(options:string|Query,callback:JobCallback):void;
| Parameters |
|---|
| Name | Description |
options | string |Query
|
callback | JobCallback
|
| Returns |
|---|
| Type | Description |
void | |
createQueryStream(options)
createQueryStream(options:Query|string):Duplex;
Run a query scoped to your dataset as a readable object stream.
See for full documentation of this method.
| Parameter |
|---|
| Name | Description |
options | Query | string
See for full documentation of this method. |
| Returns |
|---|
| Type | Description |
Duplex | {stream} |
createRoutine(id, config)
createRoutine(id:string,config:RoutineMetadata):Promise<RoutineResponse>;
Examplesconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('my-dataset');constid='my-routine';constconfig={arguments:[{name:'x',dataType:{typeKind:'INT64'}}],definitionBody:'x * 3',routineType:'SCALAR_FUNCTION',returnType:{typeKind:'INT64'}};dataset.createRoutine(id,config,(err,routine,apiResponse)=>{if(!err){// The routine was created successfully.}});
If the callback is omitted a Promise will be returned
const[routine,apiResponse]=awaitdataset.createRoutine(id,config);
createRoutine(id, config, callback)
createRoutine(id:string,config:RoutineMetadata,callback:RoutineCallback):void;
| Returns |
|---|
| Type | Description |
void | |
createTable(id, options)
createTable(id:string,options:TableMetadata):Promise<TableResponse>;
Exampleconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('institutions');consttableId='institution_data';constoptions={// From the data.gov CSV dataset (http://goo.gl/kSE7z6):schema:'UNITID,INSTNM,ADDR,CITY,STABBR,ZIP,FIPS,OBEREG,CHFNM,...'};dataset.createTable(tableId,options,(err,table,apiResponse)=>{});//-// If the callback is omitted, we'll return a Promise.//-dataset.createTable(tableId,options).then((data)=>{consttable=data[0];constapiResponse=data[1];});
createTable(id, options, callback)
createTable(id:string,options:TableMetadata,callback:TableCallback):void;
| Returns |
|---|
| Type | Description |
void | |
createTable(id, callback)
createTable(id:string,callback:TableCallback):void;
| Returns |
|---|
| Type | Description |
void | |
delete(options)
delete(options?:DatasetDeleteOptions):Promise<[Metadata]>;
| Returns |
|---|
| Type | Description |
Promise<[Metadata]> | {Promise |
Exampleconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('institutions');//-// Delete the dataset, only if it does not have any tables.//-dataset.delete((err,apiResponse)=>{});//-// Delete the dataset and any tables it contains.//-dataset.delete({force:true},(err,apiResponse)=>{});//-// If the callback is omitted, we'll return a Promise.//-dataset.delete().then((data)=>{constapiResponse=data[0];});
delete(options, callback)
delete(options:DatasetDeleteOptions,callback:DeleteCallback):void;
| Returns |
|---|
| Type | Description |
void | |
delete(callback)
delete(callback:DeleteCallback):void;
| Returns |
|---|
| Type | Description |
void | |
getModels(options)
getModels(options?:GetModelsOptions):Promise<GetModelsResponse>;
Examplesconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('institutions');dataset.getModels((err,models)=>{// models is an array of `Model` objects.});
To control how many API requests are made and page through the results manually, setautoPaginate tofalse.
functionmanualPaginationCallback(err,models,nextQuery,apiResponse){if(nextQuery){// More results exist.dataset.getModels(nextQuery,manualPaginationCallback);}}dataset.getModels({autoPaginate:false},manualPaginationCallback);
If the callback is omitted, we'll return a Promise.
dataset.getModels().then((data)=>{constmodels=data[0];});
getModels(options, callback)
getModels(options:GetModelsOptions,callback:GetModelsCallback):void;
| Returns |
|---|
| Type | Description |
void | |
getModels(callback)
getModels(callback:GetModelsCallback):void;
| Returns |
|---|
| Type | Description |
void | |
getModelsStream(options)
getModelsStream(options?:GetModelsOptions):ResourceStream<Model>;
| Returns |
|---|
| Type | Description |
ResourceStream<Model> | |
getRoutines(options)
getRoutines(options?:GetRoutinesOptions):Promise<GetRoutinesResponse>;
Examplesconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('institutions');dataset.getRoutines((err,routines)=>{// routines is an array of `Routine` objects.});
To control how many API requests are made and page through the results manually, setautoPaginate tofalse.
functionmanualPaginationCallback(err,routines,nextQuery,apiResponse){if(nextQuery){// More results exist.dataset.getRoutines(nextQuery,manualPaginationCallback);}}dataset.getRoutines({autoPaginate:false},manualPaginationCallback);
If the callback is omitted a Promise will be returned
const[routines]=awaitdataset.getRoutines();
getRoutines(options, callback)
getRoutines(options:GetRoutinesOptions,callback:GetRoutinesCallback):void;
| Returns |
|---|
| Type | Description |
void | |
getRoutines(callback)
getRoutines(callback:GetRoutinesCallback):void;
| Returns |
|---|
| Type | Description |
void | |
getRoutinesStream(options)
getRoutinesStream(options?:GetRoutinesOptions):ResourceStream<Routine>;
| Returns |
|---|
| Type | Description |
ResourceStream<Routine> | |
getTables(options)
getTables(options?:GetTablesOptions):Promise<GetTablesResponse>;
Exampleconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('institutions');dataset.getTables((err,tables)=>{// tables is an array of `Table` objects.});//-// To control how many API requests are made and page through the results// manually, set `autoPaginate` to `false`.//-functionmanualPaginationCallback(err,tables,nextQuery,apiResponse){if(nextQuery){// More results exist.dataset.getTables(nextQuery,manualPaginationCallback);}}dataset.getTables({autoPaginate:false},manualPaginationCallback);//-// If the callback is omitted, we'll return a Promise.//-dataset.getTables().then((data)=>{consttables=data[0];});
getTables(options, callback)
getTables(options:GetTablesOptions,callback:GetTablesCallback):void;
| Returns |
|---|
| Type | Description |
void | |
getTables(callback)
getTables(callback:GetTablesCallback):void;
| Returns |
|---|
| Type | Description |
void | |
getTablesStream(options)
getTablesStream(options?:GetTablesOptions):ResourceStream<Table>;
| Returns |
|---|
| Type | Description |
ResourceStream<Table> | |
model(id)
| Parameter |
|---|
| Name | Description |
id | string
The ID of the model. {Model} |
| Returns |
|---|
| Type | Description |
Model | |
Exampleconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('institutions');constmodel=dataset.model('my-model');
query(options)
query(options:Query):Promise<QueryRowsResponse>;
Run a query scoped to your dataset.
See for full documentation of this method.
| Parameter |
|---|
| Name | Description |
options | Query
See for full documentation of this method. |
query(options)
query(options:string):Promise<QueryRowsResponse>;
| Parameter |
|---|
| Name | Description |
options | string
|
query(options, callback)
query(options:Query,callback:SimpleQueryRowsCallback):void;
| Returns |
|---|
| Type | Description |
void | |
query(options, callback)
query(options:string,callback:SimpleQueryRowsCallback):void;
| Returns |
|---|
| Type | Description |
void | |
routine(id)
routine(id:string):Routine;
| Parameter |
|---|
| Name | Description |
id | string
The ID of the routine. |
| Returns |
|---|
| Type | Description |
Routine | {Routine} |
Exampleconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('institutions');constroutine=dataset.routine('my_routine');
table(id, options)
table(id:string,options?:TableOptions):Table;
| Parameters |
|---|
| Name | Description |
id | string
The ID of the table. |
options | TableOptions
Table options. |
| Returns |
|---|
| Type | Description |
Table | |
Exampleconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();constdataset=bigquery.dataset('institutions');constinstitutions=dataset.table('institution_data');