CH.Native
0.1.18
dotnet add package CH.Native --version 0.1.18
NuGet\Install-Package CH.Native -Version 0.1.18
<PackageReference Include="CH.Native" Version="0.1.18" />
<PackageVersion Include="CH.Native" Version="0.1.18" />
<PackageReference Include="CH.Native" />
paket add CH.Native --version 0.1.18
#r "nuget: CH.Native, 0.1.18"
#:package CH.Native@0.1.18
#addin nuget:?package=CH.Native&version=0.1.18
#tool nuget:?package=CH.Native&version=0.1.18
CH.Native
A high-performance .NET 8 client for ClickHouse using the native binary TCP protocol.
Quick Start
dotnet add package CH.Native
await using var connection = new ClickHouseConnection("Host=localhost;Port=9000");
await connection.OpenAsync();
var result = await connection.ExecuteScalarAsync<int>("SELECT 1");
Console.WriteLine(result); // 1
See the Getting Started Guide for more examples.
Features
- Native Binary Protocol - Direct TCP communication on port 9000 for optimal performance
- Full Async/Await - All operations are async with streaming support
- ADO.NET Provider - Standard
DbConnectionimplementation with Dapper compatibility - Bulk Insert - High-performance batched inserts with typed mapping
- Compression - LZ4 (default) and Zstd compression support
- Resilience - Built-in retry policies, circuit breakers, and health checking
- Load Balancing - Multi-server support with round-robin, random, or first-available strategies
- TLS/SSL - Secure connections with certificate validation
- Telemetry - OpenTelemetry-compatible tracing, metrics, and logging
- Type Safety - Full support for all ClickHouse types with .NET mapping
Installation
dotnet add package CH.Native
Basic Usage
Execute a Query
await using var connection = new ClickHouseConnection("Host=localhost;Port=9000");
await connection.OpenAsync();
// Scalar query
var count = await connection.ExecuteScalarAsync<long>("SELECT count() FROM users");
// DDL/DML
await connection.ExecuteNonQueryAsync("CREATE TABLE IF NOT EXISTS users (id UInt32, name String) ENGINE = Memory");
Query with Parameters
var users = await connection.QueryAsync<User>(
"SELECT * FROM users WHERE age > @minAge",
new { minAge = 18 }
).ToListAsync();
Typed Results
public class User
{
public uint Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
await foreach (var user in connection.QueryAsync<User>("SELECT * FROM users"))
{
Console.WriteLine($"{user.Id}: {user.Name}");
}
Bulk Insert
var users = new List<User> { /* ... */ };
await using var inserter = connection.CreateBulkInserter<User>("users");
await inserter.InitAsync();
await inserter.AddRangeAsync(users);
await inserter.CompleteAsync();
ADO.NET / Dapper
await using var connection = new ClickHouseDbConnection("Host=localhost;Port=9000");
await connection.OpenAsync();
// Dapper
var users = await connection.QueryAsync<User>("SELECT * FROM users");
Documentation
| Guide | Description |
|---|---|
| Quick Start | Get up and running in minutes |
| Configuration | Connection strings, settings, TLS, multi-server |
| Data Types | ClickHouse to .NET type mapping reference |
| Resilience | Retry policies, circuit breakers, load balancing |
| Bulk Insert | High-performance data loading |
| ADO.NET & Dapper | Standard provider and ORM integration |
| Telemetry | Tracing, metrics, and logging |
Performance
CH.Native uses the native binary protocol (port 9000) instead of HTTP, resulting in lower latency and significantly reduced memory allocations.
Query Performance
| Benchmark | Native TCP | HTTP | Improvement |
|---|---|---|---|
| SELECT 1 | 544 μs | 733 μs | 1.3x faster |
| SELECT 100 rows | 668 μs | 1,036 μs | 1.6x faster |
| COUNT(*) 1M rows | 948 μs | 1,170 μs | 1.2x faster |
| Read 1M rows (streaming) | 123 ms | 296 ms | 2.4x faster |
| Bulk insert 1M rows | 93 ms | 180 ms | 1.9x faster |
Memory Efficiency
| Benchmark | Native TCP | HTTP | Improvement |
|---|---|---|---|
| SELECT 1 | 266 KB | 545 KB | 2x less |
| Read 1M rows | 143 MB | 191 MB | 25% less |
| Bulk insert 1M rows | 44 MB | 120 MB | 2.7x less |
Benchmarks run on Apple M5, .NET 8.0, ClickHouse 24.8
Requirements
- .NET 8.0 or later
- ClickHouse server with native protocol enabled (port 9000)
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- K4os.Compression.LZ4 (>= 1.3.8)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- System.Diagnostics.DiagnosticSource (>= 8.0.1)
- System.IO.Pipelines (>= 8.0.0)
- ZstdSharp.Port (>= 0.8.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.