Skip to content

Instantly share code, notes, and snippets.

@ivarref
Created February 3, 2020 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivarref/0bb0e1f51919760be7c953ccd0b12279 to your computer and use it in GitHub Desktop.
Save ivarref/0bb0e1f51919760be7c953ccd0b12279 to your computer and use it in GitHub Desktop.
(ns dato.demo
(:require [datomic.api :as d])) ; datomic version 0.9.6024
(def url "datomic:mem://test-db")
(def conn (do (d/delete-database url)
(d/create-database url)
(d/connect url)))
(def schema
[#:db{:ident :e/a, :cardinality :db.cardinality/one, :valueType :db.type/string}
#:db{:ident :e/b, :cardinality :db.cardinality/one, :valueType :db.type/ref}
#:db{:ident :other/id, :cardinality :db.cardinality/one, :valueType :db.type/string :unique :db.unique/identity}
#:db{:ident :e/a+b,
:cardinality :db.cardinality/one,
:valueType :db.type/tuple,
:tupleAttrs [:e/a :e/b],
:unique :db.unique/identity}])
@(d/transact conn schema)
@(d/transact conn [{:db/id "ref"
:other/id "other"}
{:e/a "a"
:e/b "ref"}])
(def db (d/db conn))
(println (d/pull db '[:*] [:e/a+b ["a" [:other/id "other"]]]))
; => #:db{:id nil} !
(println (d/pull db '[:*] [:e/a+b ["a" (:db/id (d/pull db [:db/id] [:other/id "other"]))]]))
; => {:db/id 17592186045419, :e/a a, :e/b #:db{:id 17592186045418}, :e/a+b [a 17592186045418]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment