Created
April 30, 2012 18:42
-
-
Save stuarthalloway/2560986 to your computer and use it in GitHub Desktop.
Datomic rule to find schema attributes whose name matches a prefix
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
;; 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