datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Socks 2019-03-17T16:46:04.018Z

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}

Socks 2019-03-19T01:22:22.038700Z

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.

lauritzsh 2019-03-17T19:09:06.019700Z

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

lauritzsh 2019-03-18T17:48:54.025800Z

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 ...

lauritzsh 2019-03-18T17:49:17.026Z

I'll probably try and play with different approaches, this seems fine for now

Socks 2019-03-19T01:21:32.038500Z

can you explain to me what you mean by "storing application-wide data"?

lauritzsh 2019-03-17T19:10:29.020300Z

It's working if I replace the ID from 0 to 1 but I am curious how you handle it in your apps

Socks 2019-03-17T20:24:54.020400Z

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.