Skip to content

Instantly share code, notes, and snippets.

@RobertARandolph
Created August 3, 2021 11:45
Show Gist options
  • Select an option

  • Save RobertARandolph/17d5fff9c6737677bfc3a0d67e11c77d to your computer and use it in GitHub Desktop.

Select an option

Save RobertARandolph/17d5fff9c6737677bfc3a0d67e11c77d to your computer and use it in GitHub Desktop.
(ns datomic.tutorial
(:require [datomic.client.api :as d]))
(def cfg {:server-type :ion
:region "us-east-1" ;; e.g. us-east-1
:system "my-system"
:endpoint "https://enter-your-endpoint.execute-api.us-east-1.amazonaws.com"})
(def client (d/client cfg))
(d/create-database client {:db-name "movies"})
(def conn (d/connect client {:db-name "movies"}))
(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/valueType :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"}])
(d/transact conn {:tx-data movie-schema})
(def first-movies [{:movie/title "The Goonies"
:movie/genre "action/adventure"
:movie/release-year 1985}
{:movie/title "Commando"
:movie/genre "thriller/action"
:movie/release-year 1985}
{:movie/title "Repo Man"
:movie/genre "punk dystopia"
:movie/release-year 1984}])
(d/transact conn {:tx-data first-movies})
(def db (d/db conn))
(def all-titles-q '[:find ?movie-title
:where [_ :movie/title ?movie-title]])
(d/q all-titles-q db)
(d/delete-database client {:db-name "movies"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment