Giter Site home page Giter Site logo

fern-flower-lab / sqlg-clj Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 33 KB

The SQL Graph with Tinkerpop3 and Clojure

License: MIT License

Clojure 100.00%
clj sql graph gremlin tinkerpop3 database dataprocessing rdbms-to-graph clojure clojure-library h2 hsql maria mssql mysql postgresql tinkerpop tinkerpop-graphs

sqlg-clj's Introduction

The SQL Graph in Clojure

Utilizes Tinkerpop3 graph over SQL database using sqlg.

GitHub sqlg clj GitHub tag (latest by date) GitHub last commit GitHub release (latest by date)

Warning
Origin’s library uses J17 for releases (at least for 3.0.x versions), so independently on this Clojure library build you will be forced to use that version too.

Supported DBs

  1. PostgreSQL

  2. MySQL

  3. MariaDB

  4. HSQLDB

  5. H2

  6. MSSQL

Caution
The low-level driver is well tested only with PostgreSQL + C3P0. You are warned.

Config

Basic config is represented by sample.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

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:

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

user=>(c/config->clj config)
{"jdbc.url" "jdbc:postgresql://localhost:5432/sample", "jdbc.username" "username", "jdbc.password" "password"}

Starting

Open SqlgGraph directly

(def G (c/graph config))

or indirectly

(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

user=> (require '[sqlg-clj.core :refer :all])
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

user=> (require '[sqlg-clj.util :as u])
user=> (u/commit! G)
;; or
user=> (u/rollback! G)

respectively.

Examples

create, find, process

user=> (require '[sqlg-clj.util :as u])
user=> (require '[sqlg-clj.data :as d])
user=> (require '[sqlg-clj.core :refer :all])

user=> (-> G (d/add-V :test {:aa 11 :bb 22}))
#object[org.umlg.sqlg.structure.SqlgVertex 0x2e5e87e9 "v[public.test:::14]"]
user=> (-> G (d/add-V :test {:aa 33 :cc 44}))
#object[org.umlg.sqlg.structure.SqlgVertex 0x6ec0ead1 "v[public.test:::15]"]
user=> (u/commit! G)
nil

user=> (def vxs (-> G traversal V (has-label :test) (has :aa) u/into-vec!))
#'user/vxs

user=> (map #(value % :aa) vxs)
(11 33)
user=> (map #(value % :bb) vxs)
(22 nil)
user=> (map #(value % :cc) vxs)
(nil 44)

More info

Please, read original documentation here and here

License

©2022-2023 Fern Flower Lab

Distributed under the MIT License.

sqlg-clj's People

Contributors

source-c avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

iridanius

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.