Skip to content

Commit

Permalink
fixed congraph typos as well as supporting named parameters for the g…
Browse files Browse the repository at this point in the history
…enerated function
  • Loading branch information
mackramraydan committed Jan 17, 2020
1 parent c580b9f commit 374bda4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(defproject congraph "0.0.1"
(defproject congraph "0.0.2"
:description "a neo4j connection management library based on conman"
:license {:name "Apache License, Version 2.0"
:url "http://www.apache.org/licenses/LICENSE-2.0.html"}
:dependencies [[org.clojure/clojure "1.10.1"]
[hugneo4j "0.0.1"]]
[hugneo4j "0.0.2"]]
:profiles
{:dev
{:dependencies [[mount "0.1.16"]]}})
35 changes: 30 additions & 5 deletions src/clj/congraph/core.clj → src/congraph/core.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
(ns congraph.core
(:require [clojure.java.io :as io]
[clojure.set :refer [rename-keys]]
[hugneo4j.core :as hugneo4j])
[hugneo4j.core :as hugneo4j]
[hugneo4j.cypher :as cypher])
(:import (clojure.lang IDeref)))

(defn validate-files [filenames]
(doseq [file filenames]
(when-not (or (instance? java.io.File file) (io/resource file))
(throw (Exception. (str "conman could not find the query file:" file))))))
(throw (Exception. (str "congraph could not find the query file:" file))))))

(defn try-snip [[id snip]]
[id
Expand Down Expand Up @@ -47,16 +48,40 @@
filenames))

(defn intern-fn [ns id meta f]
(intern ns (with-meta (symbol (name id)) meta) f))
(intern ns (with-meta
(symbol (name id))
(-> meta
(assoc :arglists
(if (empty? (:keys (second (first (:arglists meta)))))
`([] [~'conn & ~'args])
`([~(second (first (:arglists meta)))]
[~'conn ~(second (first (:arglists meta))) & ~'args]))))) f))

(defmacro bind-connection [conn & filenames]
`(let [{snips# :snips fns# :fns :as queries#} (congraph.core/load-queries ~@filenames)]
(doseq [[id# {fn# :fn meta# :meta}] snips#]
(conman.core/intern-fn *ns* id# meta# fn#))
(congraph.core/intern-fn *ns* id# meta# fn#))
(doseq [[id# {query# :fn meta# :meta}] fns#]
(conman.core/intern-fn *ns* id# meta#
(congraph.core/intern-fn *ns* id# meta#
(fn f#
([] (query# ~conn {}))
([params#] (query# ~conn params#))
([conn# params# & args#] (apply query# conn# params# args#)))))
queries#))

(defn connect
([bolt-url] (connect bolt-url nil nil))
([bolt-url username] (connect bolt-url username nil))
([bolt-url username password]
(cypher/connect bolt-url username password)))

(defn disconnect
[conn]
(.close conn))

(defn set-audit-defaults
[& {:keys [node-label node-id-attribute
default-node-id audit-relationship
audit-node audit-made-relationship]
:as audit-params}]
(cypher/set-audit-params audit-params))

0 comments on commit 374bda4

Please sign in to comment.