This file contains 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
(use '[datomic.api :only [db q] :as d]) | |
;;not supplied: | |
;;* connecting to a db named "conn" | |
;; (checkout awesome Jonas Edlunds gist | |
;; for inspiration: https://gist.github.com/3122363 ) | |
;;* a schema that fit's the following person-datoms | |
;; Problem: | |
;;it's a bit quirky to generate references by functions to transact them to datoms |
This file contains 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
(use '[datomic.api :only [q db] :as d]) | |
(def uri "datomic:mem://accounts") | |
;; create database | |
(d/create-database uri) | |
;; connect to database | |
(def conn (d/connect uri)) |
This file contains 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
;; Datomic example code | |
(use '[datomic.api :only (db q) :as d]) | |
;; ?answer binds a scalar | |
(q '[:find ?answer :in ?answer] | |
42) | |
;; of course you can bind more than one of anything | |
(q '[:find ?last ?first :in ?last ?first] | |
"Doe" "John") |
This file contains 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
;; Datomic example code | |
;; demonstrates various update scenarios, using a news database | |
;; that contains stories, users, and upvotes | |
;; grab an in memory database | |
(use '[datomic.api :only (q db) :as d]) | |
(def uri "datomic:mem://foo") |
This file contains 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 logicrels.fred | |
(:require [clojure.xml :as xml] | |
[clojure.core.logic :as logic])) | |
;; (config :fred-key (do "See http://api.stlouisfed.org/api_key.html" nil)) | |
;; (clojure.pprint/pprint (sort-by :date (fred-test "DGS10" "2012-07-02"))) | |
;; ({:target "1.61", :date "2012-05-31", :value "1.59"} | |
;; {:target "1.61", :date "2012-06-01", :value "1.47"} |
This file contains 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 lucenalog.core | |
"Lucenalog = Datalog interface to Lucene in 10 lines. | |
Simple but powerful. | |
Use | |
(db/add (index) {:a \"foo\" :b \"bar\"}) | |
to index a map with Lucene. Then you can use the relation |
This file contains 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
(use '[datomic.api :only [db q] :as d]) | |
(def schema | |
[{:db/id #db/id[:db.part/db] | |
:db/ident :num | |
:db/valueType :db.type/long | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db} | |
{:db/id #db/id[:db.part/db] |
This file contains 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
;; Datomic example code | |
;; Demonstrates using datalog with Clojure defrecords | |
(use '[datomic.api :only [q db] :as d]) | |
;;; http://www.lshift.net/blog/2010/08/21/some-relational-algebra-with-datatypes-in-clojure-12 | |
(defrecord Supplier [number name status city]) | |
(defrecord Part [number name colour weight city]) | |
(defrecord Shipment [supplier part quantity]) | |
;; sample data |
This file contains 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] |
This file contains 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
;; Datomic sample code | |
;; schema query for attribute types in specified namespaces | |
(q '[:find ?attr | |
:in $ [?include-ns ...] ;; bind ?include-ns once for each item in collection | |
:where | |
[?e :db/valueType] ;; all schema types (must have a valueType) | |
[?e :db/ident ?attr] ;; schema type name | |
[(datomic.Util/namespace ?attr) ?ns] ;; namespace of name | |
[(= ?ns ?include-ns)]] ;; must match one of the ?include-ns |