-
Notifications
You must be signed in to change notification settings - Fork 0
ClickHouseRepository
Sych edited this page Apr 4, 2020
·
2 revisions
IClickHouseRepository and its implementation ClickHouseRepository simplify the work of executing requests to ClickHouse.
- 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.
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=192.168.159.131;Port=9011;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
}
}