{"id":47701400,"url":"https://github.com/rohitkadhe/clickhouse-schema","last_synced_at":"2026-04-02T17:18:20.332Z","repository":{"id":230119227,"uuid":"773188186","full_name":"rohitkadhe/clickhouse-schema","owner":"rohitkadhe","description":"Dynamic typescript type inference by writing clickhouse CREATE TABLE queries as schemas","archived":false,"fork":false,"pushed_at":"2026-03-08T23:06:56.000Z","size":174,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-09T03:30:04.031Z","etag":null,"topics":["clickhouse","type-inference","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/clickhouse-schema","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rohitkadhe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-03-17T00:57:07.000Z","updated_at":"2026-03-08T23:06:58.000Z","dependencies_parsed_at":"2024-11-08T08:49:42.102Z","dependency_job_id":null,"html_url":"https://github.com/rohitkadhe/clickhouse-schema","commit_stats":null,"previous_names":["scale3-labs/clickhouse-schema","rohitkadhe/clickhouse-schema"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rohitkadhe/clickhouse-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohitkadhe%2Fclickhouse-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohitkadhe%2Fclickhouse-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohitkadhe%2Fclickhouse-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohitkadhe%2Fclickhouse-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rohitkadhe","download_url":"https://codeload.github.com/rohitkadhe/clickhouse-schema/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohitkadhe%2Fclickhouse-schema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31311269,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["clickhouse","type-inference","typescript"],"created_at":"2026-04-02T17:18:19.537Z","updated_at":"2026-04-02T17:18:20.327Z","avatar_url":"https://github.com/rohitkadhe.png","language":"TypeScript","funding_links":["https://www.paypal.com/donate/?business=9U7SF754EBPZ2\u0026no_recurring=1\u0026currency_code=CAD"],"categories":[],"sub_categories":[],"readme":"# ClickHouse-Schema Guide\n\nIn ClickHouse, defining and managing table schemas and their associated types can be done either manually or through the ClickHouse-Schema library. This guide compares these two approaches to illustrate the simplicity and efficiency ClickHouse-Schema brings to your projects.\n\n## Traditional Manual Query Approach\n\nTraditionally, creating a table in clickhouse requires manually writing the SQL query and the interface in your code. This method is straightforward but prone to errors and inconsistencies, especially when schema changes occur.\n\n### Create Table Query\n\n```sql\nCREATE TABLE IF NOT EXISTS students\n(\n    id UInt32,\n    name String,\n    height float32,\n    age UInt8,\n    weight Float64,,\n    isStudent Boolean\n)\n# Manually defined\ninterface StudentsTableTypeManuallyDefined {\n  id: number,\n  name: string,\n  age: number,\n  height: number,\n  weight: number,\n  isStudent: boolean\n}\n```\n\n**Did you notice any errors with the code below?**  These would not get caught till runtime\n\n## Using ClickHouse-Schema\n\nClickHouse-Schema automates schema creation and ensures type safety with minimal code, providing a more robust and maintainable solution.\n\n### Defining Schema\n\n``` typescript\nconst studentsTableSchema = new ClickhouseSchema({\n  id: { type: CHUInt32() },\n  name: { type: CHString() },\n  age: { type: CHUInt8() },\n  height: { type: CHFloat32() },\n  weight: { type: CHFloat64() },\n  isStudent: { type: CHBoolean() }\n}, {\n  table_name: 'students',\n  primary_key: 'id'\n})\n\n//Automatic type inference. If schema changes type automatically changes too\ntype StudentsTableType = InferClickhouseSchemaType\u003ctypeof studentsTableSchema\u003e\n```\n\n## Getting Started\n\nTo start using ClickHouse-Schema in your projects, follow these steps:\n\n1. **Installation**\n   To install ClickHouse-Schema, run the following command in your terminal:\n\n   ```bash\n   npm install clickhouse-schema\n   ```\n\n2. **Create a Schema**\n\n    Define your table schema and provide options such as the table name and primary key. This will enable automatic type inference, making your code more robust and maintainable.\n\n    ``` typescript\n\n    import {\n      ClickhouseSchema, CHUInt32, CHString, CHUInt8, CHFloat32, CHFloat64, CHBoolean, InferClickhouseSchemaType\n    } from 'clickhouse-schema'\n\n    // Use types directly or import ClickhouseTypes object to get all the types in one place\n    const studentsTableSchema = new ClickhouseSchema({\n      id: { type: CHUInt32() },\n      name: { type: CHString() },\n      age: { type: CHUInt8() },\n      height: { type: CHFloat32() },\n      weight: { type: CHFloat64() },\n      isStudent: { type: CHBoolean() }\n    }, {\n      table_name: 'students',\n      primary_key: 'id'\n    })\n    type MyTableType = InferClickhouseSchemaType\u003ctypeof studentsTableSchema\u003e\n    ```\n\n3. **Utilize Schema Methods**\n    ClickHouse-Schema provides several methods to streamline working with your database schema:\n\n    - Use `\u003cyour_schema\u003e.GetCreateTableQuery()` or `\u003cyour_schema\u003e.toString()` to generate the SQL `CREATE TABLE` query.\n    - Use `\u003cyour_schema\u003e.GetOptions()` to access the options passed when creating the table schema.\n    - Use `\u003cyour_schema\u003e.GetCreateTableQueryAsList()` to get the `CREATE TABLE` query as a list of strings, which can be helpful for debugging or logging.\n\n## Supported Types\n\n- Integer (signed and unsigned integers): `UInt8, UInt16, UInt32, UInt64, UInt128, UInt256, Int8, Int16, Int32, Int64, Int128, Int256` types\n- Floating-point numbers: `Float32` and `Float64` types\n- Decimal - `Decimal` type\n- Boolean: `Boolean` type\n- Strings: `String` and `FixedString` types\n- Dates: `Date`, `Date32`, `DateTime` and `DateTime64` types\n- Geometric: `Point` type, `Ring` type\n- Tuple: `Tuple` type\n- JSON: `JSON` type and legacy `Object('JSON')` type (use `useLegacyJsonType=true` in the options)\n- UUID: `UUID` type\n- Arrays: `Array` type\n- Nullable: `Nullable` type\n- LowCardinality: `LowCardinality` and `Enum` types\n- IP Addresses - `IPv4` and `IPv6`\n\nAnd support for more types is coming!\n\n\n## Schema Options\n\nWhen creating a schema, you can provide the following options:\n\n- `table_name` (required): The name of the table in ClickHouse\n- `primary_key` (optional): The primary key for the table. If not specified, `order_by` must be specified\n- `order_by` (optional): The ORDER BY clause for the table. If not specified, `primary_key` must be specified\n- `database` (optional): The database to use for the table\n- `on_cluster` (optional): The name of the cluster to use for the table\n- `engine` (optional): The engine to use for the table, default is `MergeTree()`\n- `partition_by` (optional): The partition expression for the table. Can be any valid ClickHouse expression.\n- `additional_options` (optional): An array of strings that are appended to the end of the CREATE TABLE query (e.g., `['COMMENT \\'Table comment\\'']`)\n\n## ☕ Support this project\n\nIf you find this project helpful, consider buying me a coffee.  \nYour support helps me maintain and improve it.\n\n[![Buy Me A Coffee](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.paypal.com/donate/?business=9U7SF754EBPZ2\u0026no_recurring=1\u0026currency_code=CAD)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohitkadhe%2Fclickhouse-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frohitkadhe%2Fclickhouse-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohitkadhe%2Fclickhouse-schema/lists"}