Skip to main content

snippets_js

Integration

New integration from credential
const googleBigQueryClient = yepcode.integration.googleBigQuery("credential-slug");
New integration from plain authentication data
const { BigQuery } = require("@google-cloud/bigquery");

const googleBigQueryCredentials = {
projectId: "YepCode",
credentials: {
type: "service_account",
project_id: "yepcode",
private_key_id: "XXXXX",
private_key: "-----BEGIN PRIVATE KEY-----\nx\n-----END PRIVATE KEY-----",
client_email: "yepcode@example.org",
client_id: "1234567890",
auth_uri: "https://example.org",
token_uri: "https://example.org",
auth_provider_x509_cert_url: "https://example.org",
client_x509_cert_url: "https://example.org",
}
};

const googleBigQueryClient = new BigQuery(googleBigQueryCredentials);

Create a Dataset

Create a dataset
// Specify the geographic location where the dataset should reside
const options = {
location: "dataset-location",
};

const [dataset] = await googleBigQueryClient.createDataset("dataset-id", options);
console.log(`Dataset ${dataset.id} created.`);

List Datasets

List datasets
// Lists all datasets in current project
const [datasets] = await googleBigQueryClient.getDatasets();
console.log('Datasets:');
datasets.forEach(dataset => console.log(dataset.id));

Delete a Dataset

Delete a dataset
// Create a reference to the existing dataset
const dataset = googleBigQueryClient.dataset("dataset-id");

await dataset.delete({force: true});
console.log(`Dataset ${dataset.id} deleted.`);

Query to a Dataset

Query to a dataset
const query = "your-SQL-query";

// For all options, see https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query
const options = {
query: query,
// Location must match that of the dataset(s) referenced in the query.
location: "dataset-location",
};

// Run the query as a job
const [job] = await googleBigQueryClient.createQueryJob(options);
console.log(`Job ${job.id} started.`);

// Wait for the query to finish
const [rows] = await job.getQueryResults();

// Use the result