can someone explain why the db-before
in the second run contains the datom [... count 1 ...]
i would expect the count to be 2 as thats what it was "before"
run
(d/transact! conn '[{::id 1
::count 2}])
;;output
#datascript.db.TxReport{:db-before #datascript/DB {:schema {:<http://apple.frontend.app/id|apple.frontend.app/id> {:db/unique :db.unique/identity}, :<http://apple.frontend.app/count|apple.frontend.app/count> {:db/cardinality :db.cardinality/one}}, :datoms [[1 :<http://apple.frontend.app/count|apple.frontend.app/count> 2 536870913] [1 :<http://apple.frontend.app/id|apple.frontend.app/id> 1 536870913]]},
:db-after #datascript/DB {:schema {:<http://apple.frontend.app/id|apple.frontend.app/id> {:db/unique :db.unique/identity}, :<http://apple.frontend.app/count|apple.frontend.app/count> {:db/cardinality :db.cardinality/one}}, :datoms [[1 :<http://apple.frontend.app/count|apple.frontend.app/count> 2 536870913] [1 :<http://apple.frontend.app/id|apple.frontend.app/id> 1 536870913]]}, :tx-data [], :tempids {:db/current-tx 536870914}, :tx-meta nil}
;;second run run
(d/transact! conn '[{::id 1
::count 1}])
;;output
#datascript.db.TxReport{:db-before #datascript/DB {:schema {:<http://apple.frontend.app/id|apple.frontend.app/id> {:db/unique :db.unique/identity}, :<http://apple.frontend.app/count|apple.frontend.app/count> {:db/cardinality :db.cardinality/one}}, :datoms [[1 :<http://apple.frontend.app/count|apple.frontend.app/count> 1 536870915] [1 :<http://apple.frontend.app/id|apple.frontend.app/id> 1 536870913]]},
:db-after #datascript/DB {:schema {:<http://apple.frontend.app/id|apple.frontend.app/id> {:db/unique :db.unique/identity}, :<http://apple.frontend.app/count|apple.frontend.app/count> {:db/cardinality :db.cardinality/one}}, :datoms [[1 :<http://apple.frontend.app/count|apple.frontend.app/count> 1 536870915] [1 :<http://apple.frontend.app/id|apple.frontend.app/id> 1 536870913]]}, :tx-data [], :tempids {:db/current-tx 536870916}, :tx-meta nil}
i'm not on the latest version of datascript. but i would assume this too be a fairly big bug 🙂. i'm guessing there is something else going on here.
How to handle UI specific things? Say for a todo app, you'll want to see all completed todos, how would you store the filter? This example is not working https://github.com/tonsky/datascript-todo/blob/gh-pages/src/datascript_todo/core.cljs#L31-L42
I was just curious if someone came up with a good convention for storing application-wide data, it might have been that 0 is no longer supported and has to be 1, since it's not working with :db/add 0 ...
I'll probably try and play with different approaches, this seems fine for now
can you explain to me what you mean by "storing application-wide data"?
It's working if I replace the ID from 0 to 1 but I am curious how you handle it in your apps
I don't think there is anything UI specific about datascript. It's a in memory database with a query language, so you can store information (UI, etc...) as you like.
As for your example,
the 0
and 1
are both being used in the entity id
slot. That is, the second item in
[:db/add <entity-id> attr value]. So for some reason, your current project gave the entity the ID of 1 instead of 0. you can probably check the db and see this.