AnyoneDeveloper.ClickHouse.ConnectionPool 1.0.1

dotnet add package AnyoneDeveloper.ClickHouse.ConnectionPool --version 1.0.1                
NuGet\Install-Package AnyoneDeveloper.ClickHouse.ConnectionPool -Version 1.0.1                
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="AnyoneDeveloper.ClickHouse.ConnectionPool" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AnyoneDeveloper.ClickHouse.ConnectionPool --version 1.0.1                
#r "nuget: AnyoneDeveloper.ClickHouse.ConnectionPool, 1.0.1"                
#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.
// Install AnyoneDeveloper.ClickHouse.ConnectionPool as a Cake Addin
#addin nuget:?package=AnyoneDeveloper.ClickHouse.ConnectionPool&version=1.0.1

// Install AnyoneDeveloper.ClickHouse.ConnectionPool as a Cake Tool
#tool nuget:?package=AnyoneDeveloper.ClickHouse.ConnectionPool&version=1.0.1                

anyone-dotnet-use-clickhouse-connection-pool

This nuget package help you to use Octonica.ClickHouseClient with connection pool. You can fully control the concurrent query with "select" I/O mode. The original client repo is here: https://github.com/Octonica/ClickHouseClient

This repo would bundle nuget package. Anyone can reference it from nuget.org.

nuget package: https://www.nuget.org/packages/AnyoneDeveloper.ClickHouse.ConnectionPool/

If you like my module, please buy me a coffee.

More and more tiny and useful GitHub action modules are on the way. Please donate to me. I accept a part-time job contract. if you need, please contact me: zhang_nan_163@163.com

How to use

Inject referenced class

  • Add AnyoneDeveloper.ClickHouse.ConnectionPool package reference.
  • Inject Repository and Connection class
    • Inject Repository class
      services.AddScoped<IClickHouseRepository, ClickHouseRepository>();
    
    • Inject Connection class
      services.AddSingleton(x => new ClickHouseConnection(_configuration.GetValue<int>("Connection:Count"), _configuration.GetValue<string>("ConnectionStrings:SRV"))
           .InitSemaphore(_configuration.GetValue<int>("Connection:InitialConcurrentCount"), _configuration.GetValue<int>("Connection:MaximumConcurrentCount")));
    

Set up configuration

  • Set up connection pool size It should greater than concurrent size.
  • Set up SemaphoreSlim InitCount and MaxCount

Define execution method

  private static async Task<IEnumerable<Foo>> GetSomeDataAsync(ClickHouseConnection conn, string sql)
  {
      using var cmd = conn.CreateCommand(sql);
      var items = new List<Foo>();
      using (var reader = await cmd.ExecuteReaderAsync())
      {
          while (await reader.ReadAsync())
          {
              var item = new Foo();
              item.ID = await reader.GetFieldValueAsync<int>(0);
              item.Name = await reader.GetFieldValueAsync<string>(1);
              item.Job = await reader.GetFieldValueAsync<string>(2);

              items.Add(item);
          }
      }
      return items;
  }

Use it as below code:

  var sql = @"SELECT ID, Name, Job FROM one_table";
  var data = repository.GetResultAsync((conn) => GetSomeDataAsync(conn, sql));

You can reference complete code from Demo

Donation

PalPal: https://paypal.me/nzhang4

<img src="https://raw.githubusercontent.com/anyone-developer/anyone-dotnet-use-grpc-ui/main/misc/alipay.JPG" width="500">

<img src="https://raw.githubusercontent.com/anyone-developer/anyone-dotnet-use-grpc-ui/main/misc/webchat_pay.JPG" width="500">

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
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
1.0.1 421 5/20/2021
1.0.0 731 5/19/2021 1.0.0 is deprecated.