Skip to content

Instantly share code, notes, and snippets.

@stuarthalloway
Created April 30, 2012 18:42
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save stuarthalloway/2560986 to your computer and use it in GitHub Desktop.
Save stuarthalloway/2560986 to your computer and use it in GitHub Desktop.
Datomic rule to find schema attributes whose name matches a prefix
;; The Datomic schema is made up of Datomic data, so you manipulate it
;; with ordinary queries and transactions -- and with ordinary code
;; in Java or Clojure.
;; query rule that finds attributes in schema whose names start with ?prefix
;; note the Java interop call to .startsWith
;; you could create a similar rule for namespace prefixes
(def rules '[[[attr-starts-with ?prefix ?attr]
[?e :db/valueType]
[?e :db/ident ?attr]
[(name ?attr) ?name]
[(.startsWith ^String ?name ?prefix)]]])
;; in-memory example database
(use '[datomic.api :only (db q) :as d])
(def uri "datomic:mem://test")
(d/create-database uri)
(def conn (d/connect uri))
;; what attributes have names starting with "t"?
(q '[:find ?a
:in $ % ?prefix
:where (attr-starts-with ?prefix ?a)]
(db conn)
rules
"t")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment