datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
bartuka 2020-02-20T01:04:41.062Z

hi, I would like to know if this behavior is expected:

(ds/conn-from-datoms [#datascript/Datom [1 :maker/name "BMW" 536870913 true]
                      #datascript/Datom [1 :maker/name "BMW" 536870914 false]])

#datascript/DB{:datoms [[1 :maker/name BMW 536870913] [1 :maker/name BMW 536870914]]}

bartuka 2020-02-20T01:06:22.063300Z

i got into this scenario because I was loading the datoms from a persistent data structure. When I perform the same set of operations in memory, the database has no datoms for these fact

bartuka 2020-02-20T01:06:46.063900Z

I think I will have to handle this situations when loading the datoms from past databases

2020-02-20T05:54:11.064200Z

https://github.com/metasoarous/datsync was an effort in this direction, but isn't yet batteries included for anything other than full db replication.

ts1503 2020-02-20T07:43:43.064500Z

Hi @cjsauer. Thanks, will give it a try

cjsauer 2020-02-20T15:01:49.064700Z

Not that I know of…could you give an example of what you’re after?

unbalanced 2020-02-20T15:06:37.064900Z

@sergey.tkachenko

(def schema 
  {:thing/parent {:db/unique :db.unique/identity}
  :thing/child {:db/valueType :db.type/ref
               :db/cardinality :db.cardinality/many
               :db/isComponent true}}) 
The key part is the :db/isComponent true

unbalanced 2020-02-20T15:08:50.065100Z

Will usually improve your experience with parent/child stuff

ts1503 2020-02-20T16:08:27.065300Z

Yes, it could help but in my case from domain modeling perspective the child entity it's not the component of the parent entity

richiardiandrea 2020-02-20T17:53:42.066Z

@iagwanderson what is the schema? that dictates which datoms are going to be built and how

cjsauer 2020-02-20T21:38:31.066600Z

Right. :db/isComponent will cause the child to be retracted along with the parent, which from your problem description is not what you want.

unbalanced 2020-02-20T23:23:41.066800Z

To answer your specific question, to delete a reference from :thing/parent to :thing/child you can simply assert

(d/trasnsact conn 
[[:db/retract [:thing/parent parent-id] :thing/children [:thing/child child-id]])
Not sure if that helps