Aiursoft.ClickhouseSdk
10.0.13
See the version list below for details.
dotnet add package Aiursoft.ClickhouseSdk --version 10.0.13
NuGet\Install-Package Aiursoft.ClickhouseSdk -Version 10.0.13
<PackageReference Include="Aiursoft.ClickhouseSdk" Version="10.0.13" />
<PackageVersion Include="Aiursoft.ClickhouseSdk" Version="10.0.13" />
<PackageReference Include="Aiursoft.ClickhouseSdk" />
paket add Aiursoft.ClickhouseSdk --version 10.0.13
#r "nuget: Aiursoft.ClickhouseSdk, 10.0.13"
#:package Aiursoft.ClickhouseSdk@10.0.13
#addin nuget:?package=Aiursoft.ClickhouseSdk&version=10.0.13
#tool nuget:?package=Aiursoft.ClickhouseSdk&version=10.0.13
Aiursoft ClickHouse SDK & Logger Provider
A high-performance, textbook-grade ClickHouse integration suite for .NET applications. It provides an effortless way to interact with ClickHouse using a "DbContext" style pattern and a high-performance logging provider for the standard Microsoft.Extensions.Logging infrastructure.
Key Features
- Automatic Schema Management: Automatically creates databases and tables. Supports schema evolution (automatically adds missing columns).
- High-Performance Bulk Writing: Uses
ClickHouseBulkCopyfor asynchronous, non-blocking batch uploads. - Background Log Flushing: Buffered logging with background flushing to ensure zero impact on application performance.
- Clean Configuration: Standard ClickHouse connection strings. Table names are managed through code or configuration.
Project 1: Aiursoft.ClickhouseSdk (Core SDK)
The core SDK provides the base infrastructure for ClickHouse communication.
Installation
dotnet add package Aiursoft.ClickhouseSdk
Basic Usage
Define your Entity: Create a class representing your data row.
Create your DbContext: Inherit from
ClickhouseDbContextand define your sets.
using Aiursoft.ClickhouseSdk;
using Aiursoft.ClickhouseSdk.Abstractions;
public class MyDbContext : ClickhouseDbContext
{
public ClickhouseSet<MyEntity> MyEntities { get; }
public MyDbContext(IOptionsMonitor<ClickhouseOptions> options) : base(options)
{
// Define the mapping from your entity to ClickHouse row objects
// You can have multiple sets mapping to different tables in the same database!
MyEntities = new ClickhouseSet<MyEntity>(GetConnection, "MyTableName", entity => new object[]
{
entity.Id,
entity.Name,
entity.CreatedAt
});
}
public override async Task SaveChangesAsync()
{
await MyEntities.SaveChangesAsync();
}
}
- Register and Configure:
In your
Program.cs, register your DbContext and bind the configuration.
// 1. Bind configuration (from appsettings.json or environment variables)
builder.Services.Configure<ClickhouseOptions>(options =>
{
options.ConnectionString = "Host=localhost;Database=MyBusinessDb;User=default;Password=password";
});
// 2. Register your custom DbContext
builder.Services.AddSingleton<MyDbContext>();
- Initialize the Schema:
Call
InitClickhouseTableAsync<T>during application startup.
// This will ensure 'MyTableName' exists in the database defined in your connection string.
await host.Services.InitClickhouseTableAsync<MyEntity>("MyTableName", "CreatedAt");
Configuration via appsettings.json
Both projects use the same ClickhouseOptions structure. You can define your settings in appsettings.json:
{
"Clickhouse": {
"ConnectionString": "Host=localhost;Database=DemoDb;User=default;Password=password",
"TableName": "AppLogs",
"Enabled": true
}
}
And bind it in your code:
builder.Services.Configure<ClickhouseOptions>(builder.Configuration.GetSection("Clickhouse"));
Project 2: Aiursoft.ClickhouseLoggerProvider (Logging)
A specialized provider that redirects standard ILogger output to ClickHouse.
Installation
dotnet add package Aiursoft.ClickhouseLoggerProvider
Registration
Register the provider in your application builder.
builder.Logging.AddClickhouse(options =>
{
options.ConnectionString = "Host=localhost;Protocol=http;Port=8123;User=default;Password=password;Database=MyLogs";
options.TableName = "AppLogs"; // Optional, defaults to "AppLogs"
});
Initialization
Ensure the logging table is initialized at startup.
await host.Services.InitLoggingTableAsync();
How to Contribute
We welcome contributions! Please follow these steps:
- Fork the repository.
- Create a feature branch.
- Ensure all code passes
lint.shand all tests pass. - Submit a Pull Request.
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Aiursoft.ClickhouseSdk.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Aiursoft.ClickhouseSdk:
| Package | Downloads |
|---|---|
|
Aiursoft.ClickhouseLoggerProvider
A high-performance logging provider that redirects standard .NET ILogger output to ClickHouse. |
GitHub repositories
This package is not used by any popular GitHub repositories.