From a732f325dac7b61c083c18183606deafe285d5a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markenson=20Paulo=20Fran=C3=A7a?= Date: Sat, 16 Jan 2021 10:54:12 -0300 Subject: [PATCH] Adding http support --- csv/project.clj | 4 ++-- csv/src/metabase/driver/csv.clj | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/csv/project.clj b/csv/project.clj index 1b01465..c749252 100644 --- a/csv/project.clj +++ b/csv/project.clj @@ -1,9 +1,9 @@ -(defproject metabase/csv-driver "1.0.0-SNAPSHOT" +(defproject metabase/csv-driver "1.0.1-SNAPSHOT" :min-lein-version "2.5.0" :repositories {"sonartype snapshots" "https://oss.sonatype.org/content/repositories/snapshots"} :dependencies - [[br.com.markenson/csvjdbc "1.0.10-metabase-SNAPSHOT"]] + [[br.com.markenson/csvjdbc "1.1.1-metabase-SNAPSHOT"]] :profiles {:provided diff --git a/csv/src/metabase/driver/csv.clj b/csv/src/metabase/driver/csv.clj index 37d4cf0..e903b18 100644 --- a/csv/src/metabase/driver/csv.clj +++ b/csv/src/metabase/driver/csv.clj @@ -63,13 +63,21 @@ (defmethod sql-jdbc.sync/database-type->base-type :csv [_ database-type] (database-type->base-type database-type)) + +(defn is-http [path] (if (clojure.string/starts-with? (clojure.string/lower-case path) "http") true false)) + (defmethod sql-jdbc.conn/connection-details->spec :csv [_ {:keys [csv separator charset advanced] :or {csv "arquivo.csv"} :as details}] + +(def strHttp (if (is-http csv) ":class:br.markenson.com.csvjdbc4metabase.readers.HttpCSVReader" "")) + +(def customBaseUrl (if (is-http csv) (str "&customBaseUrl=" csv) "")) + (merge {:classname "org.relique.jdbc.csv.CsvDriver" - :subprotocol "relique:csv" - :subname (str csv "?separator=" separator "&charset=" charset advanced) + :subprotocol (str "relique:csv" strHttp) + :subname (str (if (is-http csv) "" csv) "?separator=" separator "&charset=" charset customBaseUrl advanced) } - (dissoc details :csv :separator :charset :advanced)) - + (dissoc details :csv :separator :charset :customBaseUrl :advanced)) + )