Skip to content

Instantly share code, notes, and snippets.

@Jaretbinford
Last active September 20, 2018 02:54
Show Gist options
  • Save Jaretbinford/aeb63888cedfbacee90180ad206603b9 to your computer and use it in GitHub Desktop.
Save Jaretbinford/aeb63888cedfbacee90180ad206603b9 to your computer and use it in GitHub Desktop.
;;Transactor
$ bin/transactor ~/Downloads/support-logs/1932-workframe/dev-transactor.properties
Launching with Java options -server -Xms1g -Xmx1g -XX:+UseG1GC -XX:MaxGCPauseMillis=50
Starting datomic:dev://0.0.0.0:4334/<DB-NAME>, storing data in: data ...
System started datomic:dev://0.0.0.0:4334/<DB-NAME>, storing data in: data
;;Connecting with a REPL from datomic distribution:
$ bin/repl
Clojure 1.9.0
user=> (require '[datomic.api :as d])
nil
user=> (def db-uri "datomic:dev://localhost:4334/hello?password=StoragePassword")
#'user/db-uri
user=> (d/create-database db-uri)
true
user=> (d/get-database-names "datomic:dev://localhost:4334/*?password=StoragePassword")
("hello")
user=> (d/get-database-names "datomic:dev://0.0.0.0:4334/*?password=StoragePassword")
("hello")
user=> (def db (d/db conn))
#'user/db
user=> @(d/transact conn [{:db/doc "Hello world"}])
{:db-before datomic.db.Db@aff635f6, :db-after datomic.db.Db@5e02f3be, :tx-data [#datom[13194139534312 50 #inst "2018-09-20T02:31:15.891-00:00" 13194139534312 true] #datom[17592186045417 62 "Hello world" 13194139534312 true]], :tempids {-9223301668109598143 17592186045417}}
user=> (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"}])
#'user/movie-schema
user=> @(d/transact conn movie-schema)
{:db-before datomic.db.Db@9db4094, :db-after datomic.db.Db@7d362a22, :tx-data [#datom[13194139534314 50 #inst "2018-09-20T02:34:15.130-00:00" 13194139534314 true] #datom[63 10 :movie/title 13194139534314 true] #datom[63 40 23 13194139534314 true] #datom[63 41 35 13194139534314 true] #datom[63 62 "The title of the movie" 13194139534314 true] #datom[64 10 :movie/genre 13194139534314 true] #datom[64 40 23 13194139534314 true] #datom[64 41 35 13194139534314 true] #datom[64 62 "The genre of the movie" 13194139534314 true] #datom[65 10 :movie/release-year 13194139534314 true] #datom[65 40 22 13194139534314 true] #datom[65 41 35 13194139534314 true] #datom[65 62 "The year the movie was released in theaters" 13194139534314 true] #datom[0 13 65 13194139534314 true] #datom[0 13 64 13194139534314 true] #datom[0 13 63 13194139534314 true]], :tempids {-9223301668109598142 63, -9223301668109598141 64, -9223301668109598140 65}}
user=> (def first-movies [{:movie/title "The Goonies"
:movie/genre "action/adventure"
:movie/release-year 1985}
{:movie/title "Commando"
:movie/genre "action/adventure"
:movie/release-year 1985}
{:movie/title "Repo Man"
:movie/genre "punk dystopia"
:movie/release-year 1984}])
#'user/first-movies
user=> @(d/transact conn first-movies)
{:db-before datomic.db.Db@4c719cb5, :db-after datomic.db.Db@4fcc9852, :tx-data [#datom[13194139534315 50 #inst "2018-09-20T02:37:06.425-00:00" 13194139534315 true] #datom[17592186045420 63 "The Goonies" 13194139534315 true] #datom[17592186045420 64 "action/adventure" 13194139534315 true] #datom[17592186045420 65 1985 13194139534315 true] #datom[17592186045421 63 "Commando" 13194139534315 true] #datom[17592186045421 64 "action/adventure" 13194139534315 true] #datom[17592186045421 65 1985 13194139534315 true] #datom[17592186045422 63 "Repo Man" 13194139534315 true] #datom[17592186045422 64 "punk dystopia" 13194139534315 true] #datom[17592186045422 65 1984 13194139534315 true]], :tempids {-9223301668109598139 17592186045420, -9223301668109598138 17592186045421, -9223301668109598137 17592186045422}}
user=> (def db (d/db conn))
#'user/db
user=> (def all-movies-q '[:find ?e :where [?e :movie/title]])
#'user/all-movies-q
user=> (d/q all-movies-q db)
#{[17592186045420] [17592186045421] [17592186045422]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment