Created
March 29, 2015 23:54
-
-
Save cigitia/106e95c3824783442c5b to your computer and use it in GitHub Desktop.
Demo of DataScript 0.10.0 circular entity-ID generation when creating new component entities within transaction
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
(ns demo.main | |
(:require [datascript :as ds])) | |
(def schema | |
{:x/component {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many | |
:db/isComponent true}}) | |
(def conn | |
(ds/create-conn schema)) | |
(ds/transact! conn | |
[{:db/id 1, :z/completely-different "Z"} | |
{:db/id 2, :x/component [{:c/name "C"}]}]) | |
; Doing the following instead also creates a circular reference: | |
#_ | |
(ds/transact! conn | |
[{:db/id 1, :x/component [{:c/name "C"}]}]) | |
(enable-console-print!) | |
(prn @conn) | |
; This will print something like: | |
; #datascript/DB {:schema ... | |
; :datoms | |
; [[1 :z/completely-different "Z" 536870913] | |
; [2 :x/component 2 536870913] | |
; [2 :x/name "C" 536870913]]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment