CH.Native 0.1.18

dotnet add package CH.Native --version 0.1.18
                    
NuGet\Install-Package CH.Native -Version 0.1.18
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CH.Native" Version="0.1.18" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CH.Native" Version="0.1.18" />
                    
Directory.Packages.props
<PackageReference Include="CH.Native" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CH.Native --version 0.1.18
                    
#r "nuget: CH.Native, 0.1.18"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CH.Native@0.1.18
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CH.Native&version=0.1.18
                    
Install as a Cake Addin
#tool nuget:?package=CH.Native&version=0.1.18
                    
Install as a Cake Tool

CH.Native

A high-performance .NET 8 client for ClickHouse using the native binary TCP protocol.

NuGet .NET License

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 DbConnection implementation 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.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.18 85 1/11/2026
0.1.16 84 1/11/2026
0.1.15 72 1/11/2026
0.1.12 77 1/11/2026
0.1.0 80 1/11/2026