@@ -12,20 +12,20 @@ integration:
1212 website : ' https://github.com/ClickHouse/clickhouse-cs'
1313---
1414
15- # ClickHouse C# Client
15+ # ClickHouse C# client
1616
1717The official C# client for connecting to ClickHouse.
1818The client source code is available in the [ GitHub repository] ( https://github.com/ClickHouse/clickhouse-cs ) .
1919Originally developed by [ Oleg V. Kozlyuk] ( https://github.com/DarkWanderer ) .
2020
21- ## Migration Guide {#migration-guide}
21+ ## Migration guide {#migration-guide}
2222
23231 . Update your ` .csproj ` file with the new package name ` ClickHouse.Driver ` and [ the latest version on NuGet] ( https://www.nuget.org/packages/ClickHouse.Driver ) .
24242 . Update all ` ClickHouse.Client ` references to ` ClickHouse.Driver ` in your codebase.
2525
2626---
2727
28- ## Supported .NET Versions {#supported-net-versions}
28+ ## Supported .NET versions {#supported-net-versions}
2929
3030` ClickHouse.Driver ` supports the following .NET versions:
3131
@@ -41,18 +41,20 @@ Originally developed by [Oleg V. Kozlyuk](https://github.com/DarkWanderer).
4141## Installation {#installation}
4242
4343Install the package from NuGet:
44+
4445``` bash
4546dotnet add package ClickHouse.Driver
4647```
4748
4849Or using the NuGet Package Manager:
50+
4951``` bash
5052Install-Package ClickHouse.Driver
5153```
5254
5355---
5456
55- ## Quick Start {#quick-start}
57+ ## Quick start {#quick-start}
5658
5759``` csharp
5860using ClickHouse .Driver .ADO ;
@@ -65,6 +67,7 @@ using (var connection = new ClickHouseConnection("Host=my.clickhouse;Protocol=ht
6567```
6668
6769Using ** Dapper** :
70+
6871``` csharp
6972using Dapper ;
7073using ClickHouse .Driver .ADO ;
@@ -80,7 +83,7 @@ using (var connection = new ClickHouseConnection("Host=my.clickhouse"))
8083
8184## Usage {#usage}
8285
83- ### Connection String Parameters {#connection-string}
86+ ### Connection string parameters {#connection-string}
8487
8588| Parameter | Description | Default |
8689| ------------------- | ----------------------------------------------- | ------------------- |
@@ -90,7 +93,7 @@ using (var connection = new ClickHouseConnection("Host=my.clickhouse"))
9093| ` Username ` | Authentication username | ` default ` |
9194| ` Password ` | Authentication password | * (empty)* |
9295| ` Protocol ` | Connection protocol (` http ` or ` https ` ) | ` http ` |
93- | ` Compression ` | Enables GZip compression | ` true ` |
96+ | ` Compression ` | Enables Gzip compression | ` true ` |
9497| ` UseSession ` | Enables persistent server session | ` false ` |
9598| ` SessionId ` | Custom session ID | Random GUID |
9699| ` Timeout ` | HTTP timeout (seconds) | ` 120 ` |
@@ -99,15 +102,17 @@ using (var connection = new ClickHouseConnection("Host=my.clickhouse"))
99102
100103** Example:** ` Host=clickhouse;Port=8123;Username=default;Password=;Database=default `
101104
102- ** Note about sessions: **
105+ :::note Sessions
103106
104107` UseSession ` flag enables persistence of server session, allowing use of ` SET ` statements and temp tables. Session will be reset after 60 seconds of inactivity (default timeout). Session lifetime can be extended by setting session settings via ClickHouse statements.
105108
106- ` ClickHouseConnection ` class normally allows for parallel operation (multiple threads can run queries concurrently). However, enabling ` UseSession ` flag will limit that to one active query per connection at any moment of time (serverside limitation).
109+ ` ClickHouseConnection ` class normally allows for parallel operation (multiple threads can run queries concurrently). However, enabling ` UseSession ` flag will limit that to one active query per connection at any moment of time (server-side limitation).
110+
111+ :::
107112
108113---
109114
110- ### Connection Lifetime & Pooling {#connection-lifetime}
115+ ### Connection lifetime and pooling {#connection-lifetime}
111116
112117` ClickHouse.Driver ` uses ` System.Net.Http.HttpClient ` under the hood. ` HttpClient ` has a per-endpoint connection pool. As a consequence:
113118
@@ -125,9 +130,10 @@ For DI environments, there is a bespoke constructor `ClickHouseConnection(string
125130
126131---
127132
128- ### Creating a Table {#creating-a-table}
133+ ### Creating a table {#creating-a-table}
129134
130135Create a table using standard SQL syntax:
136+
131137``` csharp
132138using ClickHouse .Driver .ADO ;
133139
@@ -145,9 +151,10 @@ using (var connection = new ClickHouseConnection(connectionString))
145151
146152---
147153
148- ### Inserting Data {#inserting-data}
154+ ### Inserting data {#inserting-data}
149155
150156Insert data using parameterized queries:
157+
151158``` csharp
152159using ClickHouse .Driver .ADO ;
153160
@@ -167,13 +174,14 @@ using (var connection = new ClickHouseConnection(connectionString))
167174
168175---
169176
170- ### Bulk Insert {#bulk-insert}
177+ ### Bulk insert {#bulk-insert}
171178
172179Using ` ClickHouseBulkCopy ` requires:
173180
174181* Target connection (` ClickHouseConnection ` instance)
175182* Target table name (` DestinationTableName ` property)
176183* Data source (` IDataReader ` or ` IEnumerable<object[]> ` )
184+
177185``` csharp
178186using ClickHouse .Driver .ADO ;
179187using ClickHouse .Driver .Copy ;
@@ -197,17 +205,17 @@ await bulkCopy.WriteToServerAsync(values);
197205Console .WriteLine ($" Rows written: {bulkCopy .RowsWritten }" );
198206```
199207
200- ** Notes:**
201-
202- * For optimal performance, ClickHouseBulkCopy uses the Task Parallel Library (TPL) to process batches of data, with up to 4 parallel insertion tasks (tweakable).
208+ ::: note
209+ * For optimal performance, ClickHouseBulkCopy uses the Task Parallel Library (TPL) to process batches of data, with up to 4 parallel insertion tasks (this can be tuned).
203210* Column names can be optionally provided via ` ColumnNames ` property if source data has fewer columns than target table.
204211* Configurable parameters: ` Columns ` , ` BatchSize ` , ` MaxDegreeOfParallelism ` .
205212* Before copying, a ` SELECT * FROM <table> LIMIT 0 ` query is performed to get information about target table structure. Types of provided objects must reasonably match the target table.
206213* Sessions are not compatible with parallel insertion. Connection passed to ` ClickHouseBulkCopy ` must have sessions disabled, or ` MaxDegreeOfParallelism ` must be set to ` 1 ` .
214+ :::
207215
208216---
209217
210- ### Performing SELECT Queries {#performing-select-queries}
218+ ### Performing SELECT queries {#performing-select-queries}
211219
212220Execute SELECT queries and process results:
213221
@@ -234,7 +242,8 @@ using (var connection = new ClickHouseConnection(connectionString))
234242
235243---
236244
237- ### Raw Streaming {#raw-streaming}
245+ ### Raw streaming {#raw-streaming}
246+
238247``` csharp
239248using var command = connection .CreateCommand ();
240249command .Text = " SELECT * FROM default.my_table LIMIT 100 FORMAT JSONEachRow" ;
@@ -246,15 +255,17 @@ var json = reader.ReadToEnd();
246255
247256---
248257
249- ### Nested Columns Support {#nested-columns}
258+ ### Nested columns support {#nested-columns}
250259
251260ClickHouse nested types (` Nested(...) ` ) can be read and written using array semantics.
261+
252262``` sql
253263CREATE TABLE test .nested (
254264 id UInt32,
255265 params Nested (param_id UInt8, param_val String)
256266) ENGINE = Memory
257267```
268+
258269``` csharp
259270using var bulkCopy = new ClickHouseBulkCopy (connection )
260271{
@@ -269,56 +280,62 @@ await bulkCopy.WriteToServerAsync(new[] { row1, row2 });
269280
270281---
271282
272- ### AggregateFunction Columns {#aggregatefunction-columns}
283+ ### AggregateFunction columns {#aggregatefunction-columns}
273284
274285Columns of type ` AggregateFunction(...) ` cannot be queried or inserted directly.
275286
276287To insert:
288+
277289``` sql
278290INSERT INTO t VALUES (uniqState(1 ));
279291```
280292
281293To select:
294+
282295``` sql
283296SELECT uniqMerge(c) FROM t;
284297```
285298
286299---
287300
288- ### SQL Parameters {#sql-parameters}
301+ ### SQL parameters {#sql-parameters}
289302
290303To pass parameters in query, ClickHouse parameter formatting must be used, in following form:
304+
291305``` sql
292306{< name> :< data type> }
293307```
294308
295309** Examples:**
310+
296311``` sql
297312SELECT {value:Array(UInt16)} as value
298313```
314+
299315``` sql
300316SELECT * FROM table WHERE val = {tuple_in_tuple:Tuple(UInt8, Tuple(String, UInt8))}
301317```
318+
302319``` sql
303320INSERT INTO table VALUES ({val1:Int32}, {val2:Array(UInt8)})
304321```
305322
306- ** Notes:**
307-
323+ ::: note
308324* SQL 'bind' parameters are passed as HTTP URI query parameters, so using too many of them may result in a "URL too long" exception.
309325* To insert large volume of records, consider using Bulk Insert functionality.
326+ :::
310327
311328---
312329
313- ## Supported Data Types {#supported-data-types}
330+ ## Supported data types {#supported-data-types}
314331
315332` ClickHouse.Driver ` supports the following ClickHouse data types with their corresponding .NET type mappings:
316333
317- ### Boolean Types {#boolean-types}
334+ ### Boolean types {#boolean-types}
318335
319336* ` Bool ` → ` bool `
320337
321- ### Numeric Types {#numeric-types}
338+ ### Numeric types {#numeric-types}
322339
323340** Signed Integers:**
324341* ` Int8 ` → ` sbyte `
@@ -347,31 +364,31 @@ INSERT INTO table VALUES ({val1:Int32}, {val2:Array(UInt8)})
347364* ` Decimal128 ` → ` decimal `
348365* ` Decimal256 ` → ` BigDecimal `
349366
350- ### String Types {#string-types}
367+ ### String types {#string-types}
351368
352369* ` String ` → ` string `
353370* ` FixedString ` → ` string `
354371
355- ### Date and Time Types {#date-time-types}
372+ ### Date and time types {#date-time-types}
356373
357374* ` Date ` → ` DateTime `
358375* ` Date32 ` → ` DateTime `
359376* ` DateTime ` → ` DateTime `
360377* ` DateTime32 ` → ` DateTime `
361378* ` DateTime64 ` → ` DateTime `
362379
363- ### Network Types {#network-types}
380+ ### Network types {#network-types}
364381
365382* ` IPv4 ` → ` IPAddress `
366383* ` IPv6 ` → ` IPAddress `
367384
368- ### Geographic Types {#geographic-types}
385+ ### Geographic types {#geographic-types}
369386
370387* ` Point ` → ` Tuple `
371388* ` Ring ` → ` Array of Points `
372389* ` Polygon ` → ` Array of Rings `
373390
374- ### Complex Types {#complex-types}
391+ ### Complex types {#complex-types}
375392
376393* ` Array(T) ` → ` Array of any type `
377394* ` Tuple(T1, T2, ...) ` → ` Tuple of any types `
@@ -380,7 +397,7 @@ INSERT INTO table VALUES ({val1:Int32}, {val2:Array(UInt8)})
380397
381398---
382399
383- ### DateTime Handling {#datetime-handling}
400+ ### DateTime handling {#datetime-handling}
384401
385402` ClickHouse.Driver ` tries to correctly handle timezones and ` DateTime.Kind ` property. Specifically:
386403
@@ -393,7 +410,7 @@ INSERT INTO table VALUES ({val1:Int32}, {val2:Array(UInt8)})
393410
394411---
395412
396- ### Environment Variables {#environment-variables}
413+ ### Environment variables {#environment-variables}
397414
398415You can set defaults using environment variables:
399416
@@ -403,15 +420,18 @@ You can set defaults using environment variables:
403420| ` CLICKHOUSE_USER ` | Default username |
404421| ` CLICKHOUSE_PASSWORD ` | Default password |
405422
406- ** Note:** Values provided explicitly to the ` ClickHouseConnection ` constructor will take priority over environment variables.
423+ ::: note
424+ Values provided explicitly to the ` ClickHouseConnection ` constructor will take priority over environment variables.
425+ :::
407426
408427---
409428
410- ### ORM & Dapper Support {#orm-support}
429+ ### ORM & Dapper support {#orm-support}
411430
412431` ClickHouse.Driver ` supports Dapper (with limitations).
413432
414433** Working example:**
434+
415435``` csharp
416436connection .QueryAsync <string >(
417437 " SELECT {p1:Int32}" ,
@@ -420,6 +440,7 @@ connection.QueryAsync<string>(
420440```
421441
422442** Not supported:**
443+
423444``` csharp
424445connection .QueryAsync <string >(
425446 " SELECT {p1:Int32}" ,
0 commit comments