Skip to content

Instantly share code, notes, and snippets.

@cigitia
Created March 29, 2015 23:54
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 cigitia/106e95c3824783442c5b to your computer and use it in GitHub Desktop.
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
(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