(ns top500golf.graph.utils
(:require [top500golf.data :refer [course-list golfer-list contact-list golfer-courses]]
[clojurewerkz.neocons.rest.cypher :as cy]
[clojurewerkz.neocons.rest.nodes :as nn]
[clojurewerkz.neocons.rest.transaction :as tx]
[clojurewerkz.neocons.rest.labels :as nl]
[clojurewerkz.neocons.rest.relationships :as nr]
[environ.core :refer [env]]
[clojure.string :as str])
(:use [top500golf.common]
[top500golf.graph.parser]
[clojurewerkz.neocons.rest.records]
[top500golf.graph])
(:import (java.util Date List)
(clojurewerkz.neocons.rest.records Node)))
(defn cypher->
[^String query]
(cy/tquery connection query))
(defn create-root-var
"Given a name and a value, intern a var in the current namespace, taking metadata from the value."
([name value]
(create-root-var *ns* name value))
([ns name value]
(intern *ns*
(with-meta (symbol name)
(meta value))
value)))
(defn generate-prepare-query-fn
"It does not assert anything, just a wrapper which executes prepare-query
so it can be used as a function with a name = query name, specified with //name"
[{:keys [name statement] :as query-string}]
(fn [parameter-map]
(let [execute-fn
(condp = (last name)
\ > u/cypher->v
\! u/cypher->)]
(-> statement
(statement-parser/prepare-query parameter-map)
execute-fn))))
(defn parse-tagged-queries
[text]
(iu/process-instaparse-result
(instaparse/transform
parser-transforms
(instaparse/parses
parser (str text "\n")
:start :queries))
{}))
(defn defqueries
[filename]
(->> filename
(str "queries/")
(io/resource)
slurp
parse-tagged-queries
(map gen/generate-var)
doall))
* user.cql
//name: user:find-user-by-reset-pw-key>
match (c:Golfer {resetpw : @resetpw}) return c limit 1;
* user.clj
(qp/defqueries "user.cql")
(defn find-user-by-reset-pw-key [reset-pw-key]
(-> (user:find-user-by-reset-pw-key> {:resetpw reset-pw-key}) first get-map))
The entire code of the project was compiled in two files. Full code refactoring was necessary to eliminate errors and establish optimal structure;
Migration to a new DBMS was performed for an active application with a full data transfer from the old database. To secure data integrity and structure, the developer created a new & unique algorithm for parsing DBMS queries;
The algorithms for data computing, sorting & grouping were in need of optimization. The developer wrote a separate, complex algorithm for handling data.