Skip to content

Commit

Permalink
added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
source-c committed Jun 20, 2022
1 parent 38f40d7 commit 6ab6b97
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 7 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
101 changes: 100 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
6 changes: 6 additions & 0 deletions resources/sample.properties
Original file line number Diff line number Diff line change
@@ -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
15 changes: 10 additions & 5 deletions src-clj/sqlg_clj/config.clj
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -12,19 +12,24 @@
(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))

; 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)
Expand Down

0 comments on commit 6ab6b97

Please sign in to comment.