diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..183077d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Fern Flower Lab + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.adoc b/README.adoc index d2bbe25..ced6062 100644 --- a/README.adoc +++ b/README.adoc @@ -1,6 +1,105 @@ = The SQL Graph in Clojure +Utilizes Tinkerpop3 graph over SQL database using `sqlg`. + +== Supported DBs + +. PostgreSQL +. MySQL +. MariaDB +. HSQLDB +. H2 +. MSSQL + +CAUTION: The low-level drive well tested only with PostgreSQL + C3P0. You are warned. + +== Config + +Basic config is represented by `sample.properties` + +[source,properties] +---- +sample.graph.db.type = postgresql +sample.graph.db.host = localhost +sample.graph.db.port = 5432 +sample.graph.db.name = sample +sample.graph.db.user = username +sample.graph.db.pass = password +---- + +In order to get it prepared use + +[source,clojure] +---- +user=> (require '[sqlg-clj.config :as c]) +user=> (def config (-> "sample" c/load-config :sample :graph :db c/db-config)) +---- + +Same result may be done using EDN config, i.e. directly from your app: + +[source,clojure] +---- +user=> (def config (c/db-config {:port 5432 :pass "password" :user "username" :type "postgresql" :host "localhost" :name "sample"})) +---- + +When the config is ready it may be easily read back + +[source,clojure] +---- +user=>(c/config->clj config) +{"jdbc.url" "jdbc:postgresql://localhost:5432/sample", "jdbc.username" "username", "jdbc.password" "password"} +---- + +=== Starting + +Open SqlgGraph directly + +[source,clojure] +---- +(def G (c/graph config)) +---- + +or indirectly + +[source,clojure] +---- +(def G (c/open-graph config)) +---- + +The last method opens a new TinkerGraph with default configuration or open a new Graph instance with the specified configuration. +The configuration may be a path to a file or a Map of configuration options. +When gets prepared BaseConfiguration or Configuration object as an argument - returns SqlgGraph. + +=== Using + +[source,clojure] +---- +user=> (-> ^Graph G traversal V (has-label "label")) +#object[org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal 0x3fffba3f "[GraphStep(vertex,[]), HasStep([~label.eq(label)])]"] +---- + +=== Transactions + +In order to store or to unroll the changes were made by some iteration between calls, use + +[source,clojure] +---- +user=> (require '[sqlg-clj.util :as u]) +user=> (u/commit! G) +;; or +user=> (u/rollback! G) +---- + +respectively. + +=== More info + +Please, read original documentation http://sqlg.org[here] + == License -© 2022 Fern Flower Lab +© + +2022 Fern Flower Lab +Distributed under the MIT License. diff --git a/project.clj b/project.clj index 2249de5..2eb3815 100644 --- a/project.clj +++ b/project.clj @@ -1,7 +1,7 @@ (defproject ai.z7/sqlg-clj "0.0.1" :description "The SQL Graph with Tinkerpop3 and Clojure" :url "https://github.com/fern-flower-lab/sqlg-clj" - :license {:name "CURRENTLY UNSET"} + :license {:name "MIT"} :dependencies [[org.clojure/clojure "1.11.1"] [potemkin "0.4.5"] ;[commons-io/commons-io "2.11.0"] diff --git a/resources/sample.properties b/resources/sample.properties new file mode 100644 index 0000000..718ae37 --- /dev/null +++ b/resources/sample.properties @@ -0,0 +1,6 @@ +sample.graph.db.type = postgresql +sample.graph.db.host = localhost +sample.graph.db.port = 5432 +sample.graph.db.name = sample +sample.graph.db.user = username +sample.graph.db.pass = password diff --git a/src-clj/sqlg_clj/config.clj b/src-clj/sqlg_clj/config.clj index c4d2fc3..0d00a5e 100644 --- a/src-clj/sqlg_clj/config.clj +++ b/src-clj/sqlg_clj/config.clj @@ -1,6 +1,6 @@ (ns sqlg-clj.config (:require [java-properties.core :as jconf]) - (:import (org.apache.commons.configuration2 BaseConfiguration Configuration) + (:import (org.apache.commons.configuration2 BaseConfiguration Configuration ConfigurationConverter) (org.apache.tinkerpop.gremlin.structure Graph) (org.umlg.sqlg.structure SqlgGraph) (org.apache.tinkerpop.gremlin.structure.util GraphFactory) @@ -12,11 +12,14 @@ (let [conf (doto (BaseConfiguration.) (.addProperty "jdbc.url" (format "jdbc:%s://%s:%s/%s" - type host port name)) - (.addProperty "jdbc.username" user) - (.addProperty "jdbc.password" pass))] + type host port name)))] + (when user (.addProperty conf "jdbc.username" (str user))) + (when pass (.addProperty conf "jdbc.password" (str pass))) conf)) +(defn config->clj [^Configuration cf] + (into {} (ConfigurationConverter/getMap cf))) + ;; Local SQLGraph instance (defn graph ^Graph [^Configuration config] (SqlgGraph/open config)) @@ -24,7 +27,9 @@ ; GraphFactory (defn open-graph "Opens a new TinkerGraph with default configuration or open a new Graph instance with the specified - configuration. The configuration may be a path to a file or a Map of configuration options." + configuration. The configuration may be a path to a file or a Map of configuration options. + In order to get an SqlgGraph instance - pass prepared BaseConfiguration or Configuration object as + an argument." ([conf] (cond (instance? Configuration conf)