Skip to content

Commit

Permalink
Closes #6, Closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
bbenzikry committed Sep 27, 2020
1 parent 78f26ca commit 1ce5d7b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM metabase/metabase:v0.36.2

ADD --chown=2000:2000 \
https://github.com/bbenzikry/metabase-neo4j-driver/releases/download/v0.0.4/neo4j.metabase-driver.jar \
https://github.com/bbenzikry/metabase-neo4j-driver/releases/download/v0.0.5/neo4j.metabase-driver.jar \
/plugins/neo4j.neo4j-driver.jar
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{:deps {bbenzikry/neo4clj {:git/url "https://github.com/bbenzikry/neo4clj" :sha "6384a47a34378d528f29cdb5c62b68de4a6c48c5"}
{:deps {bbenzikry/neo4clj {:git/url "https://github.com/bbenzikry/neo4clj" :sha "6b0f55cd37fd5e11f08288641da820b0f9e4ca21"}
neo4j/neo4j-bi-jdbc {:mvn/version "1.0.0"}
org.neo4j/neo4j-cypher {:mvn/version "4.1.1"}}}
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject metabase/neo4j-driver "0.0.4-SNAPSHOT-neo4j-connector-1.0.0"
(defproject metabase/neo4j-driver "0.0.5-SNAPSHOT-neo4j-connector-1.0.0"
:min-lein-version "2.5.0"
; git repo support
:plugins [[lein-tools-deps "0.4.5"]]
Expand Down
6 changes: 5 additions & 1 deletion resources/metabase-plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# see: https://github.com/metabase/metabase/wiki/Metabase-Plugin-Manifest-Reference
info:
name: Metabase Neo4j Driver
version: 0.0.4-SNAPSHOT
version: 0.0.5-SNAPSHOT
description: Allows Metabase to connect to Neo4j.
driver:
name: neo4j
Expand All @@ -24,6 +24,10 @@ driver:
- merge:
- password
- default: default
- name: protocol
display-name: Protocol
description: One of bolt,bolt+s,bolt+ssc,neo4j,neo4j+s,neo4j+ssc
default: bolt
- merge:
- additional-options
- name: jdbc-flags
Expand Down
6 changes: 4 additions & 2 deletions src/metabase/driver/neo4j.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

(driver/register! :neo4j, :parent :sql-jdbc)
(defmethod driver/display-name :neo4j [_] "Neo4j 4")

(def accepted-neo-protocols (sorted-set "bolt" "bolt+s" "bolt+ssc" "neo4j" "neo4j+s" "neo4j+ssc"))
(defn- make-subname [host port db jdbc-flags]
(str "//" host ":" port "/" db jdbc-flags))

Expand Down Expand Up @@ -128,6 +128,8 @@

(defmethod sql-jdbc.conn/connection-details->spec :neo4j
[_ details]
(when-not (contains? accepted-neo-protocols (:protocol details))
(throw (Exception. (str "Protocol must be one of " (clojure.string/join ", " accepted-neo-protocols)))))
(-> details
(update :port (fn [port]
(if (string? port)
Expand All @@ -154,7 +156,7 @@
(try
(log/info "Received neo4j query. Checking if cypher ❓")
(.parse cypher-parser query cypher-exception-factory nil)
true (catch Throwable ex (log/info ex) false)))
true (catch Throwable ex (log/debug ex) false)))

(defmethod driver/execute-reducible-query :neo4j
[driver query chans respond]
Expand Down
10 changes: 2 additions & 8 deletions src/metabase/driver/neo4j/execute.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
results-metadata {:cols (sql-jdbc.execute/column-metadata driver rsmeta)}]
(respond results-metadata (sql-jdbc.execute/reducible-rows driver rs rsmeta (context/canceled-chan context)))))))

; TODO add with-neo4j-connection macro
(defn get-neo-connection
[{host :host port :port user :user password :password dbname :dbname}]
(let [base (str "bolt://" host ":" port)
url (if dbname (str base "/" dbname) base)]
(if password (neo4j/connect url user password) (neo4j/connect url user))))

(defn get-cypher-columns [result]
(if (seq? result)
{:cols (into [] (map #(assoc {} :name %) (keys (first (take 1 result)))))}
Expand All @@ -54,7 +47,8 @@
[_ {{query :query} :native} context respond]
(log/info "Executing reducible query for cypher")
(with-neo-connection [^Driver connection (:details (qp.store/database))]
(let [results (volatile! (neo4j/execute! connection query))
(let [dbname (:dbname (:details (qp.store/database)))
results (volatile! (neo4j/execute! connection dbname query))
nonseq-val (volatile! false)
columns (get-cypher-columns @results)
row-thunk #(if-not (seq? @results) ((if-not @nonseq-val (vreset! nonseq-val true) @results) nil)
Expand Down
5 changes: 2 additions & 3 deletions src/metabase/driver/neo4j/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
nil)

(defn get-neo-connection
[{host :host port :port user :user password :password dbname :dbname}]
(let [base (str "bolt://" host ":" port)
url (if dbname (str base "/" dbname) base)]
[{host :host port :port user :user password :password protocol :protocol}]
(let [url (str protocol "://" host ":" port)]
(if password (neo4j/connect url user password) (neo4j/connect url user))))

(defn -with-neo-connection
Expand Down

0 comments on commit 1ce5d7b

Please sign in to comment.