{"id":34621304,"url":"https://github.com/squashql/squashql-codegen","last_synced_at":"2026-05-27T15:30:59.894Z","repository":{"id":188706717,"uuid":"673717140","full_name":"squashql/squashql-codegen","owner":"squashql","description":"Generate type definitions that represent tables and fields from your database","archived":false,"fork":false,"pushed_at":"2024-01-30T08:49:08.000Z","size":184,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-26T04:02:39.205Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/squashql.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-08-02T09:06:44.000Z","updated_at":"2025-10-16T07:04:33.000Z","dependencies_parsed_at":"2024-01-15T12:52:17.585Z","dependency_job_id":null,"html_url":"https://github.com/squashql/squashql-codegen","commit_stats":null,"previous_names":["squashql/squashql-codegen"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/squashql/squashql-codegen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squashql%2Fsquashql-codegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squashql%2Fsquashql-codegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squashql%2Fsquashql-codegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squashql%2Fsquashql-codegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/squashql","download_url":"https://codeload.github.com/squashql/squashql-codegen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squashql%2Fsquashql-codegen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33573247,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-24T15:01:27.325Z","updated_at":"2026-05-27T15:30:59.889Z","avatar_url":"https://github.com/squashql.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SquashQL Codegen\n\nThis tool is inspired by [Kysely Codegen](https://github.com/RobinBlomberg/kysely-codegen)\n\nsquashql-codegen generates type definitions that represent tables and fields from your database in ts file named `tables.ts`. \nIt fetches from a database the list of available tables and fields and creates a typescript file with this information. The\ntypes can be used with the [TypeScript library](https://www.npmjs.com/package/@squashql/squashql-js) to build SQL-like queries compatible with SquashQL.\n\n## NPM\n\n[https://www.npmjs.com/package/@squashql/squashql-codegen](https://www.npmjs.com/package/@squashql/squashql-codegen)\n\n## Support\n\nOnly the following databases are supported for the time being:\n- [BigQuery](#bigquery)\n- [Snowflake](#snowflake)\n\nExample:\n\n```typescript\nimport {TableField} from \"@squashql/squashql-js\"\n\nexport interface SquashQLTable {\n    _fields: TableField[]\n    _name: string\n}\n\nclass Product implements SquashQLTable {\n    readonly _name = \"product\"\n    readonly productId: TableField = new TableField(\"product.product_id\")\n    readonly price: TableField = new TableField(\"product.price\")\n    readonly brand: TableField = new TableField(\"product.brand\")\n    readonly categoryId: TableField = new TableField(\"product.category_id\")\n    readonly _fields: TableField[] = [this.productId, this.price, this.brand, this.categoryId]\n}\n\nclass Category implements SquashQLTable {\n    readonly _name = \"category\"\n    readonly categoryId: TableField = new TableField(\"category.category_id\")\n    readonly status: TableField = new TableField(\"category.status\")\n    readonly _fields: TableField[] = [this.categoryId, this.status]\n}\n\nconst product = new Product()\nconst category = new Category()\n\nexport {\n    product, category\n}\n```\n\nAnd then you can use it for your calculations that need to use the `Field` interface or the constant . [See the documentation](https://github.com/squashql/squashql/blob/main/documentation/QUERY.md#fields).\n```typescript\nimport {product, category} from \"./table\"\n\nconst price: TableField = product.price\nconst status: TableField = category.status\n\nconst priceName: string = price.name // name of the field is accessible\n// ...\n```\n\n## Installation \u0026 Execution\n\nTo install the CLI globally\n\n```\nnpm install -g @squashql/squashql-codegen\n```\n\nTo execute the CLI without installing anything\n\n```\nnpx @squashql/squashql-codegen\n```\n\n## Configuration\n\nCreate an .env to define a couple of environment variables needed to connect to the database and correctly\nexecute the script. It is also possible\nto [pass the values to the CLI](https://stackoverflow.com/questions/22312671/setting-environment-variables-for-node-to-retrieve)\n\nIn each case, a client needs to be created to connect to the DB by setting the env. variable `SQUASHQL_CLIENT`.\n\nTo choose where the file should be written, the following env. variable can be set `SQUASHQL_PATH`.\n\n```\n# .env file\nSQUASHQL_CLIENT=\"bigquery\" # mandatory\nSQUASHQL_PATH=\"/Users/john/tmp\" # optional, table.ts will be written in /Users/john/tmp directory\n```\n\n### BigQuery\n\nThe CLI uses [Application Default Credentials to authenticate](https://cloud.google.com/docs/authentication/application-default-credentials).\n\n```\n# .env file\nSQUASHQL_CLIENT=\"bigquery\" # mandatory\nSQUASHQL_BIGQUERY_DATASET_ID=\"nameofthedataset\" # mandatory\nGOOGLE_APPLICATION_CREDENTIALS=\"/path/to/key.json\" # mandatory if this authentication method is used https://cloud.google.com/docs/authentication/application-default-credentials#GAC\n```\n\n## Snowflake\n\n```\n# .env file\nSQUASHQL_CLIENT=\"snowflake\"\n\n# Snowflake\nSQUASHQL_SNOWFLAKE_ACCOUNT=\"abc123.north-europe.azure\" # mandatory\nSQUASHQL_SNOWFLAKE_USERNAME=\"john\" # mandatory\nSQUASHQL_SNOWFLAKE_PASSWORD=\"mypassword\" # mandatory\nSQUASHQL_SNOWFLAKE_DATABASE=\"DATABASE_NAME\" # mandatory\nSQUASHQL_SNOWFLAKE_SCHEMA=\"SCHEMA_NAME\" # mandatory\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquashql%2Fsquashql-codegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquashql%2Fsquashql-codegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquashql%2Fsquashql-codegen/lists"}