Skip to content

ClickHouseRepository

Sych edited this page Apr 16, 2020 · 2 revisions

ClickHouseRepository

IClickHouseRepository and its implementation ClickHouseRepository simplify the work of executing requests to ClickHouse.

Features

  • There is no need to think about opening and closing connections - they will be automatically taken from the connection pool and closed when necessary.
  • Wrappers for BULK INSERT queries allow you to not write a query at all, but only to use the names of tables and columns as a method parameters.
  • Wrapper for the SELECT query can map the query result to the user model.
  • Using the repository, you can also execute any other request that allows the driver ClickHouse-Net.

Using with dependency injection

You can connect the repository to the DI mechanism using the extension AddClickHouseRepository(IConfigurationSection configuration) such as:

public void ConfigureServices(IServiceCollection services)
{
    services.AddClickHouseRepository(config.GetSection("ClickHouseConnectionPoolConfiguration"));

    //...
}

In the extension method, you must pass the configuration section for the repository, which has the following form:

"ClickHouseConnectionPoolConfiguration": {
"ConnectionStrings": [
    "Host=Host;Port=Port;Database=default;User=default;Password="
],
"ConnectionPoolMaxCount": 4,
"ConnectionPoolName": "ClickHouseConnectionPool"
}

Next - you can use IClickHouseRepository with DI:

public class TestClass
{
    private readonly IClickHouseRepository _clickHouseRepository;

    public TestClass(IClickHouseRepository clickHouseRepository)
    {
        _clickHouseRepository = clickHouseRepository;
    }

    public void Foo()
    {
        // use repository
    }
}

Clone this wiki locally