npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@squashql/squashql-codegen

v1.0.17

Published

SquashQL CLI to generate type definitions representing tables from your database

Downloads

998

Readme

SquashQL Codegen

This tool is inspired by Kysely Codegen

squashql-codegen generates type definitions that represent tables and fields from your database in ts file named tables.ts. It fetches from a database the list of available tables and fields and creates a typescript file with this information. The types can be used with the TypeScript library to build SQL-like queries compatible with SquashQL.

NPM

https://www.npmjs.com/package/@squashql/squashql-codegen

Support

Only the following databases are supported for the time being:

Example:

import {TableField} from "@squashql/squashql-js"

export interface SquashQLTable {
    _fields: TableField[]
    _name: string
}

class Product implements SquashQLTable {
    readonly _name = "product"
    readonly productId: TableField = new TableField("product.product_id")
    readonly price: TableField = new TableField("product.price")
    readonly brand: TableField = new TableField("product.brand")
    readonly categoryId: TableField = new TableField("product.category_id")
    readonly _fields: TableField[] = [this.productId, this.price, this.brand, this.categoryId]
}

class Category implements SquashQLTable {
    readonly _name = "category"
    readonly categoryId: TableField = new TableField("category.category_id")
    readonly status: TableField = new TableField("category.status")
    readonly _fields: TableField[] = [this.categoryId, this.status]
}

const product = new Product()
const category = new Category()

export {
    product, category
}

And then you can use it for your calculations that need to use the Field interface or the constant . See the documentation.

import {product, category} from "./table"

const price: TableField = product.price
const status: TableField = category.status

const priceName: string = price.name // name of the field is accessible
// ...

Installation & Execution

To install the CLI globally

npm install -g @squashql/squashql-codegen

To execute the CLI without installing anything

npx @squashql/squashql-codegen

Configuration

Create an .env to define a couple of environment variables needed to connect to the database and correctly execute the script. It is also possible to pass the values to the CLI

In each case, a client needs to be created to connect to the DB by setting the env. variable SQUASHQL_CLIENT.

To choose where the file should be written, the following env. variable can be set SQUASHQL_PATH.

# .env file
SQUASHQL_CLIENT="bigquery" # mandatory
SQUASHQL_PATH="/Users/john/tmp" # optional, table.ts will be written in /Users/john/tmp directory

BigQuery

The CLI uses Application Default Credentials to authenticate.

# .env file
SQUASHQL_CLIENT="bigquery" # mandatory
SQUASHQL_BIGQUERY_DATASET_ID="nameofthedataset" # mandatory
GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json" # mandatory if this authentication method is used https://cloud.google.com/docs/authentication/application-default-credentials#GAC

Snowflake

# .env file
SQUASHQL_CLIENT="snowflake"

# Snowflake
SQUASHQL_SNOWFLAKE_ACCOUNT="abc123.north-europe.azure" # mandatory
SQUASHQL_SNOWFLAKE_USERNAME="john" # mandatory
SQUASHQL_SNOWFLAKE_PASSWORD="mypassword" # mandatory
SQUASHQL_SNOWFLAKE_DATABASE="DATABASE_NAME" # mandatory
SQUASHQL_SNOWFLAKE_SCHEMA="SCHEMA_NAME" # mandatory