Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 1.11 KB

File metadata and controls

61 lines (45 loc) · 1.11 KB

Datomic

Setup

(:require [datomic.api :as d])

(def db-uri "datomic:dev://localhost:4334/hello")

(d/create-database db-uri)

Get connection like

(def conn (d/connect db-uri))

And get snapshot like

(def db (d/db conn))

Queries

Simple:

(d/q '[:find ?title :where
         [?e :movie/release-year 1985]
         [?e :movie/title ?title]]
       db)

This returns only the title. Something similar to SELECT * is pull. Like

(d/q '[:find (pull ?e [*])
       :where [?e :movie/release-year 1985]]
     db)

Schema

(def movie-schema
  [{:db/ident       :movie/title
    :db/valueType   :db.type/string
    :db/cardinality :db.cardinality/one
    :db/doc         "The title of the movie"}

   {:db/ident       :movie/genre
    :db/valueTyp    :db.type/string
    :db/cardinality :db.cardinality/one
    :db/doc         "The genre of the movie"}

   {:db/ident       :movie/release-year
    :db/valueType   :db.type/long
    :db/cardinality :db.cardinality/one
    :db/doc         "The year the movie was released in theaters"}])