> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> ClickHouse R2DBC 드라이버

# R2DBC 드라이버

<div id="r2dbc-driver">
  ## R2DBC 드라이버
</div>

ClickHouse용 비동기 Java 클라이언트를 위한 [R2DBC](https://r2dbc.io/) 래퍼입니다.

<div id="environment-requirements">
  ### 환경 요구 사항
</div>

* [OpenJDK](https://openjdk.java.net) 버전 8 이상

<div id="setup">
  ### 설정
</div>

```xml theme={null}
<dependency>
    <groupId>com.clickhouse</groupId>
    <!-- SPI 0.9.1.RELEASE의 경우 clickhouse-r2dbc_0.9.1로 변경하십시오 -->
    <artifactId>clickhouse-r2dbc</artifactId>
    <version>0.7.1</version>
    <!-- 모든 의존성이 포함된 uber jar를 사용하려면 그대로 두고, 더 작은 jar가 필요하면 classifier를 http 또는 grpc로 변경하십시오 -->
    <classifier>all</classifier>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>
```

<div id="connect-to-clickhouse">
  ### ClickHouse에 연결하기
</div>

```java showLineNumbers theme={null}
ConnectionFactory connectionFactory = ConnectionFactories
    .get("r2dbc:clickhouse:http://{username}:{password}@{host}:{port}/{database}");

    Mono.from(connectionFactory.create())
        .flatMapMany(connection -> connection
```

<div id="query">
  ### 쿼리
</div>

```java showLineNumbers theme={null}
connection
    .createStatement("select domain, path,  toDate(cdate) as d, count(1) as count from clickdb.clicks where domain = :domain group by domain, path, d")
    .bind("domain", domain)
    .execute()
    .flatMap(result -> result
    .map((row, rowMetadata) -> String.format("%s%s[%s]:%d", row.get("domain", String.class),
        row.get("path", String.class),
        row.get("d", LocalDate.class),
        row.get("count", Long.class)))
    )
    .doOnNext(System.out::println)
    .subscribe();
```

<div id="insert">
  ### 삽입
</div>

```java showLineNumbers theme={null}
connection
    .createStatement("insert into clickdb.clicks values (:domain, :path, :cdate, :count)")
    .bind("domain", click.getDomain())
    .bind("path", click.getPath())
    .bind("cdate", LocalDateTime.now())
    .bind("count", 1)
    .execute();
```
