@emartech/google-big-query
Helper library to easily use Google BigQuery in NodeJS
Configuration
@emartech/google-big-query
uses the config
package for configuration. You should make the following settings available under `"GoogleCloud" namespace:
{
"projectId": "",
"bucket": "",
"dataset": "",
"credentials": {},
"maximumBillingTier": 10
}
projectId
The project you'll use for billing.
dataset
The default dataset to connect to if it was not specified.
credentials
The credentials the connection will use.
Example:
{
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"client_email": "example@my-service.iam.gserviceaccount.com"
}
maximumBillingTier
More info about pricing: https://cloud.google.com/bigquery/pricing
API
const BigQuery = require('@emartech/google-big-query');
BigQuery
Methods
static
create(datasetName):BigQuery Creates a BigQuery instance.
Parameters
Name | Type | Description |
---|---|---|
datasetName |
string | The name of the default dataset. Default: config.GoogleCloud.dataset optional
|
Returns
Type | Description |
---|---|
BigQuery | Instance of the BigQuery wrapper class. |
constructor(datasetName, client):BigQuery
Constructor of BigQuery wrapper.
Parameters
Name | Type | Description |
---|---|---|
datasetName |
string | The name of the default dataset. |
client |
@google-cloud/bigquery | The BigQuery client. |
table(tableName):Table
Returns a Table instance for the given table name.
Parameters
Name | Type | Description |
---|---|---|
tableName |
string | The name of the table in the dataset |
Returns
Type | Description |
---|---|
Table | Google Cloud BigQuery Table class instance. |
createQueryStream(query):ReadableStream
This is a wrapper of the original createQueryStream() method.
Parameters
Name | Type | Description |
---|---|---|
query |
string or object | The query to run. More info about the parameter. |
Returns
Type | Description |
---|---|
ReadableStream |
query(query):Promise
This is a wrapper of the original query() method.
Parameters
Name | Type | Description |
---|---|---|
query |
string or object | The query to run. More info about the parameter. |
Returns
Type | Description |
---|---|
Promise |
generator
createQueryJob(query):Promise This is a wrapper of the original createQueryJob() method.
Parameters
Name | Type | Description |
---|---|---|
options |
object or string |
Returns
Type | Description |
---|---|
Promise |
Example
let [job] = yield BigQuery.create().createQueryJob(query);
job.getQueryResultsStream({ maxResults: 100000, startIndex: 0 }).pipe(processRow);
generator
createTableIfNotExists(table, schema):Table Creates the table with the specified schema.
Parameters
Name | Type | Description |
---|---|---|
table |
Table | The table instance |
schema |
object | Schema definition of the table |
Returns
Type | Description |
---|---|
Table | The new Table. |
generator
dropTableIfExists(table):void Drops the given table if exists.
Parameters
Name | Type | Description |
---|---|---|
table |
Table | The table instance that should be dropped. |
generator
createTable(tableName, options):Table This is a wrapper of the original createTable() method.
Parameters
Name | Type | Description |
---|---|---|
tableName |
string | The name of the table. |
options |
object | More info in the original documentation. optional
|
Returns
Type | Description |
---|---|
Table | The new Table. |