{"id":21258905,"url":"https://github.com/microfleet/clickhouse-adapter","last_synced_at":"2025-07-11T02:32:57.341Z","repository":{"id":38426847,"uuid":"252255872","full_name":"microfleet/clickhouse-adapter","owner":"microfleet","description":"NestJS Clickhouse Adapter ","archived":false,"fork":false,"pushed_at":"2025-06-04T06:59:32.000Z","size":917,"stargazers_count":5,"open_issues_count":26,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-11T21:03:13.166Z","etag":null,"topics":["clickhouse","clickhouse-adapter","clickhouse-bulk","table-maker"],"latest_commit_sha":null,"homepage":"","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/microfleet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2020-04-01T18:29:57.000Z","updated_at":"2024-10-24T16:50:14.000Z","dependencies_parsed_at":"2023-10-21T00:24:01.406Z","dependency_job_id":"aa4d347a-f6e9-4c94-9dec-013b149386fe","html_url":"https://github.com/microfleet/clickhouse-adapter","commit_stats":{"total_commits":132,"total_committers":6,"mean_commits":22.0,"dds":0.5378787878787878,"last_synced_commit":"8407fad110faa8c0be02e81f46f1b2784fb99169"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/microfleet/clickhouse-adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microfleet%2Fclickhouse-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microfleet%2Fclickhouse-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microfleet%2Fclickhouse-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microfleet%2Fclickhouse-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microfleet","download_url":"https://codeload.github.com/microfleet/clickhouse-adapter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microfleet%2Fclickhouse-adapter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261358612,"owners_count":23146665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","clickhouse-adapter","clickhouse-bulk","table-maker"],"created_at":"2024-11-21T04:11:25.349Z","updated_at":"2025-07-11T02:32:56.877Z","avatar_url":"https://github.com/microfleet.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @microfleet / clickhouse-adapter\n\n## Installation\n\n`yarn add @microfleet/clickhouse-adapter`\n\n## Using\n\nclickhouse-adapter was created to work with Yandex.ClickHouse. The package is a wrapper over @apple/node-clickhouse that provides additional tools:\n\n- migration;\n- table maker (schemas);\n- typed methods for inserting and reading data.\n\n### Configuring\n\n#### Default options\n\n```typescript\n{\n    host: 'clickhouse',\n    dbName: 'default',\n    user: 'default',\n    password: '',\n    format: 'JSONEachRow',\n  }\n```\n\n#### Available options\n\n- `host` (required) - ClickHouse Host\n- `user` (optional) - Authentication User\n- `password` (optional) - Authentication Password\n- `dbName` (optional) - Database Name\n- `path` (optional) - Path name of ClickHouse server (default: `/`)\n- `port` (optional) - Server port (default: `8123`)\n- `protocol` (optional) - 'https:' or 'http:' (default: `http:`)\n- `dataObjects` (optional) - if set to `false` each row is will represented as an array, for `true` - every row will represented an object `{ field: 'value' }`. Default: `false`\n- `format` (optional) - Supported formats: JSON, JSONEachRow, CSV, TabSeparated (more information: [link](https://clickhouse.tech/docs/en/interfaces/formats/)). Default: `JSON`\n- `queryOptions` (optional) - ClickHouse options (more information: [link](https://clickhouse.tech/docs/en/operations/settings/)\n- `readonly` (optional) - ReadOnly options (more information: [link](https://clickhouse.tech/docs/en/operations/settings/permissions-for-queries/#settings_readonly))\n- `requestOptions` (optional) - http or https request options (more information: [http.request](https://nodejs.org/api/http.html#http_http_request_options_callback), [https.request](https://nodejs.org/api/https.html#https_https_request_options_callback))\n\n### Initialization\n\n```typescript\nconst ch = new ClickhouseClient({\n  host: 'clickhouse',\n})\n```\n\n### Use cases\n\n#### Table maker\n\n```typescript\nnew TableMaker('db_test', 'test_table', null /* cluster name */, {\n  columnDefinitions: [\n    { name: 'trackDate', type: 'Date' },\n    { name: 'trackTimestamp', type: 'DateTime' },\n    { name: 'eventType', type: 'String' },\n  ],\n  tableOptions: ['ENGINE = MergeTree(trackDate, (eventType), 8192)'],\n})\n```\n\n#### System migration\n\n```typescript\nconst migrator = new SystemMigrator(ch)\nawait migrator.up(dbName)\n```\n\n**Note**: it will create a table in which to store the completed user migrations.\n\n```typescript\nconst migrator = new SystemMigrator(ch)\nawait migrator.up(dbName)\n\nconst migrator = new Migrator(ch)\n\nmigrator.addMigration({\n  name: '1589508238_event_a',\n  async up(clickhouseClient: ClickhouseClient): Promise\u003cboolean\u003e {\n    await clickhouseClient.createTable(\n      new TableMaker('db_test', 'event_a', null, {\n        columnDefinitions: [\n          { name: 'trackDate', type: 'Date' },\n          { name: 'trackTimestamp', type: 'DateTime' },\n          { name: 'event_type', type: 'String' },\n        ],\n        tableOptions: ['ENGINE = MergeTree(trackDate, (trackTimestamp, event_type), 8192)'],\n      })\n    )\n    return true\n  },\n})\n\nawait migrator.up(migrator.migrateAll(DB_NAME))\n```\n\n#### Insert data\n\n```typescript\nconst insertData: InsertData = {\n  query: () =\u003e {\n    return 'INSERT INTO event_a'\n  },\n  data: () =\u003e {\n    return [\n      {\n        trackDate: moment(now).format('YYYY-MM-DD'),\n        trackTimestamp: moment(now).format('YYYY-MM-DD HH:mm:ss'),\n        eventType: 'type_a',\n      },\n    ]\n  },\n}\n\nch.insert(DB_NAME, insertData, (err, result) =\u003e {\n  ...\n})\n```\n\n#### Read data\n\n```typescript\nch.query(\n  this.dbName,\n  sqlstring.format(\n    `SELECT * FROM event_a`,\n    [this.dbName, this.tableName]\n  ),\n  (err, result) =\u003e {...}\n)\n```\n\n## Roadmap\n\n- [ ] TSV support\n- [ ] insert async\n- [ ] create migration table on cluster\n- [ ] add methods for works with cluster (ping, health check, ...)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrofleet%2Fclickhouse-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrofleet%2Fclickhouse-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrofleet%2Fclickhouse-adapter/lists"}