Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@triptease/prequel

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@triptease/prequel

## Install

  • 0.0.8
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
160
decreased by-13.04%
Maintainers
3
Weekly downloads
 
Created
Source

Prequel

Install

npm install @triptease/prequel

SQL Builder

Paramaters

import { BigQuery } from "@google-cloud/bigquery";
import { sql, param } from "./Prequel";

const searchTerm = param("term", "STRING[]");
const query = sql`
    SELECT COUNT(1)
    FROM ${"`bigquery-public-data.google_trends.top_terms`"}
    WHERE term IN UNNEST(${searchTerm})
  `;

const args = query.compile({ term: ["cat"] }); // correct

const [rows] = await new BigQuery().query(args);

// type safety
query.compile({ term: "cat" }); // throws a type error as string is not string[]
query.compile({ spellingMistake: "cat" }); // throws a type error as term is not provided

Composition

import { BigQuery } from "@google-cloud/bigquery";
import { sql, param } from "./Prequel";

const searchTerm = param("term", "STRING[]");
const requiresAterm = sql`
    SELECT *
    FROM ${"`bigquery-public-data.google_trends.top_terms`"}
    WHERE term IN UNNEST(${searchTerm})
  `;

const countRows = sql`
    WITH filteredRows as (${requiresAterm})

    SELECT *
    FROM filteredRows
  `;

const args = countRows.compile({ term: ["cat"] }); // correct

const [rows] = await new BigQuery().query(args);

const args = countRows.compile({}); // typeerror as the composed view requires term

Testing

Patching data

import { BigQuery } from "@google-cloud/bigquery";
import { Storage } from "@google-cloud/storage";
import { sql, param, BigQueryTestRunner } from "./Prequel";

jest.setTimeout(30_000);

it("should count terms", async () => {
  const searchTerm = param("term", "STRING[]");
  const query = sql`
    SELECT COUNT(1) as cnt
    FROM ${"`bigquery-public-data.google_trends.top_terms`"}
    WHERE term IN UNNEST(${searchTerm})
  `;

  const storage = new Storage().bucket("my-bucket");
  const bigQuery = new BigQuery();
  const runner = new BigQueryTestRunner(storage, bigQuery);
  runner.withPatch({
    uri: "`bigquery-public-data.google_trends.top_terms`",
    rows: [
      { term: "cat", score: 5 },
      { term: "dog", score: 2 },
    ],
  });

  const [rows] = await runner.query(query.compile({ term: ["cat"] }));
  expect(rows[0].cnt).toEqual(1);
});

FAQs

Package last updated on 28 Sep 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc