Skip to content

Commit

Permalink
Merge pull request tomekw#103 from fr33m0nk/master
Browse files Browse the repository at this point in the history
Adds ClickHouse usage documentation
  • Loading branch information
tomekw authored Feb 9, 2023
2 parents 8851840 + 3eb9c2a commit 002c252
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,75 @@ Custom translations of properties can be added by extending the
(def datasource-options {:jdbc-url "jdbc:sqlite:db/database.db"})
```

### ClickHouse example
`hikari-cp` can be used with [official ClickHouse driver](https://github.com/ClickHouse/clickhouse-java) in following two ways:
1. Using `:datasource` property:
- Official ClickHouse JDBC driver's `ClickHouseDataSource` does not have a zero arity constructor.
- This mandates creating `ClickHouseDataSource` separately and setting `:datasource` property in `datasource-options`
```clojure
(ns hikari-cp.example
(:require
[hikari-cp.core :refer :all]
[next.jdbc :as jdbc])
(:import
[java.util Properties]
[com.clickhouse.jdbc ClickHouseDataSource]))

(defonce clickhouse-datasource
(let [jdbc-url "jdbc:ch://localhost:8123/test_db"
properties (doto
(Properties.)
(.setProperty "user" "username")
(.setProperty "password" "password")
(.setProperty "client_name" "test_client")
(.setProperty "custom_http_params" "max_query_size=1000000"))]
(ClickHouseDataSource. jdbc-url properties)))

(def datasource-options
{:datasource clickhouse-datasource
:connection-timeout 5000
:maximum-pool-size 20
:max-lifetime 300000
:pool-name "clickhouse-conn-pool"})

(defonce datasource
(delay (make-datasource datasource-options)))

(defn -main
[& args]
(with-open [conn (jdbc/get-connection {:datasource @datasource})]
(let [rows (jdbc/execute! conn ["SELECT 0"])]
(println rows)))
(close-datasource @datasource))
```
2. Using `:jdbc-url` and `:driver-class-name` properties:
```clojure
(ns hikari-cp.example
(:require
[hikari-cp.core :refer :all]
[next.jdbc :as jdbc]))

(def datasource-options-2
{:jdbc-url "jdbc:ch://localhost:8123/test_db"
:username "username"
:password "password"
:driver-class-name "com.clickhouse.jdbc.ClickHouseDriver"
:connection-timeout 5000
:maximum-pool-size 20
:max-lifetime 300000
:pool-name "clickhouse-conn-pool"})

(defonce datasource
(delay (make-datasource datasource-options)))

(defn -main
[& args]
(with-open [conn (jdbc/get-connection {:datasource @datasource})]
(let [rows (jdbc/execute! conn ["SELECT 0"])]
(println rows)))
(close-datasource @datasource))
```

### Notice

`make-datasource` will throw `IllegalArgumentException` when invalid
Expand Down

0 comments on commit 002c252

Please sign in to comment.