Created
December 26, 2016 14:07
-
-
Save Jaretbinford/bef7b093f45251e276f982a56ced2c4f to your computer and use it in GitHub Desktop.
String temp ids do not work with d/entity function calls
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
;;google group discussion link https://groups.google.com/forum/#!topic/datomic/m6vSa6CjqjQ | |
(ns stringtemp.core | |
(:import datomic.Util) | |
(require [datomic.api :as d] | |
[clojure.java.io :as io])) | |
;;Create the DB | |
(def db-uri "datomic:dev://localhost:4334/stringtemp") | |
(d/create-database db-uri) | |
(def conn (d/connect db-uri)) | |
;; Schema | |
;[{:db/ident :foo/name | |
; :db/valueType :db.type/string | |
; :db/cardinality :db.cardinality/one} | |
; {:db/ident :foo/ref | |
; :db/valueType :db.type/ref | |
; :db/cardinality :db.cardinality/one} | |
; {:db/ident :myAdd | |
; :db/fn #db/fn {:lang :clojure | |
; :params [db e a v] | |
; :code [[:db/add (:db/id (d/entity db e)) a v]]}}] | |
(def schema (read-string (slurp "/Users/jbin/Desktop/Jaret/Projects/workproof/merge/resources/stringschema.edn"))) | |
@(d/transact conn schema) | |
;; The other examples are indirectly this. | |
@(d/transact conn | |
[[:db/add "a" :foo/name "x"] | |
[:db/add "b" :foo/name "y"] | |
[:db/add "a" :foo/ref "b"]])) | |
;; Works! Note that d/entity resolves tempid. | |
(let [a (d/tempid :db.part/user)] | |
@(d/transact conn | |
[[:db/add a :foo/name "x"] | |
[:db/add "b" :foo/name "y"] | |
[:myAdd a :foo/ref "b"]])) | |
;; Fails with :db.error/not-a-keyword. | |
@(d/transact conn | |
[[:db/add "a" :foo/name "x"] | |
[:db/add "b" :foo/name "y"] | |
[:myAdd "a" :foo/ref "b"]]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment