{"id":13695627,"url":"https://github.com/uptrace/go-clickhouse","last_synced_at":"2025-05-03T13:32:41.265Z","repository":{"id":37421668,"uuid":"451035290","full_name":"uptrace/go-clickhouse","owner":"uptrace","description":"Golang ClickHouse client","archived":false,"fork":false,"pushed_at":"2024-02-29T16:28:34.000Z","size":843,"stargazers_count":248,"open_issues_count":18,"forks_count":26,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-03T18:19:46.390Z","etag":null,"topics":["clickhouse","database","go","golang"],"latest_commit_sha":null,"homepage":"https://clickhouse.uptrace.dev","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uptrace.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"custom":["https://uptrace.dev/sponsor"]}},"created_at":"2022-01-23T07:35:31.000Z","updated_at":"2024-08-02T16:01:06.000Z","dependencies_parsed_at":"2023-01-21T11:47:06.948Z","dependency_job_id":"35ef708c-12ee-445f-97c0-57377177aef0","html_url":"https://github.com/uptrace/go-clickhouse","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptrace%2Fgo-clickhouse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptrace%2Fgo-clickhouse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptrace%2Fgo-clickhouse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptrace%2Fgo-clickhouse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uptrace","download_url":"https://codeload.github.com/uptrace/go-clickhouse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224364337,"owners_count":17299052,"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","database","go","golang"],"created_at":"2024-08-02T18:00:31.268Z","updated_at":"2024-11-12T23:30:39.807Z","avatar_url":"https://github.com/uptrace.png","language":"Go","funding_links":["https://uptrace.dev/sponsor"],"categories":["开源类库","Go","Language bindings"],"sub_categories":["数据库","Golang"],"readme":"# ClickHouse client for Go 1.18+\n\n[![build workflow](https://github.com/uptrace/go-clickhouse/actions/workflows/build.yml/badge.svg)](https://github.com/uptrace/go-clickhouse/actions)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/uptrace/go-clickhouse/ch)](https://pkg.go.dev/github.com/go-clickhouse/ch)\n[![Documentation](https://img.shields.io/badge/ch-documentation-informational)](https://clickhouse.uptrace.dev/)\n[![Chat](https://discordapp.com/api/guilds/752070105847955518/widget.png)](https://discord.gg/rWtp5Aj)\n\nThis ClickHouse client uses native protocol to communicate with ClickHouse server and requires Go\n1.18+ in order to use generics. This is not a database/sql driver, but the API is compatible.\n\nMain features are:\n\n- ClickHouse native protocol support and efficient column-oriented design.\n- API compatible with database/sql.\n- [Bun](https://github.com/uptrace/bun/)-like query builder.\n- [Selecting](https://clickhouse.uptrace.dev/guide/clickhouse-select.html) into scalars, structs,\n  maps, slices of maps/structs/scalars.\n- `Date`, `DateTime`, and `DateTime64`.\n- `Array(T)` including nested arrays.\n- Enums and `LowCardinality(String)`.\n- `Nullable(T)` except `Nullable(Array(T))`.\n- [Migrations](https://clickhouse.uptrace.dev/guide/clickhouse-migrations.html).\n- [OpenTelemetry](https://clickhouse.uptrace.dev/guide/clickhouse-monitoring-performance.html)\n  support.\n- In production at [Uptrace](https://github.com/uptrace/uptrace)\n\nResources:\n\n- [**Get started**](https://clickhouse.uptrace.dev/guide/getting-started.html)\n- [Examples](https://github.com/uptrace/go-clickhouse/tree/master/example)\n- [Discussions](https://github.com/uptrace/go-clickhouse/discussions)\n- [Chat](https://discord.gg/rWtp5Aj)\n- [Reference](https://pkg.go.dev/github.com/uptrace/go-clickhouse/ch)\n- [Example app](https://github.com/uptrace/uptrace)\n\n## Benchmark\n\n**Read** (best of 3 runs):\n\n| Library                                                                                                            | Timing |\n| ------------------------------------------------------------------------------------------------------------------ | ------ |\n| [This library](example/benchmark/read-native/main.go)                                                              | 655ms  |\n| [ClickHouse/clickhouse-go](https://github.com/ClickHouse/clickhouse-go/blob/main/benchmark/v2/read-native/main.go) | 849ms  |\n\n**Write** (best of 3 runs):\n\n| Library                                                                                                                      | Timing |\n| ---------------------------------------------------------------------------------------------------------------------------- | ------ |\n| [This library](example/benchmark/write-native-columnar/main.go)                                                              | 475ms  |\n| [ClickHouse/clickhouse-go](https://github.com/ClickHouse/clickhouse-go/blob/main/benchmark/v2/write-native-columnar/main.go) | 881ms  |\n\n## Installation\n\n```shell\ngo get github.com/uptrace/go-clickhouse@latest\n```\n\n## Example\n\nA [basic](example/basic) example:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/uptrace/go-clickhouse/ch\"\n\t\"github.com/uptrace/go-clickhouse/chdebug\"\n)\n\ntype Model struct {\n\tch.CHModel `ch:\"partition:toYYYYMM(time)\"`\n\n\tID   uint64\n\tText string    `ch:\",lc\"`\n\tTime time.Time `ch:\",pk\"`\n}\n\nfunc main() {\n\tctx := context.Background()\n\n\tdb := ch.Connect(ch.WithDatabase(\"test\"))\n\tdb.AddQueryHook(chdebug.NewQueryHook(chdebug.WithVerbose(true)))\n\n\tif err := db.Ping(ctx); err != nil {\n\t\tpanic(err)\n\t}\n\n\tvar num int\n\tif err := db.QueryRowContext(ctx, \"SELECT 123\").Scan(\u0026num); err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(num)\n\n\tif err := db.ResetModel(ctx, (*Model)(nil)); err != nil {\n\t\tpanic(err)\n\t}\n\n\tsrc := \u0026Model{ID: 1, Text: \"hello\", Time: time.Now()}\n\tif _, err := db.NewInsert().Model(src).Exec(ctx); err != nil {\n\t\tpanic(err)\n\t}\n\n\tdest := new(Model)\n\tif err := db.NewSelect().Model(dest).Where(\"id = ?\", src.ID).Limit(1).Scan(ctx); err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(dest)\n}\n```\n\n## See also\n\n- [Golang ORM](https://github.com/uptrace/bun) for PostgreSQL, MySQL, MSSQL, and SQLite\n- [Golang PostgreSQL](https://bun.uptrace.dev/postgres/)\n- [Golang HTTP router](https://github.com/uptrace/bunrouter)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuptrace%2Fgo-clickhouse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuptrace%2Fgo-clickhouse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuptrace%2Fgo-clickhouse/lists"}