Modernize library: context support, connection pooling, compression, …#2
Merged
Conversation
…and more - Add context.Context to all public methods (Exec, Iter, Ping, CheckCtx) - Reuse http.Client with connection pooling instead of creating per-request - Add gzip compression support (HttpTransport.Compression) - Check HTTP status codes and return structured errors - Add database selection via header and URL param - Add query_id, session_id, and per-query settings support - Add NewConnWithOptions constructor - Add uint, bool, Nullable, and Date unmarshal support - Fix multiline error parsing with (?s) regex flag - Compile error regex once at package level - Replace deprecated io/ioutil, strings.Replace, strings.Index - Upgrade Cluster from sync.Mutex to sync.RWMutex - Add go.mod (Go 1.21+) with testify dependency - Replace Travis CI with GitHub Actions (test + release workflows) - Expand tests from 30 to 58 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
26 integration tests running against clickhouse/clickhouse-server: - Ping, context cancellation, and timeouts - SELECT with all supported types (int, uint, float, string, bool, DateTime, Date) - Nullable type support (\N handling) - Array types (int, string) - CREATE TABLE, INSERT, SELECT round-trip - BuildInsert and BuildMultiInsert - Placeholder substitution (int and string) - Database selection via ConnOptions - Query ID tracking (verified via system.query_log) - Session ID (SET + getSetting across same session) - Per-query settings (max_rows_to_read enforcement) - Gzip compression - External data tables - Cluster health checks - Special character escaping - Error handling (bad SQL, nonexistent tables) Tests use //go:build integration tag so they only run when explicitly requested. GitHub Actions runs them in a separate job with a ClickHouse service container. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace Travis/roistat badges with GitHub Actions/mintance - Update all examples to use context.Context - Add sections: auth, database, query ID, session ID, settings, compression, context timeout - Update ClickHouse branding and links - Document NewConnWithOptions, SetSetting, CheckCtx Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Naming (Go initialisms must be all caps):
- HttpTransport → HTTPTransport
- NewHttpTransport → NewHTTPTransport
- DbError → DBError
- prepareHttp → prepareHTTP
Documentation:
- Add doc.go with package-level documentation and usage example
- Add doc comments to all exported types and functions
- Add compile-time interface check: var _ Transport = (*HTTPTransport)(nil)
Error strings (lowercase, no punctuation per Go convention):
- "Connection pointer is nil" → "connection pointer is nil"
- "Clickhouse host response was..." → "clickhouse: unexpected ping response..."
- "Amount of row items..." → "row item count..."
Code style:
- interface{} → any (Go 1.18+)
- Extract normalizeHost() to deduplicate host normalization
- Extract buildMultipartPostRequest/buildSimplePostRequest from monolithic function
- Extract unmarshalIntSlice/unmarshalStringSlice/unmarshalArray from giant switch
- Eliminate intermediate variable m in unmarshal (use two-value form of type assertion)
- Iter receiver r → it (first letter of type name)
- Remove unnecessary named returns
- Use http.MethodGet/http.MethodPost instead of string literals
- Use assert.NoError/require.NoError instead of assert.Equal(t, nil, err)
- Use assert.ErrorAs instead of type assertion for error checks
- Use assert.Empty instead of assert.Equal(t, "", ...)
- Rename numbered tests to descriptive names (Ping2 → PingBadResponse, etc.)
- Convert TestConnect to table-driven test
- Lowercase test handler types (not exported)
- Group imports: stdlib, then third-party
- Preallocate args slice in BuildMultiInsert with append
- Use range index in benchmarks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add Quick Start section with full working example including Ping - Add GoDoc badge - Add Nullable types section with pointer scanning example - Add Error handling section showing DBError and HTTP error patterns - Add Supported types table with marshal/unmarshal matrix - Add Connection pooling section documenting defaults - Expand Cluster section with IsDown and ActiveConn nil check - Add context to all examples that were missing it - Add ClickHouse settings docs link - Show proper error handling (if err != nil) instead of if err == nil - Expand Features list with specific type ranges and HTTP status checking Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Modernize the library to align with the current ClickHouse HTTP API, follow Go style guidelines, and add CI/CD.
API Improvements
Type System
Bug Fixes
Go Style Refactoring
Build & CI
Integration Tests (26 tests against real ClickHouse)
Docs
Test plan