Skip to content

Instantly share code, notes, and snippets.

@AlBaker
Last active March 24, 2017 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlBaker/e54065186197da3103d1e8bf03953252 to your computer and use it in GitHub Desktop.
Save AlBaker/e54065186197da3103d1e8bf03953252 to your computer and use it in GitHub Desktop.
Stardog-clj example
(ns stardog-clojure.core
(:require
[stardog.core :refer [insert! remove! update! query create-db-spec make-datasource
with-connection-pool with-transaction]]
[stardog.values :as values])
(:gen-class))
(defn db-spec
[database]
(create-db-spec database "http://localhost:5820/" "admin" "admin" true))
(def ds (ref {}))
(defn get-ds
"Retrieve the current Stardog data source"
[]
(:ds @ds))
(defn start-ds
"Start the Stardog data source"
[database]
(dosync
(ref-set ds {:ds (make-datasource (db-spec database))})))
(defn run-query []
(let [_ (start-ds "decomp")
ds (get-ds)]
(with-connection-pool [conn ds]
(let [results (query conn "select ?s ?p ?o where { ?s ?p ?o } limit 5")]
(doseq [r results]
(println r))))))
(defn -main [& args]
(run-query))
(defproject stardog-clojure "0.1.0-SNAPSHOT"
:description "TODO"
:url "TODO"
:license {:name "TODO: Choose a license"
:url "http://choosealicense.com/"}
:repositories {"stardog" {:url "http://maven.stardog.com"}}
:dependencies [[org.clojure/clojure "1.8.0"]
[stardog-clj "4.2.1"]
[com.stuartsierra/component "0.3.2"]]
:main ^:skip-aot stardog-clojure.core
:target-path "target/%s"
:profiles {:dev {:dependencies [[org.clojure/tools.namespace "0.2.11"]
[com.stuartsierra/component.repl "0.2.0"]]
:source-paths ["dev"]}
:uberjar {:aot :all}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment