diff --git a/README.md b/README.md index a3f0528..ae6545e 100644 --- a/README.md +++ b/README.md @@ -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