From 337422ae16ad61ee778c44c6a9cc6fb9372eabe3 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Mon, 4 Jan 2021 16:03:33 +0100 Subject: [PATCH] upgrade to neo4j v4 and inmemory connection need to rework all queries to $ syntax --- project.clj | 18 ++++++++---------- src/wanijo/infrastructure/neo4j.clj | 13 ++++++++----- src/wanijo/infrastructure/repl.clj | 11 ++++++++--- src/wanijo/instance/routes.clj | 8 ++++---- src/wanijo/user/db.clj | 17 ++++++++++++++++- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/project.clj b/project.clj index 1abd4aa..b2fe02d 100644 --- a/project.clj +++ b/project.clj @@ -7,12 +7,12 @@ :dependencies [;;clojure core [org.clojure/clojure "1.10.1"] - [nrepl "0.7.0"] + [nrepl "0.8.3"] ;; static site - [compojure "1.6.1"] + [compojure "1.6.2"] [ring/ring-defaults "0.3.2"] - [ring/ring-jetty-adapter "1.8.0" + [ring/ring-jetty-adapter "1.8.2" :exclusions [ring/ring-core ring/ring-codec commons-io @@ -24,20 +24,18 @@ ;; compojure uses old transitive dependencies of ring ;; specifiy them here explicitly so newer versions ;; will be used - [ring/ring-core "1.8.0"] + [ring/ring-core "1.8.2"] [ring/ring-codec "1.1.2"] ;; neo4j - [gorillalabs/neo4j-clj "2.0.1" - :exclusions [org.bouncycastle/bcprov-jdk15on - org.bouncycastle/bcpkix-jdk15on - com.github.ben-manes.caffeine/caffeine]] + [gorillalabs/neo4j-clj "4.1.0"] + [org.neo4j.test/neo4j-harness "4.0.0"] ;; additional server side libs - [buddy/buddy-hashers "1.4.0" + [buddy/buddy-hashers "1.7.0" :exclusions [commons-codec]] [clj-time "0.15.2"] - [markdown-clj "1.10.1"] + [markdown-clj "1.10.5"] [dorothy "0.0.7"]] :profiles {:dev {:plugins [;; neo4j db diff --git a/src/wanijo/infrastructure/neo4j.clj b/src/wanijo/infrastructure/neo4j.clj index 77103f8..fd4b58a 100644 --- a/src/wanijo/infrastructure/neo4j.clj +++ b/src/wanijo/infrastructure/neo4j.clj @@ -1,11 +1,13 @@ (ns wanijo.infrastructure.neo4j (:require [neo4j-clj.core :as db] + [neo4j-clj.in-memory :as db-inm] [wanijo.infrastructure.devmode :as devmode] [clj-time.format :as time-format] [clj-time.local :as time-local] [clojure.spec.alpha :as spec] [clojure.string :as cljs]) - (:import (java.util UUID))) + (:import (java.util UUID) + (java.net URI))) (spec/def ::date-str #(re-matches #"\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}\.\d{3}Z" %)) @@ -29,7 +31,7 @@ (create-conn! port host user pass))) ([port host user pass] (db/connect - (str "bolt://" host ":" port) + (URI. (str "bolt://" host ":" port)) user pass))) @@ -42,6 +44,9 @@ ([port host user pass] (reset! conn (create-conn! port host user pass)))) +(defn in-memory-conn! [] + (reset! conn (db-inm/create-in-memory-connection))) + (defmacro defquery [& args] `(db/defquery ~@args)) (defn uuid [] @@ -57,9 +62,7 @@ (cljs/join \newline))) (defn exec-query! [qry params] - (let [live-conn (if (nil? @conn) - (reset-conn!) - @conn)] + (let [live-conn (or @conn (reset-conn!))] (with-open [session (db/get-session live-conn)] (devmode/send-to-bar (str (butiful-query qry) diff --git a/src/wanijo/infrastructure/repl.clj b/src/wanijo/infrastructure/repl.clj index 9888461..ea42587 100644 --- a/src/wanijo/infrastructure/repl.clj +++ b/src/wanijo/infrastructure/repl.clj @@ -5,9 +5,9 @@ (neo4j/defquery create-user "CREATE (n:user) - SET n.ident = {ident} - SET n.pw = {pw} - SET n.uuid = {uuid}") + SET n.ident = $ident + SET n.pw = $pw + SET n.uuid = $uuid") (defn create-user! [ident pw] (neo4j/exec-query! @@ -114,8 +114,13 @@ (main/start-server-dev!) (println "Started server at http://localhost:8080")) +(defn setup-in-memory! [] + (neo4j/in-memory-conn!) + (create-user! "admin" "admin")) + (comment (dev-server!) + (setup-in-memory!) (neo4j/reset-conn! "7688" "mokoscha" neo4j/standard-user diff --git a/src/wanijo/instance/routes.clj b/src/wanijo/instance/routes.clj index 367fb1f..53295f2 100644 --- a/src/wanijo/instance/routes.clj +++ b/src/wanijo/instance/routes.clj @@ -140,10 +140,10 @@ (let [names (-> req :params :name) instances (-> req :params :instances) source-uuid (-> req :params :source-uuid)] - (clojure.pprint/pprint names) - (clojure.pprint/pprint instances) - (clojure.pprint/pprint source-uuid) - (clojure.pprint/pprint +; (clojure.pprint/pprint names) +; (clojure.pprint/pprint instances) +; (clojure.pprint/pprint source-uuid) +#_ (clojure.pprint/pprint (map (fn [[target-schema target-instances]] {:link-name (get names target-schema) :instances target-instances}) diff --git a/src/wanijo/user/db.clj b/src/wanijo/user/db.clj index c5a728e..229bc9e 100644 --- a/src/wanijo/user/db.clj +++ b/src/wanijo/user/db.clj @@ -1,6 +1,7 @@ (ns wanijo.user.db (:require [clojure.spec.alpha :as spec] - [wanijo.infrastructure.neo4j :as neo4j])) + [wanijo.infrastructure.neo4j :as neo4j] + [neo4j-clj.core :as db])) (spec/def ::ident (spec/and string? not-empty)) @@ -24,6 +25,20 @@ first :n)) +(comment + (macroexpand '(db/defquery test-find-user + "MATCH (u:user) WHERE u.ident = {ident} RETURN u")) + (macroexpand '(neo4j/defquery + find-user + "MATCH (n:user) WHERE n.ident = {ident} RETURN n")) + + (require '[neo4j-clj.core :as db]) + (db/defquery test-find-user + "MATCH (u:user) WHERE u.ident = {ident} RETURN u") + (with-open [s (db/get-session @neo4j/conn)] + (test-find-user s {:ident "admin"})) + (neo4j/exec-query! test-find-user {:ident "admin"})) + (neo4j/defquery all "MATCH (u:user)