Skip to main content
Reference

BigQuery SDK Reference

The complete surface of @ultracart/bigquery-sdk. For the concepts behind it, see BigQuery Data Warehouse SDK; for a first working query, see the quickstart.

Exports

const {
UltraCartBigQuery,
DEFAULT_MAX_BYTES_BILLED, // 10737418240 (10 GB)
DEFAULT_PAGE_SIZE, // 50000
resolveDataset,
projectIdForMerchant,
DATASET_STANDARD, // 'ultracart_dw'
DATASET_MEDIUM, // 'ultracart_dw_medium'
DATASET_HIGH, // 'ultracart_dw_high'
DATASET_STREAMING, // 'ultracart_dw_streaming'
transformRows,
toBigQueryDatetime,
} = require('@ultracart/bigquery-sdk');

The linked dataset names have no exported constants at the package root. resolveDataset() produces them.

new UltraCartBigQuery(options)

Either merchantId or projectId is required. Passing neither throws Provide either a merchantId or an explicit projectId.

OptionTypeDefaultDescription
merchantIdstringnoneMerchant ID. The project is derived as ultracart-dw-{merchantid}, lowercased.
projectIdstringderivedExplicit project ID. Overrides the merchantId derivation.
bigqueryBigQueryADC clientAn injected @google-cloud/bigquery client, for testing or custom auth. A client using Application Default Credentials is created when this is omitted.
maxBytesBillednumber10737418240Default per-query ceiling on bytes billed. 0 or null disables the cap.
pageSizenumber50000Rows fetched per page while streaming. Bounds memory, since one page is held at a time.

The page size default balances throughput against per-page memory for wide rows. Streaming is round-trip bound, so larger pages mean fewer HTTP fetches.

query(sql, opts)

Runs a SQL query and returns an AsyncGenerator that yields one object per result row. Iterated with for await. Rows are fetched a page at a time, so memory stays bounded no matter how large the result set is.

OptionTypeDefaultDescription
paramsobjectnoneNamed query parameters, referenced as @name in the SQL.
modelclassnoneAn UltraCart SDK model class, such as UltraCartApi.Order. Each row is hydrated through its static constructFromObject. Omitted, rows are yielded as plain SDK-shaped objects.
maxBytesBillednumberclient valuePer-query override of the byte ceiling. 0 or null disables it for this call.
pageSizenumberclient valuePer-query override of the page size.

A query that would exceed maxBytesBilled fails rather than running, and the error comes from BigQuery rather than from this package.

dryRun(sql, opts)

Estimates what a query would scan without running it, using a BigQuery dry run. Accepts params, and resolves to:

FieldTypeDescription
totalBytesProcessednumberBytes BigQuery reports it would scan.
gigabytesProcessednumberThe same figure in GiB.
estimatedCostUsdnumberAn estimate, computed at a fixed on-demand rate of 6.25 USD per TiB scanned.

estimatedCostUsd is an approximation for guarding a large extract, not a quote. Actual billing follows Google's current pricing and your project's terms. See pricing.

Because LIMIT does not reduce bytes scanned, a dry run is the only reliable way to size a query before running it.

hydrate(rows, schemaFields, model) and hydrateRow(row, schemaFields, model)

Transform rows already in hand, for callers running their own BigQuery job. hydrateRow handles one row and hydrate maps an array. Both take the result schema's fields array and an optional model class, and both return the same objects query() would yield. query() remains the streaming path.

Helpers

FunctionReturnsDescription
projectIdForMerchant(merchantId)string'DEMO' resolves to 'ultracart-dw-demo'. Throws when the merchant ID is missing or not a string.
resolveDataset({ linked, taxonomy })stringDataset name for a combination of linked and PII tier. { linked: true, taxonomy: 'high' } resolves to 'ultracart_dw_linked_high'.
toBigQueryDatetime(value)stringStrips the trailing Z from an ISO string so it can be compared against a DATETIME column, normalizing a non-UTC offset to UTC first. The inverse of what the transform emits on read.
transformRows(rows, schemaFields)arrayThe low-level schema-driven transform, without model hydration.

Dataset selection

GoalDatasetFilter
A single standard accountultracart_dwmerchant_id = 'ACME'
A parent account, all childrenultracart_dw_linkedmerchant_id optional
One child of a parentultracart_dw_linkedmerchant_id = 'ACME'
Customer names and emailsultracart_dw_medium or _high, ultracart_dw_linked_medium or _linked_highas above
Change data captureultracart_dw_streaming.uc_*_streamingRecordTime > @since

Which tiers you can reach depends on the data warehouse permissions granted to your user. The access levels and what each one exposes are documented under Data Warehouse (BigQuery).

The _linked tables are views, so their numRows and partitioning metadata read as empty. The data is still there.

Type mapping

BigQuerySDK model propertyNote
DATETIMEISO 8601 string with ZStored as UTC wall-clock with no zone.
TIMESTAMPISO 8601 string with ZNormalized to a canonical Z form.
DATE, TIMEstring, unchangedYYYY-MM-DD and HH:MM:SS.
INTEGER, NUMERICNumberWrapper objects and strings are normalized.
REPEATED RECORD with a single value sub-fieldprimitive arrayHow the warehouse stores string[] and number[].
REPEATED RECORD with several sub-fieldsarray of objectsLeft as is. Nested models hydrate normally.
*_hash columnsdroppedNo matching SDK property, so hydration discards them.

The transform reads the BigQuery result schema rather than checking runtime types, so it behaves the same for every table.

Requirements

Node.js 22 or newer, matching the floor set by @google-cloud/bigquery v9. @ultracart/bigquery-sdk@0.1.x tracks @google-cloud/bigquery v8 for older runtimes. ultra_cart_rest_api_v2 is an optional peer dependency, needed only for model hydration.

Was this page helpful?