From 6f58f1d911f5c6b28f2715b84a8509f311263b76 Mon Sep 17 00:00:00 2001 From: fr33m0nk Date: Wed, 8 Feb 2023 23:52:47 +0530 Subject: [PATCH 1/5] [fr33m0nk]: Adds example of using `Hikari-CP` with `Clickhouse` --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index a3f0528..18f415e 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,43 @@ Custom translations of properties can be added by extending the (def datasource-options {:jdbc-url "jdbc:sqlite:db/database.db"}) ``` +### Clickhouse example +- 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"}) + +(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 From e433dbd9b8c08c2fbfb87b8fb8fc527de9187328 Mon Sep 17 00:00:00 2001 From: fr33m0nk Date: Wed, 8 Feb 2023 23:56:33 +0530 Subject: [PATCH 2/5] [fr33m0nk]: Updates ReadMe with link to Clickhouse official driver --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 18f415e..c251087 100644 --- a/README.md +++ b/README.md @@ -214,8 +214,8 @@ Custom translations of properties can be added by extending the (def datasource-options {:jdbc-url "jdbc:sqlite:db/database.db"}) ``` -### Clickhouse example -- Official ClickHouse JDBC driver's `ClickHouseDataSource` does not have a zero arity constructor. +### ClickHouse example +- [Official ClickHouse JDBC driver](https://github.com/ClickHouse/clickhouse-java)'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 From c1e8dc12e354dd072dbcc56c561484606a142659 Mon Sep 17 00:00:00 2001 From: fr33m0nk Date: Wed, 8 Feb 2023 23:58:53 +0530 Subject: [PATCH 3/5] [fr33m0nk]: Adds missing `datasource` in Clickhouse example --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c251087..659172c 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,9 @@ Custom translations of properties can be added by extending the :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})] From 8f7a97aab7ba1554b9620dd86a75c448cbc85ecd Mon Sep 17 00:00:00 2001 From: fr33m0nk Date: Thu, 9 Feb 2023 00:04:00 +0530 Subject: [PATCH 4/5] [fr33m0nk]: Corrects formatting --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 659172c..a781abe 100644 --- a/README.md +++ b/README.md @@ -227,14 +227,14 @@ Custom translations of properties can be added by extending the [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))) + (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 From 3eb9c2ad232c4dc11370fc99f50af499ae4f8aaa Mon Sep 17 00:00:00 2001 From: fr33m0nk Date: Thu, 9 Feb 2023 01:02:06 +0530 Subject: [PATCH 5/5] [fr33m0nk]: Updates ReadMe with both examples --- README.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a781abe..ae6545e 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,9 @@ Custom translations of properties can be added by extending the ``` ### ClickHouse example -- [Official ClickHouse JDBC driver](https://github.com/ClickHouse/clickhouse-java)'s `ClickHouseDataSource` does not have a zero arity constructor. +`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 @@ -246,6 +248,33 @@ Custom translations of properties can be added by extending the (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})]