Last active
March 24, 2017 13:57
-
-
Save AlBaker/e54065186197da3103d1e8bf03953252 to your computer and use it in GitHub Desktop.
Stardog-clj example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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