Skip to content

Instantly share code, notes, and snippets.

@yokolet
Created May 26, 2016 14:11
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 yokolet/a5b2a3dee53f03dd548e6c84e396d0e7 to your computer and use it in GitHub Desktop.
Save yokolet/a5b2a3dee53f03dd548e6c84e396d0e7 to your computer and use it in GitHub Desktop.
ring app
(ns simple-ring.core
(:require [datomic.api :as d]))
(def uri "datomic:dev://localhost:4334/5745c8fc-6d57-4184-972a-eef798243572")
(def schema-tx
[{:db/id #db/id[:db.part/db]
:db/ident :hello/color
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/fulltext true
:db/doc "Today's color"
:db.install/_attribute :db.part/db}])
(def data-tx
[{:db/id #db/id[:db.part/user -1], :hello/color "True Mint"}
{:db/id #db/id[:db.part/user -2], :hello/color "Yellowish White"}
{:db/id #db/id[:db.part/user -3], :hello/color "Orange Red"}
{:db/id #db/id[:db.part/user -4], :hello/color "Olive Green"}])
(defn init-db []
(let [_ (prn ::init-db uri schema-tx data-tx)
created? (d/create-database uri)
_ (prn ::init-db "created?" created?)
conn (d/connect uri)
_ (prn ::init-db conn)]
@(d/transact conn schema-tx)
@(d/transact conn data-tx)
conn))
(defn simple-query
[conn]
(let [conn (d/connect uri)]
(d/q '[:find ?c :where [?e :hello/color ?c]] (d/db conn))))
(defn handler [request]
(let [conn (init-db)]
{:status 200
:headers {"Content-Type" "text/plain"}
:body (str "Hello Ring! " (simple-query conn))}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment