Socket
Book a DemoInstallSign in
Socket

cfw-bq

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cfw-bq

This is a BigQuery client library for Cloudflare Workers. It allows you to query BigQuery from within a Cloudflare Worker.

0.0.3
latest
npmnpm
Version published
Weekly downloads
6
-53.85%
Maintainers
1
Weekly downloads
 
Created
Source

BigQuery Client for Cloudflare Workers

This is a BigQuery client library for Cloudflare Workers. It allows you to query BigQuery from within a Cloudflare Worker.

Installation

npm install cfw-bq

Configuration

You need to provide the service account credentials as a secret in Cloudflare Workers.

{
  "type": "service_account",
  "project_id": "your-project",
  "private_key_id": "your-private-key-id",
  "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
  "client_email": "your-service-account-email",
  "client_id": "your-client-id",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token"
}

Set the secret in Cloudflare Workers:

wrangler secret put MY_CREDENTIALS

The secret name MY_CREDENTIALS is just an example. You can use any name you like.

Usage

import { BigQuery } from 'cfw-bq';

export interface Env {
  MY_CREDENTIALS: string;
}

const project = '{your-project-id}';

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    const bq = new BigQuery(JSON.parse(env.MY_CREDENTIALS), project);
    const query = 'SELECT * FROM `your-project.your-dataset.your-table` LIMIT 10';
    const result = await bq.query(query);

    return Response.json(result);
  }
};

for TypeScript

You can specify the schema of the result by providing a generic type argument to the query method.

interface Row {
  id: number;
  name: string;
}

const result = await bq.query<Row>(query);
// result is of type Row[]

License

MIT (see: LICENSE)

FAQs

Package last updated on 29 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.